private void MenuClick_Update_Click(object sender, EventArgs e) { if (Row_Format < 0) { return; } if (grd_FormatS.RowCount <= 0) { return; } Stock_DocumentFormat GData = (Stock_DocumentFormat)grd_FormatS.GetRow(Row_Format); db_Format = new DocumentFormatService(Utility.ConnSDB); var item = db_Format.GetFind(GData.Format_Id, GData.Menu_ID); //swith_DocGroup.IsOn = Convert.ToBoolean(item.Prefix_Enable); txt_DocGroup.Text = item.Prefix; swith_Year.IsOn = Convert.ToBoolean(item.Year_Enable); rdo_YearLen.EditValue = item.Year_Len == null ? 2 : item.Year_Len; swith_Month.IsOn = Convert.ToBoolean(item.Month_Enable); swith_Day.IsOn = Convert.ToBoolean(item.Day_Enable); num_Running.Value = Convert.ToDecimal(item.Running_Len); txt_Description.Text = item.Description; txt_FormatDisplay.Text = item.Stock_DocumentRunning == null ? "" : item.Stock_DocumentRunning.FormatDisplay; txt_FormatString.Text = item.Stock_DocumentRunning == null ? "" : item.Stock_DocumentRunning.FormatString; txt_FormatID.Text = item.Format_Id.ToString(); btn_Update.Visible = true; lbl_Update.Visible = true; btn_Save.Visible = false; lbl_New.Visible = false; }
public void Update(Stock_DocumentFormat Items) { var DEntity = this.GetFind(Items.Format_Id, Items.Menu_ID); DEntity.Running_Len = Items.Running_Len; DEntity.Prefix_Enable = Items.Prefix_Enable; DEntity.Prefix = Items.Prefix; DEntity.Year_Enable = Items.Year_Enable; DEntity.Year_Len = Items.Year_Len; DEntity.Month_Enable = Items.Month_Enable; DEntity.Day_Enable = Items.Day_Enable; DEntity.Description = Items.Description; }
public bool ValidateFormat(Stock_DocumentFormat Item) { var query = db.DocumentFormat.Where(c => c.Running_Len == Item.Running_Len && c.Prefix_Enable == Item.Prefix_Enable && c.Prefix == Item.Prefix && c.Year_Enable == Item.Year_Enable && c.Year_Len == Item.Year_Len && c.Month_Enable == Item.Month_Enable && c.Day_Enable == Item.Day_Enable && c.Description == Item.Description).ToList(); if (query.Count > 0) { return(false); } else { return(true); } }
public Stock_DocumentFormat Update(Stock_DocumentFormat Item, Stock_DocumentRunning ItemR) { var option = new TransactionOptions(); option.IsolationLevel = IsolationLevel.ReadCommitted; //option.Timeout = TimeSpan.FromSeconds(5); using (var tx = new TransactionScope(TransactionScopeOption.Required, option)) { Db.Update(Item); Db.SaveChanges(); Db_Run.Update(ItemR); Db_Run.SaveChanges(); tx.Complete(); return(Item); } }
private void MenuClick_Delete_Click(object sender, EventArgs e) { Stock_DocumentFormat GData = (Stock_DocumentFormat)grd_FormatS.GetRow(Row_Format); if (GData == null) { return; } using (var Db = new DocumentRunningService(Utility.ConnSDB)) { Stock_DocumentRunning ICheck = Db.GetFind(GData.Format_Id, GData.Menu_ID); if (ICheck != null) { if (ICheck.LastRunningID > 0) { MessageBox.Show("Running ถูกใช้งานแล้ว [ทั้งหมด : " + ICheck.LastRunningID + "] แล้ว...ไม่สามารถลบได้ครับ", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } if (MessageBox.Show("คุณต้องการที่จะลบข้อมูลของ [ " + GData.Prefix + "-" + GData.Description + " ] หรือไม่ครับ?", "ยืนยันการลบ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { try { db_Format.Delete(GData.Format_Id, GData.Menu_ID); //using (var db_Log = new ContractLogService()) // db_Log.InsertLog("", Utility._UserDB, DateTime.Now, this.Text, GData.Format_Id.ToString(), "Delete", "", "Success!!-ข้อมูล Format", "DocumentFormat"); Click_loadFormat(GData.Menu_ID); } catch (Exception ex) { //using (var db_Log = new ContractLogService()) // db_Log.InsertLog("", Utility._UserDB, DateTime.Now, this.Text, GData.Format_Id.ToString(), "Delete", "", "Error!!-ข้อมูล Format", "DocumentFormat"); MessageBox.Show("Error : " + ex.Message, "Error...!!"); } } }
public void Delete(Stock_DocumentFormat Items) { db.DocumentFormat.Remove(Items); }
public void Insert(Stock_DocumentFormat Items) { db.DocumentFormat.Add(Items); }
public bool ValidateFormat(Stock_DocumentFormat Item) { return(Db.ValidateFormat(Item)); }
private void btn_Update_Click(object sender, EventArgs e) { if (dxValidationProvider1.Validate() == false) { return; } DateTime DateCurrent = db_Run.GetDate(); Stock_DocumentMenu GData = (Stock_DocumentMenu)gridView1.GetRow(Row_Menu); Stock_DocumentFormat GDataFM = (Stock_DocumentFormat)grd_FormatS.GetRow(Row_Format); if (MessageBox.Show("คุณยืนยันที่จะทำการ [แก้ไข] รูปแบบเอกสาร [" + string.Format("{0}-{1}", GDataFM.Menu_ID, GDataFM.Description) + "] นี้หรือไม่ครับ?", "ยืนยันการแก้ไข", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Stock_DocumentFormat item = new Stock_DocumentFormat(); item.Format_Id = GDataFM.Format_Id; item.Menu_ID = GDataFM.Menu_ID; item.Running_Len = Convert.ToInt32(num_Running.Value); item.Prefix_Enable = true;//swith_DocGroup.IsOn; item.Prefix = txt_DocGroup.Text.Trim(); item.Year_Enable = swith_Year.IsOn; item.Day_Enable = swith_Day.IsOn; if (swith_Year.IsOn) { item.Year_Len = Convert.ToInt32(rdo_YearLen.EditValue); } item.Month_Enable = swith_Month.IsOn; item.Description = txt_Description.Text.Trim(); Stock_DocumentRunning itemR = db_Run.GetFind(item.Format_Id, item.Menu_ID);// new DocumentRunning(); bool _ResetRunning = false; itemR.Prefix = txt_DocGroup.Text.Trim(); if (swith_Year.IsOn) { int YearR = Convert.ToInt32(rdo_YearLen.EditValue); string SYear = DateCurrent.Year > 2400 ? DateCurrent.Year.ToString() : (DateCurrent.Year + 543).ToString(); if (YearR == 4) { if (itemR.DocYear != null) { if (itemR.DocYear.Value.ToString().Length == 4) { if (Convert.ToInt32(SYear.Substring(0, YearR)) > itemR.DocYear)//เทียบปีปัจจุบันว่าเปลี่ยนไปหรือป่าว { itemR.DocYear = Convert.ToInt32(SYear.Substring(0, YearR)); _ResetRunning = true; } } else//ไม่เคยมี Setting นี้ { if (itemR.DocYear.Value.ToString().Length == 2)//เช็คว่าอันเดิมเป็น 2 ตำแหน่งหรือไม่ แล้วทำการเปรียบเทียบว่า ปีเท่ากันมั้ย { if (Convert.ToInt32(SYear.Substring(2, 2)) > itemR.DocYear)//เทียบปีปัจจุบันว่าเปลี่ยนไปหรือป่าว { itemR.DocYear = Convert.ToInt32(SYear.Substring(0, YearR)); _ResetRunning = true; } else { itemR.DocYear = Convert.ToInt32(SYear.Substring(0, YearR)); } } else { itemR.DocYear = Convert.ToInt32(SYear.Substring(0, YearR)); _ResetRunning = true; } } } else//ไม่เคยมี Setting นี้ { itemR.DocYear = Convert.ToInt32(SYear.Substring(0, YearR)); _ResetRunning = true; } } else { if (itemR.DocYear != null) { if (itemR.DocYear.Value.ToString().Length == 2) { if (Convert.ToInt32(SYear.Substring(2, YearR)) > itemR.DocYear)//เทียบปีปัจจุบันว่าเปลี่ยนไปหรือป่าว { itemR.DocYear = Convert.ToInt32(SYear.Substring(2, YearR)); _ResetRunning = true; } } else//ไม่เคยมี Setting นี้ { if (itemR.DocYear.Value.ToString().Length == 4)//เช็คว่าอันเดิมเป็น 4 ตำแหน่งหรือไม่ แล้วทำการเปรียบเทียบว่า ปีเท่ากันมั้ย { if (Convert.ToInt32(SYear.Substring(0, 4)) > itemR.DocYear)//เทียบปีปัจจุบันว่าเปลี่ยนไปหรือป่าว { itemR.DocYear = Convert.ToInt32(SYear.Substring(2, YearR)); _ResetRunning = true; } else { itemR.DocYear = Convert.ToInt32(SYear.Substring(2, YearR)); } } else { itemR.DocYear = Convert.ToInt32(SYear.Substring(2, YearR)); _ResetRunning = true; } } } else//ไม่เคยมี Setting นี้ { itemR.DocYear = Convert.ToInt32(SYear.Substring(2, YearR)); _ResetRunning = true; } } } else { itemR.DocYear = null; } if (swith_Month.IsOn) { if (itemR.DocMonth != null) { if (DateCurrent.Month > itemR.DocMonth) { itemR.DocMonth = DateCurrent.Month; _ResetRunning = true; } } else//ไม่เคยปี Setting นี้ { itemR.DocMonth = DateCurrent.Month; _ResetRunning = true; } } else { itemR.DocMonth = null; } if (swith_Day.IsOn) { if (itemR.DocDay != null) { if (DateCurrent.Day > itemR.DocDay) { itemR.DocDay = DateCurrent.Day;; _ResetRunning = true; } } else//ไม่เคยปี Setting นี้ { itemR.DocDay = DateCurrent.Day; _ResetRunning = true; } } else { itemR.DocDay = null; } if (_ResetRunning)// Reset Running is 0 { itemR.LastRunningID = 0; } itemR.FormatString = txt_FormatString.Text.Trim(); itemR.FormatDisplay = txt_FormatDisplay.Text.Trim(); itemR.Description = txt_Description.Text.Trim(); itemR.Active = 1; db_Format.Update(item, itemR); //using (var db_Log = new ContractLogService()) // db_Log.InsertLog("", Utility._UserDB, DateTime.Now, this.Text, item.Format_Id.ToString(), "Update", "", "Success!!-ข้อมูล Format Running", "DocumentFormat,DocumentRunning"); Click_loadFormat(GData.Menu_ID); Click_Clear(); } }
private void btn_Save_Click(object sender, EventArgs e) { if (dxValidationProvider1.Validate() == false) { return; } DateTime DateCurrent = db_Run.GetDate(); if (MessageBox.Show("คุณยืนยันที่จะทำการ [บันทึก] รูปแบบเอกสารนี้หรือไม่ครับ?", "ยืนยันการบันทึก", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Stock_DocumentMenu GData = (Stock_DocumentMenu)gridView1.GetRow(Row_Menu); Stock_DocumentFormat item = new Stock_DocumentFormat(); item.Menu_ID = GData.Menu_ID; item.Running_Len = Convert.ToInt32(num_Running.Value); item.Prefix_Enable = true;//swith_DocGroup.IsOn; item.Prefix = txt_DocGroup.Text.Trim(); item.Year_Enable = swith_Year.IsOn; if (swith_Year.IsOn) { item.Year_Len = Convert.ToInt32(rdo_YearLen.EditValue); } item.Month_Enable = swith_Month.IsOn; item.Day_Enable = swith_Day.IsOn; item.Description = txt_Description.Text.Trim(); Stock_DocumentRunning itemR = new Stock_DocumentRunning(); itemR.Prefix = txt_DocGroup.Text.Trim(); if (swith_Year.IsOn) { int YearR = Convert.ToInt32(rdo_YearLen.EditValue); string SYear = DateCurrent.Year > 2400 ? DateCurrent.Year.ToString() : (DateCurrent.Year + 543).ToString(); if (YearR == 4) { itemR.DocYear = Convert.ToInt32(SYear.Substring(0, YearR)); } else { itemR.DocYear = Convert.ToInt32(SYear.Substring(2, YearR)); } } if (swith_Month.IsOn) { itemR.DocMonth = DateCurrent.Month; } if (swith_Day.IsOn) { itemR.DocDay = DateCurrent.Day; } itemR.LastRunningID = 0; itemR.FormatString = txt_FormatString.Text.Trim(); itemR.FormatDisplay = txt_FormatDisplay.Text.Trim(); itemR.Description = txt_Description.Text.Trim(); itemR.Active = 1; if (db_Format.ValidateFormat(item)) { db_Format.Insert(item, itemR); //using (var db_Log = new ContractLogService()) // db_Log.InsertLog("", Utility._UserDB, DateTime.Now, this.Text, item.Format_Id.ToString(), "Insert", "", "Success!!-ข้อมูล Format Running", "DocumentFormat,DocumentRunning"); } else { //using (var db_Log = new ContractLogService()) // db_Log.InsertLog("", Utility._UserDB, DateTime.Now, this.Text, item.Format_Id.ToString(), "Insert", "เนื่องจากข้อมูลชุดนี้มีการบันทึกในฐานข้อมูลอยู่แล้ว", "Error!!-ข้อมูล Format Running", "DocumentFormat,DocumentRunning"); MessageBox.Show("ไม่สามารถบันทึกข้อมูลได้...เนื่องจากข้อมูลชุดนี้มีการบันทึกในฐานข้อมูลอยู่แล้ว\nกรุณาเปลี่ยนแปลงรูปแบบ Format ด้วยครับ", "ข้อมูลซ้ำ", MessageBoxButtons.OK, MessageBoxIcon.Error); } Click_loadFormat(GData.Menu_ID); Click_Clear(); } }