public bool UpdateShift(CommContracts.Shift Shift) { using (DAL.HisContext ctx = new DAL.HisContext()) { var temp = ctx.Shifts.FirstOrDefault(m => m.ID == Shift.ID); if (temp != null) { temp.Name = Shift.Name; temp.StartTime = Shift.StartTime; temp.EndTime = Shift.EndTime; temp.ModifiedDate = DateTime.Now; } else { return(false); } try { ctx.SaveChanges(); } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(false); } } return(true); }
public bool SaveShift(CommContracts.Shift Shift) { Shift.ModifiedDate = DateTime.Now; using (DAL.HisContext ctx = new DAL.HisContext()) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <CommContracts.Shift, DAL.Shift>(); }); var mapper = config.CreateMapper(); DAL.Shift temp = new DAL.Shift(); temp = mapper.Map <DAL.Shift>(Shift); ctx.Shifts.Add(temp); try { ctx.SaveChanges(); } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(false); } } return(true); }
public EditShiftView(CommContracts.Shift Shift = null) { InitializeComponent(); bIsEdit = false; if (Shift != null) { this.m_Shift = Shift; this.NameEdit.Text = Shift.Name; this.StartTimeContorl.SetMyValue(Shift.StartTime); this.EndTimeContorl.SetMyValue(Shift.EndTime); bIsEdit = true; } }
private void SaveBtn_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(this.NameEdit.Text.Trim())) { return; } string strStartTime = this.StartTimeContorl.GetMyValue(); string strEndTime = this.EndTimeContorl.GetMyValue(); if (bIsEdit) { m_Shift.Name = this.NameEdit.Text; m_Shift.StartTime = strStartTime; m_Shift.EndTime = strEndTime; CommClient.Shift shiftClient = new CommClient.Shift(); if (shiftClient.UpdateShift(m_Shift)) { (this.Parent as Window).DialogResult = true; (this.Parent as Window).Close(); } } else { CommContracts.Shift shift = new CommContracts.Shift(); shift.Name = this.NameEdit.Text; shift.StartTime = strStartTime; shift.EndTime = strEndTime; CommClient.Shift shiftClient = new CommClient.Shift(); if (shiftClient.SaveShift(shift)) { (this.Parent as Window).DialogResult = true; (this.Parent as Window).Close(); } } }
public bool SaveShift(CommContracts.Shift Shift) { return(client.SaveShift(Shift)); }
public bool UpdateShift(CommContracts.Shift Shift) { return(client.UpdateShift(Shift)); }