private void btnTransfer_Click(object sender, EventArgs e) { try { DialogResult dialogResult = MessageBox.Show("هل تريد نقل المتعهد", "رسالة تأكيد", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { List <devices_tb> OldRespon = db.devices_tb.Where(u => u.lab_name == cmbLab.Text && u.respon == cmbCurrentCustody.Text).ToList(); string devicesBarcodes = string.Empty; foreach (var r in OldRespon) { r.respon = cmbNewCustody.Text; devicesBarcodes += (r.device_barcode.ToString() + ","); } db.SaveChanges(); DialogResult dialogResult2 = MessageBox.Show("هل تريد صباعة التقرير", "رسالة تأكيد", MessageBoxButtons.YesNo); if (dialogResult2 == DialogResult.Yes) { Reports.frmTransferCustodyReport frmTransferCustodyReport = new Reports.frmTransferCustodyReport(); frmTransferCustodyReport.employeeFrom = cmbCurrentCustody.Text; frmTransferCustodyReport.devicesBarcodes = devicesBarcodes; frmTransferCustodyReport.ShowDialog(); } //cmbNewCustody.Text = string.Empty; //lbxEmployee.Items.Clear(); var CurrentCustody = db.devices_tb.Where(u => u.lab_name == cmbLab.Text).Select(u => u.respon).Distinct().ToList(); cmbCurrentCustody.DataSource = CurrentCustody; //cmbNewCustody.DataSource = db.respons.Select(u => u.name).ToList(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void saveToolStripButton_Click(object sender, EventArgs e) { string error = string.Empty; if (txtDeviceName.Text == string.Empty) { error += "إدخل اسم الجهاز\n"; } if (cmbLab.SelectedItem == null) { error += "اختر المعمل\n"; } if (cmbExperiment.SelectedItem == null) { error += "اختر التجربة\n"; } if (cmbStatus.SelectedItem == null) { error += "اختر حالة الجهاز\n"; } if (error != string.Empty) { MessageBox.Show(error, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { try { if (CurrentStatus == Status.New) { GenerateBarcode(); var device = new devices_tb() { device_name = txtDeviceName.Text, device_barcode = Convert.ToDecimal(txtBarcode.Text), device_status = cmbStatus.Text, lab_name = cmbLab.Text, exp_name = cmbExperiment.Text, exp_num = Convert.ToInt32(cmbExperimentNum.SelectedItem == null ? 0 : Convert.ToInt32(cmbExperimentNum.Text)), respon = cmbEmployee.Text, description = txtDescription.Text }; db.devices_tb.Add(device); db.SaveChanges(); MessageBox.Show("تم الحفظ", "تم", MessageBoxButtons.OK, MessageBoxIcon.Information); //ClearControls(); ControlStatus(false); ToolStripButtonStatus(Status.Save); } if (CurrentStatus == Status.Edit) { var selectedItemBarcode = Convert.ToDecimal(txtBarcode.Text); var device = db.devices_tb.FirstOrDefault(u => u.device_barcode == selectedItemBarcode); var oldRespon = device.respon; // for report printing var oldStatus = device.device_status; // for report printing device.device_name = txtDeviceName.Text; device.device_barcode = Convert.ToDecimal(txtBarcode.Text); device.device_status = cmbStatus.Text; device.lab_name = cmbLab.Text; device.exp_name = cmbExperiment.Text; device.exp_num = Convert.ToInt32(cmbExperimentNum.SelectedItem == null ? 0 : Convert.ToInt32(cmbExperimentNum.Text)); device.respon = cmbEmployee.Text; device.description = txtDescription.Text; db.SaveChanges(); MessageBox.Show("تم التعديل", "تم", MessageBoxButtons.OK, MessageBoxIcon.Information); if (oldRespon != cmbEmployee.Text) { DialogResult dialogResult2 = MessageBox.Show("لقد تم تغيير صاحب العهدة هل تريد صباعة التقرير", "رسالة تأكيد", MessageBoxButtons.YesNo); if (dialogResult2 == DialogResult.Yes) { Reports.frmTransferCustodyReport frmTransferCustodyReport = new Reports.frmTransferCustodyReport(); frmTransferCustodyReport.employeeFrom = oldRespon; frmTransferCustodyReport.devicesBarcodes = device.device_barcode.ToString(); frmTransferCustodyReport.ShowDialog(); } } if (oldStatus != "مكهن" && device.device_status == "مكهن") { DialogResult dialogResult2 = MessageBox.Show("لقد تم تكهين الجهاز هل تريد صباعة التقرير", "رسالة تأكيد", MessageBoxButtons.YesNo); if (dialogResult2 == DialogResult.Yes) { Reports.frmTakhinReport frmTakhinReport = new Reports.frmTakhinReport(); frmTakhinReport.barcodes = device.device_barcode.ToString(); frmTakhinReport.ShowDialog(); } } //ClearControls(); ControlStatus(false); ToolStripButtonStatus(Status.Save); Search(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }