public int RemoveDataPrinterJob(PrintJobModel data) { try { //if (data!=null) //{ // var printjob = _context.PRINT_JOB.Find(data.ID); // if (printjob != null) // { // printjob.Status = 0; // printjob.UpdateBy = data.UpdateBy; // printjob.UpdateDate = DateTime.Now; // _context.Entry(printjob).State = System.Data.Entity.EntityState.Modified; // _context.SaveChanges(); // var detail =_context.PRINTE_JOB_DETAIL.Where(x => x.PrinteJobID == printjob.ID && x.Status == 1).ToList(); // foreach (var item in detail) // { // item.Status = 0; // item.UpdateBy = data.UpdateBy; // item.UpdateDate = DateTime.Now; // _context.Entry(item).State = System.Data.Entity.EntityState.Modified; // _context.SaveChanges(); // } // return 1; // } //} //return 0; } catch (Exception ex) { LogPOS.WriteLog("Service Printer Job:::::::::::::::::::RemoveDataPrinterJob::::::::::::::::" + ex.Message); return 0; } return 0; }
public int SaveDataPrinterJob(PrintJobModel data) { try { #region Update if (data.ID > 0) { var printejob = _context.PRINT_JOB.Find(data.ID); if (printejob != null) { printejob.PrintJobName = data.PrintJobName; printejob.PrintContent = data.PrintContent; printejob.UpdateBy = data.UpdateBy; printejob.UpdateDate = DateTime.Now; _context.Entry(printejob).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); foreach (var item in data.dataDetail) { if (item.ID > 0) { var tempitem = _context.PRINTE_JOB_DETAIL.Find(item.ID); if (tempitem!=null) { tempitem.CategoryID = item.CategoryID; tempitem.ProductID = item.ProductID; tempitem.PrinterID = item.PrinterID; tempitem.TemplatesID = item.TemplatesID; tempitem.UpdateBy = item.UpdateBy; tempitem.UpdateDate = DateTime.Now; _context.Entry(tempitem).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); } } else { var tempitem = new PRINTE_JOB_DETAIL(); //tempitem.PrinteJobID = printejob.ID; tempitem.CategoryID = item.CategoryID; tempitem.ProductID = item.ProductID; tempitem.PrinterID = item.PrinterID; tempitem.TemplatesID = item.TemplatesID; tempitem.Status = 1; tempitem.Notes = item.Notes??""; tempitem.CreateBy = item.CreateBy; tempitem.CreateDate = DateTime.Now; _context.Entry(tempitem).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } } return 1; } return 0; } #endregion Update #region Insert else { var printejob = new PRINT_JOB(); printejob.PrintJobName = data.PrintJobName; printejob.PrintContent = data.PrintContent; printejob.Status = 1; printejob.CreateBy = data.CreateBy; printejob.CreateDate = DateTime.Now; _context.Entry(printejob).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); foreach (var item in data.dataDetail) { var tempitem = new PRINTE_JOB_DETAIL(); //tempitem.PrinteJobID = printejob.ID; tempitem.CategoryID = item.CategoryID; tempitem.ProductID = item.ProductID; tempitem.PrinterID = item.PrinterID; tempitem.TemplatesID = item.TemplatesID; tempitem.Status = 1; tempitem.Notes = item.Notes ?? ""; tempitem.CreateBy = item.CreateBy; tempitem.CreateDate = DateTime.Now; _context.Entry(tempitem).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } return 1; } #endregion Insert } catch (Exception ex) { LogPOS.WriteLog("Service Printer Job:::::::::::::::::::SaveDataPrinterJob::::::::::::::::" + ex.Message); return 0; } }
void btnSaveInforPrinterJob_Click(object sender, EventArgs e) { try { Button btntag = (Button)sender; PrintJobModel item = (PrintJobModel)btntag.Tag; if (item == null) item = new PrintJobModel(); UCPrinterJobDetail ucJob = (UCPrinterJobDetail)pDetail.Controls[0]; item.PrintJobName = ucJob.txtPrintJobName.Text ?? ""; item.PrintContent = ((KeyValueModel)ucJob.cbPrintContent.SelectedItem).Value ?? ""; item.CreateBy = userid; item.UpdateBy = userid; if (item.dataDetail==null) item.dataDetail= new List<PrintJobDetailModel>(); foreach (UCPrinterMapping mapPrinter in ucJob.flpPriterMap.Controls) { PrintJobDetailModel temp = (PrintJobDetailModel)mapPrinter.Tag; if (temp==null) temp= new PrintJobDetailModel(); temp.CategoryID = ((KeyValueModel)mapPrinter.cbGroupItem.SelectedItem).Key; temp.ProductID = ((KeyValueModel)mapPrinter.cbItem.SelectedItem).Key; temp.PrinterID = ((KeyValueModel)mapPrinter.cbPrinter.SelectedItem).Key; temp.TemplatesID = ((KeyValueModel)mapPrinter.cbTemplate.SelectedItem).Key; temp.CreateBy = userid; temp.UpdateBy = userid; item.dataDetail.Add(temp); } var messenger = ""; if (item.PrintJobName == "") messenger = messenger + "Print Job Name isn't empty. "; if (item.PrintContent == "") messenger = messenger + "Print Content isn't empty. "; if (messenger == "") { var result = PrinterService.SaveDataPrinterJob(item); messenger = "Save data infor printe job fail. "; if (result > 0) { messenger = "Save data infor printe job successful. "; LoadPriterJob(); 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) { frmMessager frm = new frmMessager("Messenger", "Please save again."); frmOpacity.ShowDialog(this, frm); LogPOS.WriteLog("frmPrinterSetting:::::::::::::::::::btnSaveInforPrinterJob_Click::::::::::::::::" + ex.Message); } }