public Stock_DocumentMenu Delete(Stock_DocumentMenu Item) { var option = new TransactionOptions(); option.IsolationLevel = IsolationLevel.ReadCommitted; //option.Timeout = TimeSpan.FromSeconds(5); using (var tx = new TransactionScope(TransactionScopeOption.Required, option)) { Db.Delete(Item); Db.SaveChanges(); tx.Complete(); return(Item); } }
private void Menu_MDelete_Click(object sender, EventArgs e) { try { Stock_DocumentMenu GData = (Stock_DocumentMenu)gridView1.GetRow(Row_Menu); if (GData == null) { return; } using (var db = new DocumentRunningService(Utility.ConnSDB)) { bool DeleteS = true; var Item = db.LoadAllWhereMenu(GData.Menu_ID); if (Item.Count() > 0) { foreach (var Icheck in Item) { if (Icheck.LastRunningID > 0) { MessageBox.Show("ไม่สามารถลบข้อมูลเมนูได้...เนื่องจาก Running มีการใช้งานไปแล้วครับ", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); DeleteS = false; break; } } } if (DeleteS == false) { return; } } if (MessageBox.Show("คุณต้องการที่จะลบเมนู [" + GData.Menu_ID + "-" + GData.Description + "] หรือไม่ครับ?\nมีผลต่อ Format ที่ถูกตั้งค่าไปแล้วและเลขที่เอกสารที่ใช้ไปแล้ว จะถูกลบทั้งหมด", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { db_Menu.Delete(GData); //using (var db_Log = new ContractLogService()) // db_Log.InsertLog("", Utility._UserDB, DateTime.Now, this.Text, GData.Menu_ID, "Delete", "", "Success!!-ข้อมูลเมนู", "DocumentMenu"); Click_LoadMenu(); Click_loadFormat(GData.Menu_ID); } } catch (Exception ex) { //using (var db_Log = new ContractLogService()) // db_Log.InsertLog("", Utility._UserDB, DateTime.Now, this.Text, "", "Delete", "", "Error!!-ข้อมูลเมนู", "DocumentMenu"); MessageBox.Show("Error!!...::" + ex.Message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { Row_Menu = e.RowHandle; if (e.RowHandle >= 0) { Stock_DocumentMenu GData = (Stock_DocumentMenu)gridView1.GetRow(e.RowHandle); if (GData != null) { groupControl2.Text = "Document Running ของเมนู - [ " + GData.Description + " ]"; MenuID = GData.Menu_ID; Click_LoadRunning(GData.Menu_ID); } } }
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { Row_Menu = e.RowHandle; if (e.RowHandle >= 0) { Stock_DocumentMenu GData = (Stock_DocumentMenu)gridView1.GetRow(e.RowHandle); if (GData != null) { txt_Menu.Text = string.Format("{0} - {1}", GData.Menu_ID, GData.Description); //txt_MenuID.Text = GData.Menu_ID; groupControl2.Text = "ตั้งค่า Document Format ของเมนู - [ " + GData.Description + " ]"; groupControl3.Enabled = true; Click_loadFormat(GData.Menu_ID); } } }
private void btn_Update_Click(object sender, EventArgs e) { if (MessageBox.Show("คุณต้องการที่จะ [แก้ไขข้อมูล] ของเมนูหลักหรือไม่ครับ?", "บัยทึกเมนูหลัก", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } if (txt_MenuID.Text != "" && txt_Description.Text != "") { Stock_DocumentMenu Item = new Stock_DocumentMenu(); Item.Menu_ID = txt_MenuID.Text.Trim(); Item.Description = txt_Description.Text.Trim(); db_Menu.Update(Item); _Success = true; this.Close(); } }
private void btn_Save_Click(object sender, EventArgs e) { if (MessageBox.Show("คุณต้องการที่จะ [บันทึกข้อมูล] ของเมนูหลักหรือไม่ครับ?", "บัยทึกเมนูหลัก", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } if (txt_MenuID.Text != "" && txt_Description.Text != "") { Stock_DocumentMenu Item = new Stock_DocumentMenu(); Item.Menu_ID = txt_MenuID.Text.Trim(); Item.Description = txt_Description.Text.Trim(); db_Menu.Insert(Item); //using (var db_Log = new ContractLogService()) // db_Log.InsertLog("", Utility._UserDB, DateTime.Now, this.Text, Item.Menu_ID, "Insert", "", "Success!! - บัยทึกเมนูหลัก", "DocumentMenu"); _Success = true; this.Close(); } }
private void Menu_MUpdate_Click(object sender, EventArgs e) { try { if (Row_Menu < 0) { return; } Stock_DocumentMenu GData = (Stock_DocumentMenu)gridView1.GetRow(Row_Menu); Frm_CreateMenu F_Menu = new Frm_CreateMenu(); F_Menu.StatusNew = false; F_Menu.ItemUpdate = GData; F_Menu.ShowDialog(); if (Frm_CreateMenu.SuccessFrmLogin) { Click_LoadMenu(); } } catch (Exception ex) { MessageBox.Show("Error!!...::" + ex.Message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Delete(Stock_DocumentMenu Items) { db.DocumentMenu.Remove(Items); }
public void Update(Stock_DocumentMenu Items) { var DEatity = this.GetFind(Items.Menu_ID); DEatity.Description = Items.Description; }
public void Insert(Stock_DocumentMenu Items) { db.DocumentMenu.Add(Items); }
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(); } }