public UpdateItem ( |
||
entity | ||
isDirty | bool | |
Результат | void |
public void UpdateItem(SqlCeOfflineEntity entity, bool isDirty)
{
var item = (Item)entity;
using (var command = new SqlCeCommand())
{
command.Connection = GetSqlCeConnection();
command.CommandText = UPDATE_ITEM;
command.Parameters.Add("@ListID", SqlDbType.UniqueIdentifier).Value = item.ListID;
command.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier).Value = item.UserID;
command.Parameters.AddWithValue("@Name", item.Name);
command.Parameters.AddWithValue("@Description", item.Description);
command.Parameters.AddWithValue("@Priority", item.Priority);
command.Parameters.AddWithValue("@Status", item.Status);
if (null != item.StartDate)
{
command.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = item.StartDate;
}
else
{
command.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = DBNull.Value;
}
if (null != item.EndDate)
{
command.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = item.EndDate;
}
else
{
command.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = DBNull.Value;
}
command.Parameters.AddWithValue("@IsDirty", isDirty ? 1 : 0);
command.Parameters.Add("@ItemID", SqlDbType.UniqueIdentifier).Value = item.ID;
if (null == item.ServiceMetadata.Id)
{
command.Parameters.Add("@MetadataId", SqlDbType.NVarChar, 250).Value = DBNull.Value;
}
else
{
command.Parameters.Add("@MetadataId", SqlDbType.NVarChar, 250).Value = item.ServiceMetadata.Id;
}
command.ExecuteNonQuery();
}
}
SqlCeStorageHandler::UpdateItem ( |
private void menuItem1_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.textBoxName.Text)) { MessageBox.Show("Item name cannot be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } try { if (IsNewItem) { var item = new Item() { Name = textBoxName.Text.Trim(), Description = textBoxDescription.Text.Trim(), UserID = new Guid(Settings.ClientId), ID = Guid.NewGuid(), ListID = this.ListId, Priority = ((Priority) comboBoxPriority.SelectedItem).ID, Status = ((Status) comboBoxStatus.SelectedItem).ID, ServiceMetadata = new OfflineEntityMetadata() { IsTombstone = false } }; var storageHandler = new SqlCeStorageHandler(); storageHandler.InsertItem(item, true); MessageBox.Show("Item created!", "Success", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); } else { Item.Name = textBoxName.Text.Trim(); Item.Description = textBoxDescription.Text.Trim(); Item.Priority = ((Priority) comboBoxPriority.SelectedItem).ID; Item.Status = ((Status) comboBoxStatus.SelectedItem).ID; var storageHandler = new SqlCeStorageHandler(); storageHandler.UpdateItem(Item, true); MessageBox.Show("Item updated!", "Success", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); } this.Close(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } }