private void btnEdit_Click(object sender, EventArgs e) { ctx = new VisaXEntities(); int id = (int)dgvShifts.SelectedRows[0].Cells["colID"].Value; Shift shift = (from s in ctx.Shifts where s.ID == id select s).First(); string message = string.Format("ویرایش توضیحات شیفت شماره {0} با تاریخ {1} توسط {2}؟", shift.ShiftNum, shift.Date.ToShortDateString(), shift.User.RealName); frmNewShift frmNewShift = new frmNewShift(message); frmNewShift.txtDescription.Text = shift.Description; if (frmNewShift.ShowDialog() == DialogResult.Yes) { shift.Description = frmNewShift.txtDescription.Text; } ctx.SaveChanges(); refreshGrid(); dgvShifts.ClearSelection(); dgvShifts.Rows[dgvShifts.RowCount - 1].Selected = true; }//btnEdit
private void btnNew_Click(object sender, EventArgs e) { byte max = ctx.Shifts.Where(s => s.Date == DateTime.Today).Select(s => s.ShiftNum).DefaultIfEmpty <byte>(0).Max(); max++; string message = string.Format("تولید شیفت شماره {0} به تاریخ {1} توسط {2}؟", max, DateTime.Today.ToShortDateString(), Properties.Settings.Default.User.RealName); frmNewShift frmNewShift = new frmNewShift(message); if (frmNewShift.ShowDialog() == DialogResult.Yes) { ctx.Shifts.Add(new Shift { Date = DateTime.Today, UserID = Properties.Settings.Default.User.ID, ShiftNum = max, Description = frmNewShift.txtDescription.Text }); ctx.SaveChanges(); refreshGrid(); dgvShifts.ClearSelection(); dgvShifts.Rows[dgvShifts.RowCount - 1].Selected = true; } //if } //btnNew