private void RunDeleteData() { try { My.MyDatabase MyDb = new My.MyDatabase(); SIS.Configuration.ClsPurchaseConfig CPC = new Configuration.ClsPurchaseConfig(); CPC.PurchaseID = txtPurchaseID.Text; SIS.DBClass.DBClassPurchaseMaster DBCPM = new DBClass.DBClassPurchaseMaster(); if (MyDb.AuthPK(CPC.PurchaseID, "PurchaseID", "PurchaseMaster") == true) { if (DBCPM.DeleteMasterDetailsData(CPC.PurchaseID)) { MessageBox.Show("刪除[" + CPC.PurchaseID + "]採購單資料成功", "刪除採購單資料", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDefaultValue(); } else { MessageBox.Show("刪除[" + CPC.PurchaseID + "]採購單資料失敗", "刪除採購單資料", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("對不起,資料庫不存在[ " + CPC.PurchaseID + " ]採購單資料!!(資料不存在)", "資料刪除"); } } catch (Exception ex) { MessageBox.Show("錯誤訊息:" + ex.Message.ToString(), "發生例外"); } }
/// <summary> /// 將資料寫入資料庫中 /// </summary> private void RunInsertData() { try { My.MyDatabase MyDb = new My.MyDatabase(); SIS.Configuration.ClsPurchaseConfig CPC = new Configuration.ClsPurchaseConfig(); CPC.PurchaseID = txtPurchaseID.Text; CPC.PurchaseDate = dtpPurchaseDate.Value.ToString("yyyy年MM月dd日"); CPC.DeliveryDate = dtpDeliveryDate.Value.ToString("yyyy年MM月dd日"); CPC.ManufacturerID = cboManufacturer.Text.Substring(0, cboManufacturer.Text.IndexOf("-")); CPC.PurchaseStaff = cboPurchaseStaff.Text; CPC.PurchasePhone = mtbPurchasePhone.Text; CPC.DeliveryAddress = cboDeliveryAddress.Text; CPC.PaymentType = cboPaymentType.Text.Split('-')[1]; CPC.BusinessTaxStockTaxRate = int.Parse(txtBusinessTaxStockTaxRate.Text); CPC.TotalPreTax = int.Parse(txtTotalPreTax.Text); CPC.Tax = int.Parse(txtTax.Text); CPC.TotalAfterTax = int.Parse(txtTotalAfterTax.Text); CPC.Notes = rtbNotes.Text.Replace("'", "''"); CPC.PurchaseItems = getItemsValueFromDataGridView(dgvPurchaseDetails); //SIS.DBClass.DBClassPurchaseMaster DBCPM = new DBClass.DBClassPurchaseMaster(); //實作工廠模式(Factory Pattern) var Processor = SIS.Configuration.SISProcessorFactory.getInstance(SIS.Configuration.SISOperating.Purchase); if (MyDb.AuthPK(CPC.PurchaseID, "PurchaseID", "PurchaseMaster") == false) { if (Processor.Insert(CPC)) //DBCPM.InsertData(CPC) { MessageBox.Show("新增[" + CPC.PurchaseID + "]採購單資料成功", "新增採購單資料", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDefaultValue(); } else { MessageBox.Show("新增[" + CPC.PurchaseID + "]採購單資料失敗", "新增採購單資料", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("對不起,資料庫已存在[ " + CPC.PurchaseID + " ]採購單資料!!(資料重複)", "資料新增"); } } catch (Exception ex) { MessageBox.Show("錯誤訊息:" + ex.Message.ToString(), "發生例外"); } }
//查詢 private void tsbQuery_Click(object sender, EventArgs e) { string Msg = "是否要進行採購單[" + txtPurchaseID.Text + "]查詢動作?\r\n"; DialogResult DR; DR = MessageBox.Show(Msg, "查詢採購單", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (DR == DialogResult.Yes) { if (CheckField()) { SIS.DBClass.DBClassPurchaseMaster DBCPM = new DBClass.DBClassPurchaseMaster(); SIS.Configuration.ClsPurchaseConfig CPC = new Configuration.ClsPurchaseConfig(); bool result = DBCPM.QueryData(txtPurchaseID.Text, CPC); if (result) { MessageBox.Show("有找到採購單號:[" + txtPurchaseID.Text + "]資料!\r\n是否將採購單資料載入?", "搜尋結果", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DR == DialogResult.Yes) { txtPurchaseID.Text = CPC.PurchaseID; dtpPurchaseDate.Text = CPC.PurchaseDate; dtpDeliveryDate.Text = CPC.DeliveryDate; cboManufacturer.Text = My.MyMethod.SearchComboBoxItems(cboManufacturer, CPC.ManufacturerID); cboPurchaseStaff.Text = CPC.PurchaseStaff; mtbPurchasePhone.Text = CPC.PurchasePhone; cboDeliveryAddress.Text = CPC.DeliveryAddress; cboPaymentType.Text = My.MyMethod.SearchComboBoxItems(cboPaymentType, CPC.PaymentType); txtBusinessTaxStockTaxRate.Text = CPC.BusinessTaxStockTaxRate.ToString(); txtTotalPreTax.Text = CPC.TotalPreTax.ToString(); txtTax.Text = CPC.Tax.ToString(); txtTotalAfterTax.Text = CPC.TotalAfterTax.ToString(); rtbNotes.Text = CPC.Notes; if (dgvPurchaseDetails.Rows.Count > 1) { btnRemoveItems_Click(sender, e); } for (int i = 0; i < CPC.PurchaseItems.Length; i++) { var index = dgvPurchaseDetails.Rows.Add(); dgvPurchaseDetails.Rows[index].Cells["ItemsID"].Value = CPC.PurchaseItems[i].ItemsID; dgvPurchaseDetails.Rows[index].Cells["NAME"].Value = CPC.PurchaseItems[i].NAME; dgvPurchaseDetails.Rows[index].Cells["Quantity"].Value = CPC.PurchaseItems[i].Quantity.ToString(); dgvPurchaseDetails.Rows[index].Cells["ItemsUnit"].Value = CPC.PurchaseItems[i].ItemsUnit; dgvPurchaseDetails.Rows[index].Cells["CostPrice"].Value = CPC.PurchaseItems[i].Price.ToString(); dgvPurchaseDetails.Rows[index].Cells["Totals"].Value = CPC.PurchaseItems[i].Totals.ToString(); dgvPurchaseDetails.Rows[index].Cells["Notes"].Value = CPC.PurchaseItems[i].Notes; } getTaxTotals(); } } else { MessageBox.Show("沒有找到採購單號:[" + txtPurchaseID.Text + "]資料!", "搜尋結果"); } } } else { MessageBox.Show("取消採購單查詢動作!!", "查詢採購單"); } //if (DV.Count == 0) //{ // MessageBox.Show("搜尋條件並未找到任何符合資料", "搜尋結果", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); //} //else //{ // MessageBox.Show("共找到資料筆數" + DV.Count.ToString(), "搜尋結果"); //} }