private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } if (e.ColumnIndex == 0) { //編輯 //DataGridViewButtonCell clickedButtonCell = (DataGridViewButtonCell)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; int colIndex = this.dataGridView1.GetColumnIndex("料件編號"); string pn = dataGridView1.Rows[e.RowIndex].Cells[colIndex].Value.ToString(); colIndex = this.dataGridView1.GetColumnIndex("採購數量"); string qty = dataGridView1.Rows[e.RowIndex].Cells[colIndex].Value.ToString(); colIndex = this.dataGridView1.GetColumnIndex("SourceListOID"); int sl = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[colIndex].Value); POSetQtyForm frm = new POSetQtyForm { CmdMode = POSetQtyForm.CommandMode.Edit, PartNumber = pn, Qty = qty, SourceListOID = sl, ListIndex = e.RowIndex }; Common.ContainerForm.NextForm(frm); } else if (e.ColumnIndex == 1) { //刪除 PurchasingOrderUtil.GetPurchasingOrderDetail().RemoveAt(e.RowIndex); this.Init(); } }
void Init() { this.lblPODCount.Text = PurchasingOrderUtil.GetPurchasingOrderDetailStatus(); decimal total = 0.0M; SourceListDao slDao = new SourceListDao(); List <Model.PurchasingOrderDetail> pods = PurchasingOrderUtil.GetPurchasingOrderDetail(); var q = from s in pods select s.SourceListOID; DataTable dt = new DataTable(); object resultObj = null; if (!(pods == null || pods.Count == 0)) { dt = slDao.FineSourceListForPOAddMain(q.ToList()); dt.PrimaryKey = new DataColumn[] { dt.Columns["SourceListOID"] }; var qs = from pod in pods select new { 料件編號 = GetDTValue(dt, "料件編號", pod.SourceListOID), 料件品名 = GetDTValue(dt, "料件品名", pod.SourceListOID), 供應商名稱 = GetDTValue(dt, "供應商名稱", pod.SourceListOID), 批量 = GetDTValue(dt, "批量", pod.SourceListOID), 批量單價 = $"{Convert.ToDecimal(GetDTValue(dt, "批量單價", pod.SourceListOID)):#.#}", 採購數量 = $"{pod.Qty:#.#}", 小計 = (Convert.ToDecimal(GetDTValue(dt, "批量單價", pod.SourceListOID)) * pod.Qty).ToString("#.#"), pod.SourceListOID }; var result = qs.ToList(); foreach (var item in result) { total += Convert.ToDecimal(item.小計); } resultObj = result; } this.lblTotal.Text = $"採購單金額總計:{total:0.#}"; this.dataGridView1.Columns.Clear(); if (resultObj != null) { this.DataGridViewAddButton(); } this.POD.DataSource = resultObj; this.dataGridView1.DataSource = this.POD; if (resultObj != null) { this.dataGridView1.Columns[this.dataGridView1.GetColumnIndex("SourceListOID")].Visible = false; } this.btnSendPO.Enabled = !(PurchasingOrderUtil.GetPurchasingOrderDetailCount() == 0); }
private void btnSendPO_Click(object sender, EventArgs e) { if (MessageBox.Show("您確定要新增此筆採購單嗎?", "確認新增", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { PurchasingOrderDao dao = new PurchasingOrderDao(); dao.InsertPurchasingOrderAndDetail(Common.ContainerForm.BuyerLoginAccount.EmployeeID, PurchasingOrderUtil.GetPurchasingOrderDetail()); MessageBox.Show("新增採購單成功"); List <Model.PurchasingOrderDetail> details = PurchasingOrderUtil.GetPurchasingOrderDetail(); details.Clear(); Common.ContainerForm.NextForm(new PurchasingOrderForm()); } }
private void btnAddToPO_Click(object sender, EventArgs e) { int qty = 0; if (!int.TryParse(txtQty.Text.Trim(), out qty)) { MessageBox.Show("請輸入正確數字"); return; } switch (this.CmdMode) { case CommandMode.Add: PurchasingOrderDetail pod = new PurchasingOrderDetail() { SourceListOID = Convert.ToInt32(this.cbSourceList.SelectedValue), Qty = qty }; PurchasingOrderUtil.SetPurchasingOrderDetail(pod); this.lblPODCount.Text = PurchasingOrderUtil.GetPurchasingOrderDetailStatus(); break; case CommandMode.Edit: PurchasingOrderDetail updatePod = PurchasingOrderUtil.GetPurchasingOrderDetail()[this.ListIndex]; updatePod.SourceListOID = Convert.ToInt32(this.cbSourceList.SelectedValue); updatePod.Qty = qty; Common.ContainerForm.NextForm(new POAddMainForm()); break; case CommandMode.OrderEdit: Model.SourceList sl = this.sourceLists.Find(s => s.SourceListOID.Equals(Convert.ToInt32(this.cbSourceList.SelectedValue))); this.SourceOrderListData.Batch = sl.Batch; this.SourceOrderListData.Discount = sl.Discount; this.SourceOrderListData.Qty = Convert.ToInt32(this.txtQty.Text); SourceOrderListDao dao = new SourceOrderListDao(); dao.Update(this.SourceOrderListData); CheckOrderForm cof = new CheckOrderForm(this.SourceOrderListData.GetOrderPart().OrderID, "edit"); Common.ContainerForm.NextForm(cof); break; default: break; } }