private void btnSave_Click(object sender, EventArgs e) { try { if (!CheckData()) { return; } //Table RegistBarcode RegistBarcode registBarcode = new RegistBarcode(); registBarcode.Id = _id; registBarcode.PartNo = cbbPartNumber.Text.Trim(); registBarcode.RegistDate = dtpRegistDate.Value; registBarcode.MachineNo = cbbMachine.Text.Trim(); registBarcode.MoldNo = cbbMold.Text.Trim(); registBarcode.ShiftNo = cbbShift.Text.Trim(); registBarcode.SEQ = txtSEQ.Text.Trim(); registBarcode.Barcode = txtBarcode.Text.Trim(); registBarcode.Status = GlobalConstants.StatusValue.Using; _registBarcodeRepository.Save(registBarcode); UnitOfWork unitOfWork = new UnitOfWork(_projectDataContext); int result = unitOfWork.Complete(); if (result > 0) { if (String.IsNullOrEmpty(_id)) { PrintBarcode(); XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Lưu thành công"), LanguageTranslate.ChangeLanguageText("Thông báo")); Clear(); } else { DialogResult = DialogResult.OK; Close(); } } else { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Lưu thất bại"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Lưu thất bại"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
private bool CheckData() { if (cbbPartNumber.SelectedValue == null || String.IsNullOrEmpty(cbbPartNumber.Text.Trim())) { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Chưa chọn dữ liệu"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); cbbPartNumber.Focus(); return(false); } else if (cbbMachine.SelectedValue == null || String.IsNullOrEmpty(cbbMachine.Text.Trim())) { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Chưa chọn dữ liệu"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); cbbMachine.Focus(); return(false); } else if (cbbMold.SelectedValue == null || String.IsNullOrEmpty(cbbMold.Text.Trim())) { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Chưa chọn dữ liệu"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); cbbMold.Focus(); return(false); } else if (cbbShift.SelectedValue == null || String.IsNullOrEmpty(cbbShift.Text.Trim())) { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Chưa chọn dữ liệu"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); cbbShift.Focus(); return(false); } else if (txtSEQ.Text.Trim() == "") { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Chưa điền dữ liệu"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); txtSEQ.Focus(); return(false); } RegistBarcode registBarcode = _registBarcodeRepository.FirstOrDefault(_ => _.Barcode.Equals(txtBarcode.Text.Trim())); if (registBarcode != null && ( String.IsNullOrEmpty(_id) || (!String.IsNullOrEmpty(_id) && txtBarcode.Text.Trim() != registBarcode.Barcode) )) { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Dữ liệu đã tồn tại"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); cbbPartNumber.Focus(); return(false); } return(true); }
private void btnSave_Click(object sender, EventArgs e) { try { if (!CheckData()) { return; } //Table RegistBarcode RegistBarcode registBarcode = new RegistBarcode(); int seq = int.Parse(_registBarcodeRepository.GetSEQ(dtpRegistDate.Value, cbbShift.Text.Trim())); string barcode = ""; DataTable listBarcode = new DataTable(); listBarcode.Columns.Add("Barcode", typeof(string)); listBarcode.Columns.Add("PartNo", typeof(string)); listBarcode.Columns.Add("DateShift", typeof(string)); listBarcode.Columns.Add("MoldNoSEQ", typeof(string)); listBarcode.Columns.Add("VN", typeof(string)); for (int i = 0; i < txtQuantity.Value; i++) { //Generate barcode seq++; barcode = String.Format("{0}{1}{2}{3}{4}{5}", cbbPartNumber.Text.Trim(), dtpRegistDate.Value.ToString("yyMMdd"), cbbMachine.Text.Trim(), cbbShift.Text.Trim(), cbbMold.Text.Trim(), seq.ToString("0000")); //Set list barcode listBarcode.Rows.Add(new string[] { barcode, "P/N:" + cbbPartNumber.Text.Trim(), "Date:" + dtpRegistDate.Value.ToString("yyMMdd") + cbbShift.Text.Trim(), "M/N:" + cbbMold.Text.Trim() + "SEQ" + seq.ToString("0000"), "VN:" + GlobalConstants.VN }); //Insert data registBarcode = new RegistBarcode(); registBarcode.Id = _id; registBarcode.PartNo = cbbPartNumber.Text.Trim(); registBarcode.RegistDate = dtpRegistDate.Value.Date; registBarcode.MachineNo = cbbMachine.Text.Trim(); registBarcode.MoldNo = cbbMold.Text.Trim(); registBarcode.ShiftNo = cbbShift.Text.Trim(); registBarcode.SEQ = seq.ToString("0000"); registBarcode.Barcode = barcode; _registBarcodeRepository.Save(registBarcode); } UnitOfWork unitOfWork = new UnitOfWork(_projectDataContext); int result = unitOfWork.Complete(); if (result > 0) { if (String.IsNullOrEmpty(_id)) { _registBarcodeRepository.PrintListBarcode(listBarcode); Clear(); } else { DialogResult = DialogResult.OK; Close(); } } else { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Lưu thất bại"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Lưu thất bại"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
private void PrintBarcode(string partnumber, string mold, string machine, string shift) { try { //Table RegistBarcode RegistBarcode registBarcode = new RegistBarcode(); int seq = int.Parse(_registBarcodeRepository.GetSEQ(DateTime.Today, shift)); string barcode = ""; string _id = ""; DataTable listBarcode = new DataTable(); listBarcode.Columns.Add("Barcode", typeof(string)); listBarcode.Columns.Add("PartNo", typeof(string)); listBarcode.Columns.Add("DateShift", typeof(string)); listBarcode.Columns.Add("MoldNoSEQ", typeof(string)); listBarcode.Columns.Add("VN", typeof(string)); //Generate barcode seq++; barcode = String.Format("{0}{1}{2}{3}{4}{5}", partnumber.Trim(), DateTime.Today.ToString("yyMMdd"), machine.Trim(), shift.Trim(), mold.Trim(), seq.ToString("0000")); //Set list barcode listBarcode.Rows.Add(new string[] { barcode, "P/N:" + partnumber.Trim(), "Date:" + DateTime.Today.ToString("yyMMdd") + shift.Trim(), "M/N:" + mold.Trim() + "SEQ" + seq.ToString("0000"), "VN:" + GlobalConstants.VN }); //Insert data registBarcode = new RegistBarcode(); registBarcode.Id = _id; registBarcode.PartNo = partnumber.Trim(); registBarcode.RegistDate = DateTime.Today; registBarcode.MachineNo = machine.Trim(); registBarcode.MoldNo = mold.Trim(); registBarcode.ShiftNo = shift.Trim(); registBarcode.SEQ = seq.ToString("0000"); registBarcode.Barcode = barcode; _registBarcodeRepository.Save(registBarcode); UnitOfWork unitOfWork = new UnitOfWork(_projectDataContext); int result = unitOfWork.Complete(); if (result > 0) { if (String.IsNullOrEmpty(_id)) { _registBarcodeRepository.PrintListBarcode(listBarcode); BarcodePrint = barcode; //_serialPort.Write("0"); //timer.Enabled = false; } } else { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Lưu thất bại"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { XtraMessageBox.Show(LanguageTranslate.ChangeLanguageText("Lưu thất bại"), LanguageTranslate.ChangeLanguageText("Thông báo"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }