private void btnAdd_Click(object sender, EventArgs e) { switch (flag) { case 1: pDetail.Controls.Clear(); UCPrinter ucPrinter = new UCPrinter(); ucPrinter.Dock = DockStyle.Fill; ucPrinter.btnRemove.Hide(); ucPrinter.btnSave.Click += btnSaveInforPrinter_Click; ucPrinter.ResetPrinterList = new ResetPrinterList(this.ResetPriter); pDetail.Controls.Add(ucPrinter); break; case 2: pDetail.Controls.Clear(); UCPrinterJobDetail ucJob = new UCPrinterJobDetail(); ucJob.Dock = DockStyle.Fill; pDetail.Controls.Add(ucJob); ucJob.LoadPriterMapp(); ucJob.btnSave.Click += btnSaveInforPrinterJob_Click; ucJob.btnRemove.Hide(); break; } }
void ucPList_Click(object sender, EventArgs e) { UCPrinterList ucPList = (UCPrinterList)sender; PrinterModel item = (PrinterModel)ucPList.Tag; foreach (Control ctr in flpPrintList.Controls) { if (ctr.BackColor == Color.FromArgb(0, 153, 51)) { ctr.BackColor = Color.FromArgb(255, 255, 255); ctr.ForeColor = Color.FromArgb(51, 51, 51); } } ucPList.BackColor = Color.FromArgb(0, 153, 51); ucPList.ForeColor = Color.FromArgb(255, 255, 255); if (pDetail.Controls.Count > 0) { if (pDetail.Controls[0] is UCPrinter) { UCPrinter uc = (UCPrinter)pDetail.Controls[0]; uc.btnRemove.Show(); uc.lblTitle.Text = item.PrintName; uc.txtPrintName.Text = item.PrintName; uc.cbPrintType.SelectedIndex = item.PrinterType; uc.cbSharePrint.SelectedItem = item.PrinterName; uc.btnRemove.Click += btnRemove_Click; uc.btnRemove.Tag = item; uc.btnSave.Click += btnSaveInforPrinter_Click; uc.btnSave.Tag = item; } } else { UCPrinter ucPrinter = new UCPrinter(); ucPrinter.Width = pDetail.Width; ucPrinter.Dock = DockStyle.Fill; pDetail.Controls.Add(ucPrinter); ucPrinter.lblTitle.Text = item.PrintName; ucPrinter.txtPrintName.Text = item.PrintName; ucPrinter.cbPrintType.SelectedIndex = item.PrinterType; ucPrinter.cbSharePrint.SelectedItem = item.PrinterName; ucPrinter.btnRemove.Click += btnRemove_Click; ucPrinter.btnRemove.Tag = item; ucPrinter.btnSave.Click += btnSaveInforPrinter_Click; ucPrinter.btnSave.Tag = item; } }
void btnSaveInforPrinter_Click(object sender, EventArgs e) { try { Button btntag = (Button)sender; PrinterModel item = (PrinterModel)btntag.Tag; UCPrinter uc = (UCPrinter)pDetail.Controls[0]; if (item != null && item.ID > 0) { item.PrintName = uc.txtPrintName.Text ?? ""; item.PrinterName = uc.cbSharePrint.Text ?? ""; item.PrinterType = uc.cbPrintType.SelectedIndex; item.Status = 1; item.UpdateBy = userid; item.UpdateDate = DateTime.Now; var messenger = ""; if (item.PrintName == "") { messenger = messenger + "Printer Name isn't empty. "; } if (item.PrinterName == "") { messenger = messenger + "Shared Printer / Port isn't empty. "; } if (item.PrinterType < 0) { messenger = messenger + "Printer Type isn't empty. "; } if (messenger == "") { int result = PrinterService.UpdatePrinter(item); messenger = "Update " + item.PrintName + " fail. "; if (result == 1) { messenger = "Update " + item.PrintName + " successful. "; LoadDataOfPrinter(); } frmMessager frm = new frmMessager("Messenger", messenger); frmOpacity.ShowDialog(this, frm); } else { frmMessager frm = new frmMessager("Messenger", messenger + "Please input data."); frmOpacity.ShowDialog(this, frm); } } else { item = new PrinterModel(); item.PrintName = uc.txtPrintName.Text ?? ""; item.PrinterName = uc.cbSharePrint.Text ?? ""; item.PrinterType = uc.cbPrintType.SelectedIndex; item.Status = 1; item.CreateBy = userid; item.CreateDate = DateTime.Now; int result = PrinterService.InsertPrinter(item); var messenger = ""; if (item.PrintName == "") { messenger = messenger + "Printer Name isn't empty. "; } if (item.PrinterName == "") { messenger = messenger + "Shared Printer / Port isn't empty. "; } if (item.PrinterType == 0) { messenger = messenger + "Printer Type isn't empty. "; } if (messenger == "") { messenger = "Add new " + item.PrintName + " fail. "; if (result == 1) { messenger = "Add new " + item.PrintName + " successful. "; LoadDataOfPrinter(); pDetail.Controls.Clear(); } frmMessager frm = new frmMessager("Messenger", messenger); frmOpacity.ShowDialog(this, frm); } else { frmMessager frm = new frmMessager("Messenger", messenger + "Please input data."); frmOpacity.ShowDialog(this, frm); } } } catch (Exception ex) { LogPOS.WriteLog("frmPrinterSetting:::::::::::::::::::btnSaveInforPrinter_Click::::::::::::::::" + ex.Message); } }