private void RunDeleteData() { My.MyDatabase MyDb = new My.MyDatabase(); SIS.Configuration.ClsItemsConfig CIC = new Configuration.ClsItemsConfig(); CIC.ItemsID = txtItemsID.Text; CIC.NAME = txtNAME.Text; SIS.DBClass.DBClassItemsInfo DBCII = new DBClass.DBClassItemsInfo(); if (MyDb.AuthPK(CIC.ItemsID, "ItemsID", "ItemsInfo") == true) { if (DBCII.DeleteOneData(CIC.ItemsID)) { MessageBox.Show("刪除[" + CIC.ItemsID + "-" + CIC.NAME + "]商品資料成功", "刪除商品資料", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDefaultValue(); } else { MessageBox.Show("刪除[" + CIC.ItemsID + "-" + CIC.NAME + "]商品資料失敗", "刪除商品資料", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("對不起,資料庫不存在[ " + CIC.ItemsID + "-" + CIC.NAME + " ]商品資料!!(資料不存在)", "資料刪除"); } }
/// <summary> /// 將資料寫入資料庫中 /// </summary> private void RunInsertData() { try { My.MyDatabase MyDb = new My.MyDatabase(); SIS.Configuration.ClsItemsConfig CIC = new Configuration.ClsItemsConfig(); CIC.ItemsID = txtItemsID.Text; CIC.NAME = txtNAME.Text; CIC.ItemsType = cboItemsType.Text.Substring(0, cboItemsType.Text.IndexOf("-")); CIC.Specifications = txtSpecifications.Text.Replace("'", "''"); //將一個單引號置換成二個單引號避免SQL語法錯誤 CIC.ItemsUnit = cboItemsUnit.Text; CIC.SellingPrice = int.Parse(mtbSellingPrice.Text); CIC.CostPrice = int.Parse(mtbCostPrice.Text); CIC.MSRP = int.Parse(mtbMSRP.Text); CIC.ManufacturerID = cboManufacturer.Text.Substring(0, cboManufacturer.Text.IndexOf("-")); CIC.Inventory = int.Parse(mtbInventory.Text); CIC.SafeInventory = int.Parse(mtbSafeInventory.Text); CIC.Notes = rtbNotes.Text.Replace("'", "''"); SIS.DBClass.DBClassItemsInfo DBCII = new DBClass.DBClassItemsInfo(); if (MyDb.AuthPK(CIC.ItemsID, "ItemsID", "ItemsInfo") == false) { if (DBCII.InsertData(CIC)) { MessageBox.Show("新增[" + CIC.ItemsID + "-" + CIC.NAME + "]商品資料成功", "新增商品資料", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDefaultValue(); } else { MessageBox.Show("新增[" + CIC.ItemsID + "-" + CIC.NAME + "]商品資料失敗", "新增商品資料", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("對不起,資料庫已存在[ " + CIC.ItemsID + "-" + CIC.NAME + " ]商品資料!!(資料重複)", "資料新增"); } } catch (Exception ex) { MessageBox.Show("錯誤訊息:" + ex.Message.ToString(), "發生例外"); } }
private void RunUpdateData() { My.MyDatabase MyDb = new My.MyDatabase(); SIS.Configuration.ClsItemsConfig CIC = new Configuration.ClsItemsConfig(); CIC.ItemsID = txtItemsID.Text; CIC.NAME = txtNAME.Text; CIC.ItemsType = cboItemsType.Text.Substring(0, cboItemsType.Text.IndexOf("-")); CIC.Specifications = txtSpecifications.Text.Replace("'", "''"); CIC.ItemsUnit = cboItemsUnit.Text; CIC.SellingPrice = int.Parse(mtbSellingPrice.Text); CIC.CostPrice = int.Parse(mtbCostPrice.Text); CIC.MSRP = int.Parse(mtbMSRP.Text); CIC.ManufacturerID = cboManufacturer.Text.Substring(0, cboManufacturer.Text.IndexOf("-")); CIC.Inventory = int.Parse(mtbInventory.Text); CIC.SafeInventory = int.Parse(mtbSafeInventory.Text); CIC.Notes = rtbNotes.Text.Replace("'", "''"); SIS.DBClass.DBClassItemsInfo DBCII = new DBClass.DBClassItemsInfo(); if (MyDb.AuthPK(CIC.ItemsID, "ItemsID", "ItemsInfo") == true) { if (DBCII.Update(CIC)) { MessageBox.Show("更新[" + CIC.ItemsID + "-" + CIC.NAME + "]商品資料成功", "更新商品資料", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDefaultValue(); } else { MessageBox.Show("更新[" + CIC.ItemsID + "-" + CIC.NAME + "]商品資料失敗", "更新商品資料", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("對不起,資料庫不存在[ " + CIC.ItemsID + "-" + CIC.NAME + " ]商品資料!!(資料不存在)", "資料更新"); } }