|
|
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.Sql; using System.Data.SqlClient; using System.Configuration; using System.Xml.Linq; using System.IO; using ManagementSystem.Utility;
namespace ManagementSystem { public partial class PayPlanManagement : Form { //程式內共用物件
public bool blIsAdded = true; //判斷分錄是否寫入成功
string strFrmStatus = ""; //表單狀態
string strActiveUserID = ""; //取得登入作用的使用者帳號
string strAccountingBookID = ""; //取得作用中的帳本
SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID); SqlTransaction sqlTran; SqlCommand sqlCmd = new SqlCommand(); DataSet sdInsurance = new System.Data.DataSet(); string strKey = ""; //程式內加密的Key值
public PayPlanManagement() { InitializeComponent(); }
#region 自定義程式
private void SetupStatus() //畫面載入設定
{ try { strActiveUserID = MainForm.strActiveUserID; strAccountingBookID = MainForm.strAccountingBookID; strKey = MainForm.strKey; //設定畫面初始狀態
StatusChange("NONE"); } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
public void StatusChange(string strStatus) //變更主畫面狀態
{ try { switch (strStatus.ToUpper()) { case "NONE": CleanForm(); CleanToolbar(); LockForm(); dgvOrderContent.AllowUserToAddRows = false; dgvOutSourcingContent.AllowUserToAddRows = false; dgvReceiptPlan.AllowUserToAddRows = false; dgvOrderList.ReadOnly = true; ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = ""; strFrmStatus = ""; tsbSearch.Enabled = true; break; case "SEARCH": UnLockFormHead(); CleanForm(); btnGetSalesOrderNo.Enabled = false; tsbSearch.Visible = false; tsbEdit.Enabled = false; tsbDelete.Enabled = false; tsbSave.Visible = false; tsbOK.Visible = true; tsbCancel.Visible = true; dgvOrderContent.AllowUserToAddRows = false; dgvOutSourcingContent.AllowUserToAddRows = false; dgvReceiptPlan.AllowUserToAddRows = false; ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "搜尋"; strFrmStatus = "SEARCH"; break; case "ADD": //本程式不提供新增功能
((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "新增"; strFrmStatus = "ADD"; break; case "MODIFY": UnLockFormHead(); UnLockFormDetail(); UnLockFormSubDetail(); tsbSearch.Enabled = false; tsbEdit.Visible = false; tsbDelete.Enabled = false; tsbSave.Visible = true; tsbCancel.Visible = true; dgvOrderContent.AllowUserToAddRows = true; dgvOutSourcingContent.AllowUserToAddRows = true; dgvReceiptPlan.AllowUserToAddRows = true; ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "修改"; strFrmStatus = "MODIFY"; break; case "DEL": ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "刪除"; strFrmStatus = "DEL"; break; } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void CleanForm() //清除畫面
{ blIsAdded = true; CleanFormHead(); CleanFormDetail(); CleanFormSubDetail(); }
private void CleanFormHead() //清除畫面
{ //設定畫面物件狀態
//清除GridView
txtSalesOrderNo.Text = ""; txtCustomerID.Text = ""; txtCustomerName.Text = ""; txtOrderSum.Text = ""; txtOutSourcingSum.Text = ""; rbPayType.Checked = false; rbPayType1.Checked = false; rbPayType2.Checked = false; rbPayType3.Checked = false; txtProjectName.Text = ""; txtProjectNumber.Text = ""; rbOrderStatusClose.Checked = false; rbOrderStatusOpen.Checked = false; }
private void CleanFormDetail() //清除畫面
{ //設定畫面物件狀態
try { if (dgvOrderContent.CurrentCell != null) { if (!dgvOrderContent.CurrentCell.IsInEditMode) { dgvOrderContent.Rows.Clear(); } } dgvOutSourcingContent.Rows.Clear(); } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void CleanFormSubDetail() //清除畫面
{ try { //設定畫面物件狀態
if (dgvReceiptPlan.Rows.Count > 0) dgvReceiptPlan.Rows.Clear(); if (dgvToPayPlan.Rows.Count > 0) dgvToPayPlan.Rows.Clear(); } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void CleanToolbar() //清除工具列
{ //設定Toolbar狀態
tsbSearch.Visible = true; tsbSearch.Enabled = true; tsbAdd.Visible = false; //本程式不存在新功能
tsbEdit.Visible = true; tsbEdit.Enabled = true; tsbDelete.Visible = true; tsbDelete.Enabled = true; tsbSave.Visible = false; tsbOK.Visible = false; tsbCancel.Visible = false; }
private void UnLockFormHead() //解除限制唯讀物件
{ txtSalesOrderNo.ReadOnly = false; txtCustomerName.ReadOnly = false; rbPayType.Enabled = true; rbPayType1.Enabled = true; rbPayType2.Enabled = true; rbPayType3.Enabled = true; rbOrderStatusClose.Enabled = true; rbOrderStatusOpen.Enabled = true; txtProjectName.ReadOnly = false; btnGetSalesOrderNo.Enabled = true; btnGetCustomer.Enabled = true; }
private void UnLockFormDetail() //解除限制唯讀物件
{ dgvOrderContent.ReadOnly = false; dgvOutSourcingContent.ReadOnly = false; }
private void UnLockFormSubDetail() //解除限制唯讀物件
{ try { if (dgvOrderContent.Rows.Count > 0) { btnArrangeProject.Enabled = true; dgvReceiptPlan.ReadOnly = false; }
if (dgvOutSourcingContent.Rows.Count > 0) { btnArrangToPayProject.Enabled = true; dgvToPayPlan.ReadOnly = false; } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void LockForm() //限制唯讀物件
{ txtSalesOrderNo.ReadOnly = true; txtCustomerName.ReadOnly = true; txtProjectName.ReadOnly = true; rbPayType.Enabled = false; rbPayType1.Enabled = false; rbPayType2.Enabled = false; rbPayType3.Enabled = false; dgvOrderContent.ReadOnly = true; dgvOutSourcingContent.ReadOnly = true; dgvReceiptPlan.ReadOnly = true; dgvToPayPlan.ReadOnly = true; rbOrderStatusOpen.Enabled = false; rbOrderStatusClose.Enabled = false; btnGetSalesOrderNo.Enabled = false; btnGetCustomer.Enabled = false; btnArrangeProject.Enabled = false; btnArrangToPayProject.Enabled = false; }
private bool CheckForm() //檢查表單填寫狀況
{ try { //訂單表頭確認
if (txtSalesOrderNo.Text.Trim() == "") { MessageBox.Show("請輸入訂單編號", "提示"); txtSalesOrderNo.Focus(); return false; }
if (txtCustomerID.Text.Trim() == "") { MessageBox.Show("請輸入正確客戶名稱", "提示"); txtCustomerID.Focus(); return false; }
if (rbPayType.Checked == false && rbPayType1.Checked == false && rbPayType2.Checked == false && rbPayType3.Checked == false) { MessageBox.Show("請選擇請款方式", "提示"); rbPayType.Focus(); return false; }
//訂單內容與請款計劃確認
if (dgvReceiptPlan.Rows.Count > 0 && dgvReceiptPlan.ReadOnly == false) { if (!dgvReceiptPlan.Rows[0].IsNewRow) { //物件宣告
DataTable dtTemp = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; double dbOrderAmount = 0; double dbReceiptAmount = 0; string strOrderContent = ""; string strReceiptItem = ""; DataGridViewComboBoxCell cbCell = new DataGridViewComboBoxCell();
foreach (DataRow drTemp in dtTemp.Rows) //取得訂單內容的金額總數
{ foreach (DataGridViewRow drOrderItem in dgvOrderContent.Rows) { cbCell = (DataGridViewComboBoxCell)drOrderItem.Cells["cOrderContent"]; strOrderContent = (string)cbCell.Value;
if (drTemp["ArgumentID"].ToString() == (string.IsNullOrEmpty(strOrderContent) ? "" : strOrderContent)) { dbOrderAmount += Convert.ToDouble(drOrderItem.Cells["cAmount"].Value.ToString().Replace(",", "")); } }
foreach (DataGridViewRow drReceiptItem in dgvReceiptPlan.Rows) //取得請款計劃的金額總數
{ cbCell = (DataGridViewComboBoxCell)drReceiptItem.Cells["cReceiptItem"]; strReceiptItem = (string)cbCell.Value;
if (drTemp["ArgumentID"].ToString() == (string.IsNullOrEmpty(strReceiptItem) ? "" : strReceiptItem)) { dbReceiptAmount += Convert.ToDouble(drReceiptItem.Cells["cReceiptAmount"].Value.ToString().Replace(",", "")); } }
if (dbOrderAmount != dbReceiptAmount) { MessageBox.Show("請款計劃" + drTemp["ArgumentValue"].ToString() + "累計金額有誤!", "提示"); return false; } } } }
//委外內容與付款計劃確認
if (dgvToPayPlan.Rows.Count > 0 && dgvToPayPlan.ReadOnly == false) { if (!dgvToPayPlan.Rows[0].IsNewRow) { //物件宣告
DataTable dtTemp = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; double dbOutSourceAmount = 0; double dbPayAmount = 0; string strOrderContent = ""; string strPayItem = ""; DataGridViewComboBoxCell cbCell = new DataGridViewComboBoxCell();
foreach (DataRow drTemp in dtTemp.Rows) //取得訂單內容的金額總數
{ foreach (DataGridViewRow drPayItem in dgvOutSourcingContent.Rows) { cbCell = (DataGridViewComboBoxCell)drPayItem.Cells["cOutOrderContent"]; strOrderContent = (string)cbCell.Value;
if (drTemp["ArgumentID"].ToString() == (string.IsNullOrEmpty(strOrderContent) ? "" : strOrderContent)) { dbOutSourceAmount += Convert.ToDouble(drPayItem.Cells["cOutAmount"].Value.ToString().Replace(",", "")); } }
foreach (DataGridViewRow drPayItem in dgvToPayPlan.Rows) //取得請款計劃的金額總數
{ cbCell = (DataGridViewComboBoxCell)drPayItem.Cells["cPayItem"]; strPayItem = (string)cbCell.Value;
if (drTemp["ArgumentID"].ToString() == (string.IsNullOrEmpty(strPayItem) ? "" : strPayItem)) { dbPayAmount += Convert.ToDouble(drPayItem.Cells["cPayAmount"].Value.ToString().Replace(",", "")); } }
if (dbOutSourceAmount != dbPayAmount) { MessageBox.Show("付款計劃" + drTemp["ArgumentValue"].ToString() + "累計金額有誤!", "提示"); return false; } } } } return true; } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); return false; } }
private void GetOrderList() //取得專案列表
{ try { StringBuilder strSQL = new StringBuilder(); strSQL.Append("Select * From OVW_SAL_ProjectOrderList Where ISNULL(CustomerName,'') <> '' And AccountingBookID = '" + strAccountingBookID + "' "); if (rbOrderStatusClose.Checked == true) { strSQL.Append("Union "); strSQL.Append("Select * From OVW_SAL_ProjectOrderList_Closed Where ISNULL(CustomerName,'') <> '' And AccountingBookID = '" + strAccountingBookID + "' "); } strSQL.Append("Order BY CustomerName"); dgvOrderList.DataSource = UtilityClass.GetSQLResult(strSQL.ToString()).Tables["Result"]; } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
public void GoEvent() //執行事件
{ try { //物件宣告
StringBuilder sbSQL = new StringBuilder(); string strSalesOrderNo = ""; //訂單編號
string strOrderItem = ""; //訂單項目
string strOrderContent = ""; //採購項目
string strUnitPrice = ""; //單價
string strQuantity = ""; //數量
string strTax = ""; //稅額
string strMemo = ""; //訂單內容註解
string strOutOrderItem = ""; //委外項目
string strOutOrderContent = ""; //委外項目
string strOutUnitPrice = ""; //委外單價
string strOutQuantity = ""; //委外數量
string strOutMemo = ""; //委外內容註解
string strReceiptNo = ""; //請款單號
string strItemNo = ""; //項次
string strPhase = ""; //期數
string strReceiptItem = ""; //請款項目
string strReceiptUnitPrice = ""; //請款單價
string strReceiptQuantity = ""; //請款數量
string strRestReceipt = ""; //待請數量
string strExpectedReceiptDate = ""; //預計請款日期
string strActualReceiptDate = ""; //實際請款日期
string strExpectedReceiptedDate = ""; //預計收款日期
string strActualReceiptedDate = ""; //實際收款日期
string strReceiptAmount = ""; //請款金額
string strRestReceiptAmount = ""; //待請餘額
string strInvoiceNo = ""; //付款單號
string strPayItemNo = ""; //項次
string strPayPhase = ""; //期數
string strPayItem = ""; //付款項目
string strPayUnitPrice = ""; //付款單價
string strPayQuantity = ""; //付款數量
string strRestPayQuantity = ""; //待付餘量
string strExpectedPayDate = ""; //預計付款日期
string strActualPayDate = ""; //實際請付日期
string strPayAmount = ""; //付款止額
string strRestPayAmount = ""; //待付餘額
string strPayMemo = ""; //備註
switch (strFrmStatus) { case "SEARCH": sbSQL.Append("Select * From OVW_SAL_ProjectOrderList "); sbSQL.Append(" Where ISNULL(CustomerName,'') <> '' "); if (txtSalesOrderNo.Text.Trim() != "") { sbSQL.Append("AND SalesOrderNo like '" + txtSalesOrderNo.Text.Trim() + "' "); } if (txtCustomerName.Text.Trim() != "") { sbSQL.Append("AND CustomerName like '" + txtCustomerName.Text.Trim() + "' "); } if (txtProjectName.Text.Trim() != "") { sbSQL.Append("AND ProjectCName like '" + txtProjectName.Text.Trim() + "' "); }
if (rbOrderStatusClose.Checked == true) { sbSQL.Append("Union "); sbSQL.Append("Select * From OVW_SAL_ProjectOrderList_Closed "); sbSQL.Append(" Where ISNULL(CustomerName,'') <> '' ");
if (txtSalesOrderNo.Text.Trim() != "") { sbSQL.Append("AND SalesOrderNo like '" + txtSalesOrderNo.Text.Trim() + "' "); } if (txtCustomerName.Text.Trim() != "") { sbSQL.Append("AND CustomerName like '" + txtCustomerName.Text.Trim() + "' "); } if (txtProjectName.Text.Trim() != "") { sbSQL.Append("AND ProjectCName like '" + txtProjectName.Text.Trim() + "' "); } }
sbSQL.Append("Order BY CustomerName"); DataTable dtTemp = UtilityClass.GetSQLResult(sbSQL.ToString()).Tables["Result"]; dgvOrderList.DataSource = dtTemp; StatusChange("NONE"); break;
case "MODIFY": if (CheckForm() == true) { if (blIsAdded == false) { MessageBox.Show("您未完成分錄建立,請先完成分錄建立,再行儲存", "提示"); return; }
if (rbOrderStatusClose.Checked == true) { //處理合約結案相關事宜
} //參數設定
strSalesOrderNo = txtSalesOrderNo.Text.Trim(); //訂單編號
string strPayType = ""; //設定請款方式
if (rbPayType.Checked) strPayType = "P"; if (rbPayType1.Checked) strPayType = "M"; if (rbPayType2.Checked) strPayType = "D"; if (rbPayType3.Checked) strPayType = "H"; string strOrderStatus = ""; //設定訂單狀態
if (rbOrderStatusClose.Checked) strOrderStatus = "C"; if (rbOrderStatusOpen.Checked) strOrderStatus = "O";
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); } string strCHKSQL = string.Format("Select * From OTB_SAL_OrderList Where SalesOrderNo = '{0}' And AccountingBookID = '{1}'", strSalesOrderNo, strAccountingBookID); sqlTran = sqlConn.BeginTransaction();
if (UtilityClass.IsExist(strCHKSQL)) { //資料存在,採用UPdate,基本資料不允許修改
//清除訂單及委外內容
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { sbSQL.Clear(); sbSQL.Append("Delete OTB_SAL_OrderContent Where SalesOrderNo = @SalesOrderNo "); sbSQL.Append("Delete OTB_SAL_OutSourcingContent Where SalesOrderNo = @SalesOrderNo "); sbSQL.Append("Delete OTB_SAL_ReceiptPlan Where SalesOrderNo = @SalesOrderNo "); sbSQL.Append("Delete OTB_SAL_PayPlan Where SalesOrderNo = @SalesOrderNo ");
//添加參數
sqlAdapter.DeleteCommand = new SqlCommand(); sqlAdapter.DeleteCommand.Connection = sqlConn; sqlAdapter.DeleteCommand.Transaction = sqlTran; sqlAdapter.DeleteCommand.CommandText = sbSQL.ToString(); sqlAdapter.DeleteCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@SalesOrderNo",string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo) } ); if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.DeleteCommand.ExecuteNonQuery(); }
//寫入訂單內容
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { sbSQL.Clear(); sbSQL.Append("Insert Into OTB_SAL_OrderContent (SalesOrderNo, ItemNo, OrderContent, UnitPrice, Quantity, Tax, Memo, CreateDate, CreateUser, ModifyDate, ModifyUser) Values"); sbSQL.Append("(@SalesOrderNo, @ItemNo, @OrderContent, @UnitPrice, @Quantity, @Tax, @Memo, GetDate(), @CreateUser, GetDate(), @ModifyUser)");
foreach (DataGridViewRow drContent in dgvOrderContent.Rows) { strOrderContent = (string)drContent.Cells["cOrderContent"].Value; strOrderItem = (string)drContent.Cells["cOrderItem"].Value; strUnitPrice = (string)drContent.Cells["cUnitPrice"].Value; strQuantity = (string)drContent.Cells["cQuantity"].Value; strTax = (string)drContent.Cells["cTax"].Value; strMemo = (string)drContent.Cells["cOrderMemo"].Value; if (!drContent.IsNewRow) { //添加參數
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = sbSQL.ToString(); sqlAdapter.InsertCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@SalesOrderNo",string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo), new SqlParameter("@ItemNo",string.IsNullOrEmpty(strOrderItem) ? "" : strOrderItem), new SqlParameter("@OrderContent",string.IsNullOrEmpty(strOrderContent) ? "" : strOrderContent), new SqlParameter("@UnitPrice",string.IsNullOrEmpty(strUnitPrice) ? "" : UtilityClass.EncryptDES(strUnitPrice,strKey)), new SqlParameter("@Quantity",string.IsNullOrEmpty(strQuantity) ? "" : UtilityClass.EncryptDES(strQuantity,strKey)), new SqlParameter("@Tax",string.IsNullOrEmpty(strTax) ? "" : UtilityClass.EncryptDES(strTax,strKey)), new SqlParameter("@Memo",string.IsNullOrEmpty(strMemo) ? "" : strMemo), new SqlParameter("@CreateUser",strActiveUserID), new SqlParameter("@ModifyUser",strActiveUserID) } );
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.InsertCommand.ExecuteNonQuery(); } } }
//寫入委外內容
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { sbSQL.Clear(); sbSQL.Append("Insert Into OTB_SAL_OutSourcingContent (SalesOrderNo, ItemNo, OrderContent, UnitPrice, Quantity, Memo, CreateDate, CreateUser, ModifyDate, ModifyUser) Values"); sbSQL.Append("(@SalesOrderNo, @ItemNo, @OrderContent, @UnitPrice, @Quantity, @Memo, GetDate(), @CreateUser, GetDate(), @ModifyUser)");
foreach (DataGridViewRow drContent in dgvOutSourcingContent.Rows) { strOutOrderContent = (string)drContent.Cells["cOutOrderContent"].Value; strOutOrderItem = (string)drContent.Cells["cOutOrderItem"].Value; strOutUnitPrice = (string)drContent.Cells["cOutUnitPrice"].Value; strOutQuantity = (string)drContent.Cells["cOutQuantity"].Value; strOutMemo = (string)drContent.Cells["cOutOrderMemo"].Value; if (!drContent.IsNewRow) { //添加參數
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = sbSQL.ToString(); sqlAdapter.InsertCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@SalesOrderNo",string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo), new SqlParameter("@ItemNo",string.IsNullOrEmpty(strOutOrderItem) ? "" : strOutOrderItem), new SqlParameter("@OrderContent",string.IsNullOrEmpty(strOutOrderContent) ? "" : strOutOrderContent), new SqlParameter("@UnitPrice",string.IsNullOrEmpty(strOutUnitPrice) ? "" : UtilityClass.EncryptDES(strOutUnitPrice,strKey)), new SqlParameter("@Quantity",string.IsNullOrEmpty(strOutQuantity) ? "" : UtilityClass.EncryptDES(strOutQuantity,strKey)), new SqlParameter("@Memo",string.IsNullOrEmpty(strOutMemo) ? "" : strOutMemo), new SqlParameter("@CreateUser",strActiveUserID), new SqlParameter("@ModifyUser",strActiveUserID) } );
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.InsertCommand.ExecuteNonQuery(); } } }
//寫入請款計劃
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { foreach (DataGridViewRow drContent in dgvReceiptPlan.Rows) { if (!drContent.IsNewRow) { strReceiptNo = (string)drContent.Cells["cReceiptNo"].Value; //請款單號
strItemNo = (string)drContent.Cells["cItemNo"].Value; //項次
strPhase = drContent.Cells["cPhase"].Value.ToString(); //期數
strReceiptItem = (string)drContent.Cells["cReceiptItem"].Value; //請款項目
strReceiptUnitPrice = (string)drContent.Cells["cReceiptUnitPrice"].Value; //請款單價
strReceiptQuantity = (string)drContent.Cells["cReceiptQuantity"].Value; //請款數量
strRestReceipt = (string)drContent.Cells["cRestReceipt"].Value; //待請數量
strExpectedReceiptDate = (string)drContent.Cells["cExpectedReceiptDate"].Value; //預計請款日期
strActualReceiptDate = (string)drContent.Cells["cActualReceiptDate"].Value; //實際請款日期
strExpectedReceiptedDate = (string)drContent.Cells["cExpectedReceiptedDate"].Value; //預計收款日期
strActualReceiptedDate = (string)drContent.Cells["cActualReceiptedDate"].Value; //實際收款日期
strReceiptAmount = (string)drContent.Cells["cReceiptAmount"].Value; strTax = (string)drContent.Cells["cReceiptTax"].Value; //稅額
strRestReceiptAmount = (string)drContent.Cells["cRestReceiptAmount"].Value; //待請餘額
strMemo = (string)drContent.Cells["cMemo"].Value; //備註
sbSQL.Clear(); sbSQL.Append("Insert Into OTB_SAL_ReceiptPlan (AccountingBookID, SalesOrderNo, ReceiptNo, ItemNo, Phase, ReceiptItem, ReceiptUnitPrice, ReceiptQuantity, RestReceipt, ExpectedReceiptDate, ActualReceiptDate, ExpectedReceiptedDate, ActualReceiptedDate, ReceiptAmount, Tax, RestReceiptAmount, Memo , CreateDate, CreateUser, ModifyDate, ModifyUser) Values("); sbSQL.Append("'" + (string.IsNullOrEmpty(strAccountingBookID) ? "" : strAccountingBookID) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptNo) ? "" : strReceiptNo) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strItemNo) ? "" : strItemNo) + "', "); sbSQL.Append((string.IsNullOrEmpty(strPhase) ? "" : strPhase) + ", "); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptItem) ? "" : strReceiptItem) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptUnitPrice) ? "" : UtilityClass.EncryptDES(strReceiptUnitPrice, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptQuantity) ? "" : UtilityClass.EncryptDES(strReceiptQuantity, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strRestReceipt) ? "" : UtilityClass.EncryptDES(strRestReceipt, strKey)) + "', "); sbSQL.Append(!UtilityClass.IsDate(strExpectedReceiptDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strExpectedReceiptDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append(!UtilityClass.IsDate(strActualReceiptDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strActualReceiptDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append(!UtilityClass.IsDate(strExpectedReceiptedDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strExpectedReceiptedDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append(!UtilityClass.IsDate(strActualReceiptedDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strActualReceiptedDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptAmount) ? "" : UtilityClass.EncryptDES(strReceiptAmount, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strTax) ? "" : UtilityClass.EncryptDES(strTax, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strRestReceiptAmount) ? "" : UtilityClass.EncryptDES(strRestReceiptAmount, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strMemo) ? "" : strMemo) + "', "); sbSQL.Append("GetDate(), '" + strActiveUserID + "', GetDate(), '" + strActiveUserID + "')");
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = sbSQL.ToString();
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.InsertCommand.ExecuteNonQuery();
} } }
//寫入付款計劃
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { foreach (DataGridViewRow drContent in dgvToPayPlan.Rows) { if (!drContent.IsNewRow) { strInvoiceNo = (string)drContent.Cells["cInvoiceNo"].Value; //付款單號
strPayItemNo = (string)drContent.Cells["cPayItemNo"].Value; //項次
strPayPhase = drContent.Cells["cPayPhase"].Value.ToString(); //期數
strPayItem = (string)drContent.Cells["cPayItem"].Value; //付款項目
strPayUnitPrice = (string)drContent.Cells["cPayUnitPrice"].Value; //付款單價
strPayQuantity = (string)drContent.Cells["cPayQuantity"].Value; //付款數量
strRestPayQuantity = (string)drContent.Cells["cRestPayQuantity"].Value; //待付數量
strExpectedPayDate = (string)drContent.Cells["cExpectedPayDate"].Value; //預計付款日期
strActualPayDate = (string)drContent.Cells["cActualPaiedDate"].Value; //實際付款日期
strPayAmount = (string)drContent.Cells["cPayAmount"].Value; //付款金額
strRestPayAmount = (string)drContent.Cells["cRestPayAmount"].Value; //待付餘額
strPayMemo = (string)drContent.Cells["cPayMemo"].Value; //備註
sbSQL.Clear(); sbSQL.Append("Insert Into OTB_SAL_PayPlan (AccountingBookID, SalesOrderNo, ItemNo, PhaseNo, InvoiceNo, PayItem, PayUnitPrice, PayQuantity, RestPay, ExpectedPayDate, ActualPayDate, PayAmount,RestPayAmount ,Memo ,CreateDate, CreateUser, ModifyDate, ModifyUser) Values("); sbSQL.Append("'" + (string.IsNullOrEmpty(strAccountingBookID) ? "" : strAccountingBookID) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayItemNo) ? "" : strPayItemNo) + "', "); sbSQL.Append((string.IsNullOrEmpty(strPayPhase) ? "" : strPayPhase) + ", "); sbSQL.Append("'" + (string.IsNullOrEmpty(strInvoiceNo) ? "" : strInvoiceNo) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayItem) ? "" : strPayItem) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayUnitPrice) ? "" : UtilityClass.EncryptDES(strPayUnitPrice, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayQuantity) ? "" : UtilityClass.EncryptDES(strPayQuantity, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strRestPayQuantity) ? "" : UtilityClass.EncryptDES(strRestPayQuantity, strKey)) + "', "); sbSQL.Append(!UtilityClass.IsDate(strExpectedPayDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strExpectedPayDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append(!UtilityClass.IsDate(strActualPayDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strActualPayDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayAmount) ? "" : UtilityClass.EncryptDES(strPayAmount, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strRestPayAmount) ? "" : UtilityClass.EncryptDES(strRestPayAmount, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayMemo) ? "" : strPayMemo) + "', "); sbSQL.Append("GetDate(), '" + strActiveUserID + "', GetDate(), '" + strActiveUserID + "')");
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = sbSQL.ToString();
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.InsertCommand.ExecuteNonQuery();
} } }
sqlTran.Commit(); //資料完成寫入資料庫中
dgvOrderList.ReadOnly = true; StatusChange("SEARCH"); GoEvent(); //定位在已存檔的位置
string strColumnValue = ""; foreach (DataGridViewRow dr in dgvOrderList.Rows) { strColumnValue = (string)dr.Cells["cOrderID"].Value; if (!string.IsNullOrEmpty(strColumnValue) && strColumnValue == strSalesOrderNo) { dgvOrderList.CurrentCell = dgvOrderList.Rows[dr.Index].Cells["cCustomerName"]; } } MessageBox.Show("儲存成功", "提示"); } else { # region 基本資料不存在,採用Insert
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { sbSQL.Clear(); sbSQL.Append("Insert Into OTB_SAL_OrderList (AccountingBookID, SalesOrderNo, CustomerID, ProjectNumber, PayType, OrderStatus, CreateDate, CreateUser, ModifyDate, ModifyUser) Values"); sbSQL.Append("(@AccountingBookID, @SalesOrderNo, @CustomerID, @ProjectNumber, @PayType, @OrderSatus, GetDate(), @CreateUser, GetDate(), @ModifyUser)");
//添加參數
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = sbSQL.ToString(); sqlAdapter.InsertCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@AccountingBookID",strAccountingBookID), new SqlParameter("@SalesOrderNo",txtSalesOrderNo.Text.Trim()), new SqlParameter("@CustomerID",txtCustomerID.Text.Trim()), new SqlParameter("@ProjectNumber",txtProjectNumber.Text.Trim()), new SqlParameter("@PayType",strPayType), new SqlParameter("@OrderSatus",strOrderStatus), new SqlParameter("@CreateUser",strActiveUserID), new SqlParameter("@ModifyUser",strActiveUserID) } );
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); } sqlAdapter.InsertCommand.ExecuteNonQuery(); }
//清除訂單與委外內容
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { sbSQL.Clear(); sbSQL.Append("Delete OTB_SAL_OrderContent Where SalesOrderNo = @SalesOrderNo "); sbSQL.Append("Delete OTB_SAL_OutSourcingContent Where SalesOrderNo = @SalesOrderNo "); sbSQL.Append("Delete OTB_SAL_ReceiptPlan Where SalesOrderNo = @SalesOrderNo "); sbSQL.Append("Delete OTB_SAL_PayPlan Where SalesOrderNo = @SalesOrderNo ");
//添加參數
sqlAdapter.DeleteCommand = new SqlCommand(); sqlAdapter.DeleteCommand.Connection = sqlConn; sqlAdapter.DeleteCommand.Transaction = sqlTran; sqlAdapter.DeleteCommand.CommandText = sbSQL.ToString(); sqlAdapter.DeleteCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@SalesOrderNo",string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo) } ); if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.DeleteCommand.ExecuteNonQuery(); }
//寫入訂單內容
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { sbSQL.Clear(); sbSQL.Append("Insert Into OTB_SAL_OrderContent (SalesOrderNo, ItemNo, OrderContent, UnitPrice, Quantity, Tax, Memo, CreateDate, CreateUser, ModifyDate, ModifyUser) Values"); sbSQL.Append("(@SalesOrderNo, @ItemNo, @OrderContent, @UnitPrice, @Quantity, @Tax, @Memo, GetDate(), @CreateUser, GetDate(), @ModifyUser)"); foreach (DataGridViewRow drContent in dgvOrderContent.Rows) { //檢查參數
strOrderContent = (string)drContent.Cells["cOrderContent"].Value; strOrderItem = (string)drContent.Cells["cOrderItem"].Value; strUnitPrice = (string)drContent.Cells["cUnitPrice"].Value; strQuantity = (string)drContent.Cells["cQuantity"].Value; strTax = (string)drContent.Cells["cTax"].Value; strMemo = (string)drContent.Cells["cOrderMemo"].Value; if (!drContent.IsNewRow) { ////添加參數
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = sbSQL.ToString(); sqlAdapter.InsertCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@SalesOrderNo",string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo), new SqlParameter("@ItemNo",string.IsNullOrEmpty(strOrderItem) ? "" : strOrderItem), new SqlParameter("@OrderContent",string.IsNullOrEmpty(strOrderContent) ? "" : strOrderContent), new SqlParameter("@UnitPrice",string.IsNullOrEmpty(strUnitPrice) ? "" : UtilityClass.EncryptDES(strUnitPrice,strKey)), new SqlParameter("@Quantity",string.IsNullOrEmpty(strQuantity) ? "" : UtilityClass.EncryptDES(strQuantity,strKey)), new SqlParameter("@Tax",string.IsNullOrEmpty(strTax) ? "" : UtilityClass.EncryptDES(strTax,strKey)), new SqlParameter("@Memo",string.IsNullOrEmpty(strMemo) ? "" : strMemo), new SqlParameter("@CreateUser",strActiveUserID), new SqlParameter("@ModifyUser",strActiveUserID) } );
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.InsertCommand.ExecuteNonQuery(); } } }
//寫入委外內容
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { sbSQL.Clear(); sbSQL.Append("Insert Into OTB_SAL_OutSourcingContent (SalesOrderNo, ItemNo, OrderContent, UnitPrice, Quantity, Memo, CreateDate, CreateUser, ModifyDate, ModifyUser) Values"); sbSQL.Append("(@SalesOrderNo, @ItemNo, @OrderContent, @UnitPrice, @Quantity, @Memo, GetDate(), @CreateUser, GetDate(), @ModifyUser)");
foreach (DataGridViewRow drContent in dgvOutSourcingContent.Rows) { //檢查參數
strOutOrderContent = (string)drContent.Cells["cOutOrderContent"].Value; strOutOrderItem = (string)drContent.Cells["cOutOrderItem"].Value; strOutUnitPrice = (string)drContent.Cells["cOutUnitPrice"].Value; strOutQuantity = (string)drContent.Cells["cOutQuantity"].Value; strOutMemo = (string)drContent.Cells["cOutOrderMemo"].Value; if (!drContent.IsNewRow) { ////添加參數
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = sbSQL.ToString(); sqlAdapter.InsertCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@SalesOrderNo",string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo), new SqlParameter("@ItemNo",string.IsNullOrEmpty(strOutOrderItem) ? "" : strOutOrderItem), new SqlParameter("@OrderContent",string.IsNullOrEmpty(strOutOrderContent) ? "" : strOutOrderContent), new SqlParameter("@UnitPrice",string.IsNullOrEmpty(strOutUnitPrice) ? "" : UtilityClass.EncryptDES(strOutUnitPrice,strKey)), new SqlParameter("@Quantity",string.IsNullOrEmpty(strOutQuantity) ? "" : UtilityClass.EncryptDES(strOutQuantity,strKey)), new SqlParameter("@Memo",string.IsNullOrEmpty(strOutMemo) ? "" : strOutMemo), new SqlParameter("@CreateUser",strActiveUserID), new SqlParameter("@ModifyUser",strActiveUserID) } );
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.InsertCommand.ExecuteNonQuery(); } } }
//寫入請款計劃
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { foreach (DataGridViewRow drContent in dgvReceiptPlan.Rows) { if (!drContent.IsNewRow) { strReceiptNo = (string)drContent.Cells["cReceiptNo"].Value; //請款單號
strItemNo = (string)drContent.Cells["cItemNo"].Value; //項次
strPhase = drContent.Cells["cPhase"].Value.ToString(); //期數
strReceiptItem = (string)drContent.Cells["cReceiptItem"].Value; //請款項目
strReceiptUnitPrice = (string)drContent.Cells["cReceiptUnitPrice"].Value; //請款單價
strReceiptQuantity = (string)drContent.Cells["cReceiptQuantity"].Value; //請款數量
strRestReceipt = (string)drContent.Cells["cRestReceipt"].Value; //待請數量
strExpectedReceiptDate = (string)drContent.Cells["cExpectedReceiptDate"].Value; //預計請款日期
strActualReceiptDate = (string)drContent.Cells["cActualReceiptDate"].Value; //實際請款日期
strExpectedReceiptedDate = (string)drContent.Cells["cExpectedReceiptedDate"].Value; //預計收款日期
strActualReceiptedDate = (string)drContent.Cells["cActualReceiptedDate"].Value; //實際收款日期
strReceiptAmount = (string)drContent.Cells["cReceiptAmount"].Value; //請款金額
strTax = (string)drContent.Cells["cReceiptTax"].Value; //請款金額
strRestReceiptAmount = (string)drContent.Cells["cRestReceiptAmount"].Value; //待請餘額
strMemo = (string)drContent.Cells["cMemo"].Value; //備註
sbSQL.Clear(); sbSQL.Append("Insert Into OTB_SAL_ReceiptPlan (AccountingBookID, SalesOrderNo, ReceiptNo, ItemNo, Phase, ReceiptItem, ReceiptUnitPrice, ReceiptQuantity, RestReceipt, ExpectedReceiptDate, ActualReceiptDate, ExpectedReceiptedDate, ActualReceiptedDate, ReceiptAmount, Tax, RestReceiptAmount, Memo , CreateDate, CreateUser, ModifyDate, ModifyUser) Values("); sbSQL.Append("'" + (string.IsNullOrEmpty(strAccountingBookID) ? "" : strAccountingBookID) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptNo) ? "" : strReceiptNo) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strItemNo) ? "" : strItemNo) + "', "); sbSQL.Append((string.IsNullOrEmpty(strPhase) ? "" : strPhase) + ", "); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptItem) ? "" : strReceiptItem) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptUnitPrice) ? "" : UtilityClass.EncryptDES(strReceiptUnitPrice, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptQuantity) ? "" : UtilityClass.EncryptDES(strReceiptQuantity, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strRestReceipt) ? "" : UtilityClass.EncryptDES(strRestReceipt, strKey)) + "', "); sbSQL.Append(!UtilityClass.IsDate(strExpectedReceiptDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strExpectedReceiptDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append(!UtilityClass.IsDate(strActualReceiptDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strActualReceiptDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append(!UtilityClass.IsDate(strExpectedReceiptedDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strExpectedReceiptedDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append(!UtilityClass.IsDate(strActualReceiptedDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strActualReceiptedDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append("'" + (string.IsNullOrEmpty(strReceiptAmount) ? "" : UtilityClass.EncryptDES(strReceiptAmount, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strTax) ? "" : UtilityClass.EncryptDES(strTax, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strRestReceiptAmount) ? "" : UtilityClass.EncryptDES(strRestReceiptAmount, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strMemo) ? "" : strMemo) + "', "); sbSQL.Append("GetDate(), '" + strActiveUserID + "', GetDate(), '" + strActiveUserID + "')");
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = sbSQL.ToString();
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.InsertCommand.ExecuteNonQuery();
} } }
//寫入付款計劃
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { foreach (DataGridViewRow drContent in dgvToPayPlan.Rows) { if (!drContent.IsNewRow) { strInvoiceNo = (string)drContent.Cells["cInvoiceNo"].Value; //付款單號
strPayItemNo = (string)drContent.Cells["cPayItemNo"].Value; //項次
strPayPhase = drContent.Cells["cPayPhase"].Value.ToString(); //期數
strPayItem = (string)drContent.Cells["cPayItem"].Value; //付款項目
strPayUnitPrice = (string)drContent.Cells["cPayUnitPrice"].Value; //付款單價
strPayQuantity = (string)drContent.Cells["cPayQuantity"].Value; //付款數量
strRestPayQuantity = (string)drContent.Cells["cRestPayQuantity"].Value; //待付數量
strExpectedPayDate = (string)drContent.Cells["cExpectedPayDate"].Value; //預計付款日期
strActualPayDate = (string)drContent.Cells["cActualPaiedDate"].Value; //實際請付日期
strPayAmount = (string)drContent.Cells["cPayAmount"].Value; //付款金額
strRestPayAmount = (string)drContent.Cells["cRestPayAmount"].Value; //待付餘額
strPayMemo = (string)drContent.Cells["cPayMemo"].Value; //備註
sbSQL.Clear(); sbSQL.Append("Insert Into OTB_SAL_PayPlan (AccountingBookID, SalesOrderNo, ItemNo, PhaseNo, InvoiceNo, PayItem, PayUnitPrice, PayQuantity, RestPay, ExpectedPayDate, ActualPayDate, PayAmount,RestPayAmount ,Memo ,CreateDate, CreateUser, ModifyDate, ModifyUser) Values("); sbSQL.Append("'" + (string.IsNullOrEmpty(strAccountingBookID) ? "" : strAccountingBookID) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayItemNo) ? "" : strPayItemNo) + "', "); sbSQL.Append((string.IsNullOrEmpty(strPayPhase) ? "" : strPayPhase) + ", "); sbSQL.Append("'" + (string.IsNullOrEmpty(strInvoiceNo) ? "" : strInvoiceNo) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayItem) ? "" : strPayItem) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayUnitPrice) ? "" : UtilityClass.EncryptDES(strPayUnitPrice, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayQuantity) ? "" : UtilityClass.EncryptDES(strPayQuantity, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strRestPayQuantity) ? "" : UtilityClass.EncryptDES(strRestPayQuantity, strKey)) + "', "); sbSQL.Append(!UtilityClass.IsDate(strExpectedPayDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strExpectedPayDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append(!UtilityClass.IsDate(strActualPayDate) ? "null," : ("Convert(DateTime,'" + Convert.ToDateTime(strActualPayDate + " 00:00:00").ToString("yyyy/MM/dd HH:mm:ss") + "'), ")); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayAmount) ? "" : UtilityClass.EncryptDES(strPayAmount, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strRestPayAmount) ? "" : UtilityClass.EncryptDES(strRestPayAmount, strKey)) + "', "); sbSQL.Append("'" + (string.IsNullOrEmpty(strPayMemo) ? "" : strPayMemo) + "', "); sbSQL.Append("GetDate(), '" + strActiveUserID + "', GetDate(), '" + strActiveUserID + "')");
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = sbSQL.ToString();
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.InsertCommand.ExecuteNonQuery();
} } }
sqlTran.Commit(); //資料完成寫入資料庫中
dgvOrderList.ReadOnly = true; MessageBox.Show("儲存成功","提示"); StatusChange("SEARCH"); GoEvent(); #endregion
} } break; } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); sqlTran.Rollback(); } }
private void ReArrangeReceipt(DataGridViewCellEventArgs e) //重新整理請款計劃
{ try { //物件宣告
string strItemNo = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells[2].Value; //項次
string strRestReceipt = ""; //請款數量
string strReceiptClass = ""; //請款計算方式 (P:百分比、D:三位一撇)
double dbSumRestReceipt = 0; //請款總量
string strRestReceiptAmount = ""; //待請餘額
double dbSumRestReceiptAmount = 0; //待請總餘額
string strReceiptUnitPrice = ""; //請款單價
string strReceiptQuantity = ""; //請款數量
double dbReceiptQuantity = 0; //請款數量
double dbTax = 0; //稅額
double dbReceiptAmount = 0; //請款金額
if (rbPayType.Checked == true) { foreach (DataGridViewRow drData in dgvOrderContent.Rows) { if (!drData.IsNewRow) { strRestReceipt = (string)drData.Cells["cQuantity"].Value; if (!string.IsNullOrEmpty(strRestReceipt)) //取得待請數量
{ if (strRestReceipt.IndexOf("%") != -1) { dbSumRestReceipt += Convert.ToDouble(string.IsNullOrEmpty(strRestReceipt) ? "0" : strRestReceipt.Replace("%", "")); strReceiptClass = "P"; } else { dbSumRestReceipt += Convert.ToDouble(string.IsNullOrEmpty(strRestReceipt) ? "0" : strRestReceipt.Replace(",", "")); strReceiptClass = "D"; } strRestReceiptAmount = (string)drData.Cells["cAmount"].Value; dbSumRestReceiptAmount += Convert.ToDouble(string.IsNullOrEmpty(strRestReceiptAmount) ? "0" : strRestReceiptAmount.Replace(",", ""));//取得待請餘額
} } } } else { foreach (DataGridViewRow drData in dgvOrderContent.Rows) { if ((string)drData.Cells["cOrderItem"].Value == strItemNo) { strRestReceipt = (string)drData.Cells["cQuantity"].Value; //取得待請數量
dbSumRestReceipt = string.IsNullOrEmpty(strRestReceipt) ? 0 : Convert.ToDouble(strRestReceipt.Replace(",", "")); strRestReceiptAmount = (string)drData.Cells["cAmount"].Value; //取得待請餘額
dbSumRestReceiptAmount = Convert.ToDouble(string.IsNullOrEmpty(strRestReceiptAmount) ? "0" : strRestReceiptAmount.Replace(",", "")); strReceiptClass = "D"; } } }
//變更該筆項目資料
strReceiptUnitPrice = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells[5].Value; strReceiptUnitPrice = string.IsNullOrEmpty(strReceiptUnitPrice) ? "0" : strReceiptUnitPrice.Replace(",", ""); //請款單價
strReceiptQuantity = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells[6].Value; if (strReceiptClass != "") { if (strReceiptClass == "P") //取得請款數量
{ dgvReceiptPlan.Columns["cReceiptItem"].ReadOnly = true; dgvReceiptPlan.AllowUserToAddRows = false; dbReceiptQuantity = string.IsNullOrEmpty(strReceiptQuantity) ? 0 : (Convert.ToDouble(strReceiptQuantity.Replace("%", "")) / 100); dbTax = Convert.ToDouble(strReceiptUnitPrice) * dbReceiptQuantity * 0.05; dbReceiptAmount = Convert.ToDouble(strReceiptUnitPrice) * Convert.ToDouble(dbReceiptQuantity) + dbTax; dgvReceiptPlan.Rows[e.RowIndex].Cells[12].Value = UtilityClass.MarkNumber(dbTax); //稅額
dgvReceiptPlan.Rows[e.RowIndex].Cells[13].Value = UtilityClass.MarkNumber(dbReceiptAmount); //請款金額
for (int intCount = 0; intCount < dgvReceiptPlan.Rows.Count; intCount++) { //重新整理期數 (專案分期模式,不可修改請款計劃)
if (!dgvReceiptPlan.Rows[intCount].IsNewRow) { dgvReceiptPlan.Rows[intCount].Cells[3].Value = intCount + 1; } } } else { dbReceiptQuantity = Convert.ToDouble(dgvReceiptPlan.Rows[e.RowIndex].Cells[6].Value); dbTax = Convert.ToDouble(strReceiptUnitPrice) * dbReceiptQuantity * 0.05; dbReceiptAmount = Convert.ToDouble(strReceiptUnitPrice) * Convert.ToDouble(dbReceiptQuantity) + dbTax; dgvReceiptPlan.Rows[e.RowIndex].Cells[12].Value = UtilityClass.MarkNumber(dbTax); //稅額
dgvReceiptPlan.Rows[e.RowIndex].Cells[13].Value = UtilityClass.MarkNumber(dbReceiptAmount); //請款金額
dbSumRestReceiptAmount = string.IsNullOrEmpty(strRestReceiptAmount) ? 0 : Convert.ToDouble(strRestReceiptAmount.Replace(",", "")); //可請款總額
for (int intCount = 0; intCount < dgvReceiptPlan.Rows.Count; intCount++) { //重新整理期數
if (!dgvReceiptPlan.Rows[intCount].IsNewRow) { dgvReceiptPlan.Rows[intCount].Cells[3].Value = intCount + 1; }
//重新計算相關資訊
if (strItemNo == (string)dgvReceiptPlan.Rows[intCount].Cells[2].Value) { if (strReceiptClass != "") { strReceiptQuantity = (string)dgvReceiptPlan.Rows[intCount].Cells[6].Value; dbSumRestReceipt = dbSumRestReceipt - (string.IsNullOrEmpty(strReceiptQuantity) ? 0 : Convert.ToDouble(strReceiptQuantity)); dgvReceiptPlan.Rows[intCount].Cells[7].Value = UtilityClass.MarkNumber(dbSumRestReceipt, 2); dbSumRestReceiptAmount = dbSumRestReceiptAmount - Convert.ToDouble(dgvReceiptPlan.Rows[intCount].Cells[13].Value.ToString().Replace(",", "")); dgvReceiptPlan.Rows[intCount].Cells[14].Value = UtilityClass.MarkNumber(dbSumRestReceiptAmount); } } } } } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void ReArrangePay(DataGridViewCellEventArgs e) //重新整理付款計劃
{ try { //物件宣告
string strItemNo = (string)dgvToPayPlan.Rows[e.RowIndex].Cells[2].Value; //項次
string strRestPay = ""; //付款數量
string strPayClass = ""; //付款計算方式 (P:百分比、D:三位一撇)
double dbSumRestPay = 0; //付款總量
string strRestPayAmount = ""; //待付餘額
double dbSumRestPayAmount = 0; //待付總餘額
string strPayUnitPrice = ""; //付款單價
string strPayQuantity = ""; //付款數量
double dbPayQuantity = 0; //付款數量
double dbPayAmount = 0; //付款金額
if (rbPayType.Checked == true) { foreach (DataGridViewRow drData in dgvOutSourcingContent.Rows) { if (!drData.IsNewRow) { strRestPay = (string)drData.Cells["cOutQuantity"].Value; if (!string.IsNullOrEmpty(strRestPay)) //取得待付數量
{ if (strRestPay.IndexOf("%") != -1) { dbSumRestPay += Convert.ToDouble(string.IsNullOrEmpty(strRestPay) ? "0" : strRestPay.Replace("%", "")); strPayClass = "P"; } else { dbSumRestPay += Convert.ToDouble(string.IsNullOrEmpty(strRestPay) ? "0" : strRestPay.Replace(",", "")); strPayClass = "D"; } strRestPayAmount = (string)drData.Cells["cOutAmount"].Value; dbSumRestPayAmount += Convert.ToDouble(string.IsNullOrEmpty(strRestPayAmount) ? "0" : strRestPayAmount.Replace(",", ""));//取得待付餘額
} } } } else { foreach (DataGridViewRow drData in dgvOutSourcingContent.Rows) { if ((string)drData.Cells["cOutOrderItem"].Value == strItemNo) { strRestPay = (string)drData.Cells["cOutQuantity"].Value; //取得待付數量
dbSumRestPay = string.IsNullOrEmpty(strRestPay) ? 0 : Convert.ToDouble(strRestPay.Replace(",", "")); strRestPayAmount = (string)drData.Cells["cOutAmount"].Value; //取得待付餘額
dbSumRestPayAmount = Convert.ToDouble(string.IsNullOrEmpty(strRestPayAmount) ? "0" : strRestPayAmount.Replace(",", "")); strPayClass = "D"; } } }
//變更該筆項目資料
strPayUnitPrice = (string)dgvToPayPlan.Rows[e.RowIndex].Cells[5].Value; strPayUnitPrice = string.IsNullOrEmpty(strPayUnitPrice) ? "0" : strPayUnitPrice.Replace(",", ""); //付款單價
strPayQuantity = (string)dgvToPayPlan.Rows[e.RowIndex].Cells[6].Value; if (strPayClass != "") { if (strPayClass == "P") //取得請款數量
{ dgvToPayPlan.Columns["cPayItem"].ReadOnly = true; dgvToPayPlan.AllowUserToAddRows = false; dbPayQuantity = string.IsNullOrEmpty(strPayQuantity) ? 0 : (Convert.ToDouble(strPayQuantity.Replace("%", "")) / 100); dbPayAmount = Convert.ToDouble(strPayUnitPrice) * Convert.ToDouble(dbPayQuantity); dgvToPayPlan.Rows[e.RowIndex].Cells[10].Value = UtilityClass.MarkNumber(dbPayAmount); //付款金額
for (int intCount = 0; intCount < dgvToPayPlan.Rows.Count; intCount++) { //重新整理期數 (專案分期模式,不可修改請款計劃)
if (!dgvToPayPlan.Rows[intCount].IsNewRow) { dgvToPayPlan.Rows[intCount].Cells[3].Value = intCount + 1; } } } else { dbPayQuantity = Convert.ToDouble(dgvToPayPlan.Rows[e.RowIndex].Cells[6].Value); dbPayAmount = Convert.ToDouble(strPayUnitPrice) * Convert.ToDouble(dbPayQuantity); dgvToPayPlan.Rows[e.RowIndex].Cells[10].Value = UtilityClass.MarkNumber(dbPayAmount); //付款金額
dbSumRestPayAmount = string.IsNullOrEmpty(strRestPayAmount) ? 0 : Convert.ToDouble(strRestPayAmount.Replace(",", "")); //可付款總額
for (int intCount = 0; intCount < dgvToPayPlan.Rows.Count; intCount++) { //重新整理期數
if (!dgvToPayPlan.Rows[intCount].IsNewRow) { dgvToPayPlan.Rows[intCount].Cells[3].Value = intCount + 1; }
//重新計算相關資訊
if (strItemNo == (string)dgvToPayPlan.Rows[intCount].Cells[2].Value) { if (strPayClass != "") { strPayQuantity = (string)dgvToPayPlan.Rows[intCount].Cells[6].Value; dbSumRestPay = dbSumRestPay - (string.IsNullOrEmpty(strPayQuantity) ? 0 : Convert.ToDouble(strPayQuantity.Replace(",", ""))); dgvToPayPlan.Rows[intCount].Cells[7].Value = UtilityClass.MarkNumber(dbSumRestPay, 2); dbSumRestPayAmount = dbSumRestPayAmount - Convert.ToDouble(dgvToPayPlan.Rows[intCount].Cells[10].Value.ToString().Replace(",", "")); dgvToPayPlan.Rows[intCount].Cells[11].Value = UtilityClass.MarkNumber(dbSumRestPayAmount); } } } } } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
public void ReturnCustomer(string[] strCustomerData) //回傳客戶資料
{ txtCustomerID.Text = strCustomerData[0].ToString(); txtCustomerName.Text = strCustomerData[1].ToString(); }
private void GetHistoryList() //取得歷史資料
{ try { string strCustomerID = txtCustomerID.Text.Trim(); if (string.IsNullOrEmpty(strCustomerID)) return; //判斷空值即不執行
StringBuilder strPJSQL = new StringBuilder(); strPJSQL.Append("Select ProjectNumber,ProjectCName From OTB_PRJ_ProjectInfo Where CustomerID ='" + strCustomerID + "' "); if (rbOrderStatusClose.Checked == true) { strPJSQL.Append("Union "); strPJSQL.Append("Select ProjectNumber,ProjectCName From OTB_PRJ_ProjectInfo_Closed Where CustomerID ='" + strCustomerID + "' "); }
DataTable dtTemp = UtilityClass.GetSQLResult(strPJSQL.ToString()).Tables["Result"]; } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private string GetSalesOrderNo(string strAccontingBookID) //取得最新訂單編號
{ try { string strReturnValue = ""; string strBookID = ""; switch (strAccountingBookID) { case "Origtek": strBookID = "OTK"; break; case "OrigtekEnergy": strBookID = "IPS"; break; } string strCHKSQL = string.Format("Select CountMax From OTB_SYS_MaxNumber Where Type='ORD' And CountYear ={0} And CountMonth={1}", DateTime.Now.Year, DateTime.Now.Month); DataTable dtTemp = UtilityClass.GetSQLResult(strCHKSQL).Tables["Result"]; if (dtTemp.Rows.Count > 0) { int intMaxNo = Convert.ToInt32(dtTemp.Rows[0]["CountMax"].ToString()) + 1; string strSQL = string.Format("Update OTB_SYS_MaxNumber Set CountMax = {0} Where Type='ORD' And CountYear ={1} And CountMonth={2}", intMaxNo, DateTime.Now.Year, DateTime.Now.Month); UtilityClass.RunSQLNonReturn(strSQL); strReturnValue = strBookID + DateTime.Now.Year.ToString("0000") + DateTime.Now.Month.ToString("00") + intMaxNo.ToString("000"); } else { int intMaxNo = 1; string strSQL = "Insert OTB_SYS_MaxNumber (Type, CountYear, CountMonth, CountDay, CountMax, CreateUser, CreateDate, ModifyUser, ModifyDate) "; strSQL += "Values ('ORD','" + DateTime.Now.Year.ToString() + "','" + DateTime.Now.Month.ToString() + "',' ','" + intMaxNo + "','" + strActiveUserID + "',GetDate(),'" + strActiveUserID + "', GetDate())"; UtilityClass.RunSQLNonReturn(strSQL); strReturnValue = strBookID + DateTime.Now.Year.ToString("0000") + DateTime.Now.Month.ToString("00") + intMaxNo.ToString("000"); } return strReturnValue; } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); return ""; } }
public void CountOrderSum() //計算訂單總金額
{ try { if (dgvOrderContent.Rows.Count > 0) { double dbOrderSum = 0; foreach (DataGridViewRow rwCount in dgvOrderContent.Rows) { string strCount = (string)rwCount.Cells["cAmount"].Value; if (!string.IsNullOrEmpty(strCount)) dbOrderSum += Convert.ToDouble(strCount.Replace(",", "")); } txtOrderSum.Text = UtilityClass.MarkNumber(dbOrderSum); } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
public void CountOutSourcingSum() //計算委外總金額
{ try { if (dgvOutSourcingContent.Rows.Count > 0) { double dbOutSourcingSum = 0; foreach (DataGridViewRow rwCount in dgvOutSourcingContent.Rows) { string strCount = (string)rwCount.Cells["cOutAmount"].Value; if (!string.IsNullOrEmpty(strCount)) dbOutSourcingSum += Convert.ToDouble(strCount.Replace(",", "")); } txtOutSourcingSum.Text = UtilityClass.MarkNumber(dbOutSourcingSum); } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void GetOrderDetail(string strCustomerID, string strCustomerName, string strOrderID, string strProjectName, string strProjectNumber, string strPayType, string strOrderStatus) //取得付款細部資料
{ try { //物件宣告
StringBuilder sbSQL = new StringBuilder(); string strSalesOrderNo = ""; //訂單編號
string strOrderItem = ""; //項次(cOrderItem)
string strOrderContent = ""; //採購項目(cOrderContent)
string strUnitPrice = ""; //單價(cUnitPrice)
string strQuantity = ""; //數量(cQuantity)
string strTax = ""; //稅額(cTax、cReceiptTax)
string strMemo = ""; //備註(cOrderMemo)
string strOutOrderItem = ""; //項次(cOutOrderItem)
string strOutOrderContent = ""; //委外項目(cOutOrderContent)
string strOutUnitPrice = ""; //委外單價(cOutUnitPrice)
string strOutQuantity = ""; //委外數量(cOutQuantity)
string strOutMemo = ""; //備註(cOutOrderMemo)
string strReceiptItem = ""; //請款項目
string strItemNo = ""; //項次
string strPhase = ""; //期數
string strReceiptNo = ""; //請款單號
string strReceiptUnitPrice = ""; //請款單價
string strReceiptQuantity = ""; //請款數量
string strRestReceipt = ""; //請款餘量
string strExpectedReceiptDate = ""; //預計請款日期
string strActualReceiptDate = ""; //實際請款日期
string strExpectedReceiptedDate = ""; //預計收款日期
string strActualReceiptedDate = ""; //實際收款日期
string strReceiptAmount = ""; //請款金額
string strRestReceiptAmount = ""; //待請餘額
string strPhaseNo = ""; //期數
string strInvoiceNo = ""; //發票號碼
string strPayItem = ""; //請款項目
string strPayUnitPrice = ""; //請款單價
string strPayQuantity = ""; //請款數量
string strRestPay = ""; //請款餘量
string strExpectedPayDate = ""; //預計付款日期
string strActualPayDate = ""; //實際付款日期
string strPayAmount = ""; //付款金額
string strRestPayAmount = ""; //待付餘額
//取得訂單基本資料
txtCustomerID.Text = strCustomerID; txtCustomerName.Text = strCustomerName; txtSalesOrderNo.Text = strOrderID; txtProjectName.Text = strProjectName; txtProjectNumber.Text = strProjectNumber; switch (strPayType) //設定付款方式
{ case "P": rbPayType.Checked = true; break; case "M": rbPayType1.Checked = true; break; case "D": rbPayType2.Checked = true; break; case "H": rbPayType3.Checked = true; break; }
switch (strOrderStatus) //設定訂單狀態
{ case "O": rbOrderStatusOpen.Checked = true; rbOrderStatusClose.Checked = false; break; case "C": rbOrderStatusClose.Checked = true; rbOrderStatusOpen.Checked = false; break; case " ": rbOrderStatusOpen.Checked = true; rbOrderStatusClose.Checked = false; break; }
//取得訂單內容資料
sbSQL.Clear(); sbSQL.Append("Select SalesOrderNo, ItemNo, OrderContent, UnitPrice, Quantity, Tax, Memo From OTB_SAL_OrderContent Where SalesOrderNo = '" + strOrderID + "' Order By ItemNo");
using (DataTable dtTemp = UtilityClass.GetSQLResult(sbSQL.ToString()).Tables["Result"]) { foreach (DataRow drData in dtTemp.Rows) { strOrderItem = (string)drData["ItemNo"]; strSalesOrderNo = (string)drData["SalesOrderNo"]; strOrderContent = (string)drData["OrderContent"]; strUnitPrice = (string)drData["UnitPrice"]; strQuantity = (string)drData["Quantity"]; strTax = (string)drData["Tax"]; strMemo = (string)drData["Memo"];
//產生資料
DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(dgvOrderContent); dgvRow.Cells[0].Value = strOrderItem; //項次
strUnitPrice = (string.IsNullOrEmpty(strUnitPrice) ? "" : UtilityClass.DecryptDES(strUnitPrice, strKey)); //單價
strQuantity = (string.IsNullOrEmpty(strQuantity) ? "" : UtilityClass.DecryptDES(strQuantity, strKey)); //數量
strTax = (string.IsNullOrEmpty(strTax) ? "" : UtilityClass.DecryptDES(strTax, strKey)); //稅額
dgvRow.Cells[2].Value = UtilityClass.MarkNumber(strUnitPrice); dgvRow.Cells[3].Value = UtilityClass.MarkNumber(strQuantity, 2); dgvRow.Cells[4].Value = UtilityClass.MarkNumber(strTax); if (strQuantity.IndexOf("%") != -1) { dgvRow.Cells[5].Value = UtilityClass.MarkNumber((Convert.ToDouble(strUnitPrice.Replace(",", "")) * Convert.ToDouble(strQuantity.Replace("%", "")) / 100) + Convert.ToDouble(strTax.Replace(",",""))); } else { dgvRow.Cells[5].Value = UtilityClass.MarkNumber((Convert.ToDouble(strUnitPrice.Replace(",", "")) * Convert.ToDouble(strQuantity.Replace(",", ""))) + Convert.ToDouble(strTax.Replace(",", ""))); } dgvRow.Cells[6].Value = strMemo; dgvOrderContent.Rows.Add(dgvRow); } CountOrderSum(); }
//取得委外內容資料
sbSQL.Clear(); sbSQL.Append("Select SalesOrderNo, ItemNo, OrderContent, UnitPrice, Quantity, Memo From OTB_SAL_OutSourcingContent Where SalesOrderNo = '" + strOrderID + "' Order By ItemNo");
using (DataTable dtOutTemp = UtilityClass.GetSQLResult(sbSQL.ToString()).Tables["Result"]) { foreach (DataRow drData in dtOutTemp.Rows) { strSalesOrderNo = (string)drData["SalesOrderNo"]; strOutOrderItem = (string)drData["ItemNo"]; strOutOrderContent = (string)drData["OrderContent"]; strOutUnitPrice = (string)drData["UnitPrice"]; strOutQuantity = (string)drData["Quantity"]; strOutMemo = (string)drData["Memo"];
//產生資料
DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(dgvOutSourcingContent); dgvRow.Cells[0].Value = strOutOrderItem; //項次
strOutUnitPrice = (string.IsNullOrEmpty(strOutUnitPrice) ? "" : UtilityClass.DecryptDES(strOutUnitPrice, strKey)); //單價
strOutQuantity = (string.IsNullOrEmpty(strOutQuantity) ? "" : UtilityClass.DecryptDES(strOutQuantity, strKey)); //數量
dgvRow.Cells[2].Value = UtilityClass.MarkNumber(strOutUnitPrice); dgvRow.Cells[3].Value = UtilityClass.MarkNumber(strOutQuantity, 2); if (strOutQuantity.IndexOf("%") != -1) { dgvRow.Cells[4].Value = UtilityClass.MarkNumber(Convert.ToDouble(strOutUnitPrice.Replace(",", "")) * Convert.ToDouble(strOutQuantity.Replace("%", "")) / 100); } else { dgvRow.Cells[4].Value = UtilityClass.MarkNumber(Convert.ToDouble(strOutUnitPrice.Replace(",", "")) * Convert.ToDouble(strOutQuantity.Replace(",", ""))); } dgvRow.Cells[5].Value = strMemo; dgvOutSourcingContent.Rows.Add(dgvRow); } CountOutSourcingSum(); }
//取得請款計劃
sbSQL.Clear(); sbSQL.Append("Select * From OTB_SAL_ReceiptPlan Where SalesOrderNo = '" + strOrderID + "' Order By Phase"); using (DataTable dtOutTemp = UtilityClass.GetSQLResult(sbSQL.ToString()).Tables["Result"]) { foreach (DataRow drData in dtOutTemp.Rows) { strSalesOrderNo = drData["SalesOrderNo"].ToString(); strItemNo = drData["ItemNo"].ToString(); //項次
strPhase = drData["Phase"].ToString(); //期數
strReceiptNo = drData["ReceiptNo"].ToString(); //請款單號
strReceiptItem = drData["ReceiptItem"].ToString(); //請款項目
strReceiptUnitPrice = drData["ReceiptUnitPrice"].ToString(); //請款單價
strReceiptQuantity = drData["ReceiptQuantity"].ToString(); //請款數量
strRestReceipt = drData["RestReceipt"].ToString(); //請款餘量
strExpectedReceiptDate = drData["ExpectedReceiptDate"].ToString(); //預計請款日期
strActualReceiptDate = drData["ActualReceiptDate"].ToString(); //實際請款日期
strExpectedReceiptedDate = drData["ExpectedReceiptedDate"].ToString(); //預計收款日期
strActualReceiptedDate = drData["ActualReceiptedDate"].ToString(); //實際收款日期
strReceiptAmount = drData["ReceiptAmount"].ToString(); //請款金額
strTax = drData["Tax"].ToString(); //請款金額
strRestReceiptAmount = drData["RestReceiptAmount"].ToString(); //待請餘額
strMemo = drData["Memo"].ToString(); //備註
//產生資料
DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(dgvReceiptPlan); dgvRow.Cells[1].Value = strReceiptItem; //請款項目
dgvRow.Cells[2].Value = strItemNo; //項次
dgvRow.Cells[3].Value = strPhase; //期數
dgvRow.Cells[4].Value = strReceiptNo; //請款單號
strReceiptUnitPrice = string.IsNullOrEmpty(strReceiptUnitPrice) ? "" : UtilityClass.DecryptDES(strReceiptUnitPrice, strKey); //請款單價
dgvRow.Cells[5].Value = UtilityClass.MarkNumber(strReceiptUnitPrice); strReceiptQuantity = string.IsNullOrEmpty(strReceiptQuantity) ? "" : UtilityClass.DecryptDES(strReceiptQuantity, strKey); //請款數量
dgvRow.Cells[6].Value = UtilityClass.MarkNumber(strReceiptQuantity, 2); strRestReceipt = string.IsNullOrEmpty(strRestReceipt) ? "" : UtilityClass.DecryptDES(strRestReceipt, strKey); //待請餘額
dgvRow.Cells[7].Value = UtilityClass.MarkNumber(strRestReceipt,2); dgvRow.Cells[8].Value = string.IsNullOrEmpty(strExpectedReceiptDate) ? "" : Convert.ToDateTime(strExpectedReceiptDate).ToString("yyyy/MM/dd"); //預計請款日期
dgvRow.Cells[9].Value = string.IsNullOrEmpty(strActualReceiptDate) ? "" : Convert.ToDateTime(strActualReceiptDate).ToString("yyyy/MM/dd"); //實際請款日期
dgvRow.Cells[10].Value = string.IsNullOrEmpty(strExpectedReceiptedDate) ? "" : Convert.ToDateTime(strExpectedReceiptedDate).ToString("yyyy/MM/dd"); //預計收款日期
dgvRow.Cells[11].Value = string.IsNullOrEmpty(strActualReceiptedDate) ? "" : Convert.ToDateTime(strActualReceiptedDate).ToString("yyyy/MM/dd"); //實際收款日期
strTax = string.IsNullOrEmpty(strTax) ? "" : UtilityClass.DecryptDES(strTax, strKey); //稅額
dgvRow.Cells[12].Value = UtilityClass.MarkNumber(strTax); strReceiptAmount = string.IsNullOrEmpty(strReceiptAmount) ? "" : UtilityClass.DecryptDES(strReceiptAmount, strKey); //請款金額
dgvRow.Cells[13].Value = UtilityClass.MarkNumber(strReceiptAmount); strRestReceiptAmount = string.IsNullOrEmpty(strRestReceiptAmount) ? "" : UtilityClass.DecryptDES(strRestReceiptAmount, strKey); //待請餘額
dgvRow.Cells[14].Value = UtilityClass.MarkNumber(strRestReceiptAmount); dgvRow.Cells[15].Value = strMemo; //備註
if (!string.IsNullOrEmpty(strReceiptNo)) //有請款記錄,設定為唯讀
{ dgvRow.ReadOnly = true; } dgvReceiptPlan.Rows.Add(dgvRow); } }
//取得付款計劃
sbSQL.Clear(); sbSQL.Append("Select * From OTB_SAL_PayPlan Where SalesOrderNo = '" + strOrderID + "' Order By PhaseNo");
using (DataTable dtOutTemp = UtilityClass.GetSQLResult(sbSQL.ToString()).Tables["Result"]) { foreach (DataRow drData in dtOutTemp.Rows) { strSalesOrderNo = drData["SalesOrderNo"].ToString(); strItemNo = drData["ItemNo"].ToString(); //項次
strPhaseNo = drData["PhaseNo"].ToString(); //期數
strInvoiceNo = drData["InvoiceNo"].ToString(); //發票號碼
strPayItem = drData["PayItem"].ToString(); //請款項目
strPayUnitPrice = drData["PayUnitPrice"].ToString(); //請款單價
strPayQuantity = drData["PayQuantity"].ToString(); //請款數量
strRestPay = drData["RestPay"].ToString(); //請款餘量
strExpectedPayDate = drData["ExpectedPayDate"].ToString(); //預計付款日期
strActualPayDate = drData["ActualPayDate"].ToString(); //實際付款日期
strPayAmount = drData["PayAmount"].ToString(); //付款金額
strRestPayAmount = drData["RestPayAmount"].ToString(); //待付餘額
strMemo = drData["Memo"].ToString(); //備註
//產生資料
DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(dgvToPayPlan); dgvRow.Cells[1].Value = strPayItem; //付款項目
dgvRow.Cells[2].Value = strItemNo; //項次
dgvRow.Cells[3].Value = strPhaseNo; //期數
dgvRow.Cells[4].Value = strInvoiceNo; //發票號碼
strPayUnitPrice = (string.IsNullOrEmpty(strPayUnitPrice) ? "" : UtilityClass.DecryptDES(strPayUnitPrice, strKey)); //付款單價
dgvRow.Cells[5].Value = UtilityClass.MarkNumber(strPayUnitPrice); strPayQuantity = (string.IsNullOrEmpty(strPayQuantity) ? "" : UtilityClass.DecryptDES(strPayQuantity, strKey)); //付款數量
dgvRow.Cells[6].Value = UtilityClass.MarkNumber(strPayQuantity, 2); strRestPay = (string.IsNullOrEmpty(strRestPay) ? "" : UtilityClass.DecryptDES(strRestPay, strKey)); //待付餘額
dgvRow.Cells[7].Value = UtilityClass.MarkNumber(strRestPay,2); dgvRow.Cells[8].Value = (string.IsNullOrEmpty(strExpectedPayDate) ? "" : Convert.ToDateTime(strExpectedPayDate).ToString("yyyy/MM/dd")); //預計付款日期
dgvRow.Cells[9].Value = (string.IsNullOrEmpty(strActualPayDate) ? "" : Convert.ToDateTime(strActualPayDate).ToString("yyyy/MM/dd")); //實際付款日期
strPayAmount = (string.IsNullOrEmpty(strPayAmount) ? "" : UtilityClass.DecryptDES(strPayAmount, strKey)); //付款金額
dgvRow.Cells[10].Value = UtilityClass.MarkNumber(strPayAmount); strRestPayAmount = (string.IsNullOrEmpty(strRestPayAmount) ? "" : UtilityClass.DecryptDES(strRestPayAmount, strKey)); //待付餘額
dgvRow.Cells[11].Value = UtilityClass.MarkNumber(strRestPayAmount); dgvRow.Cells[12].Value = strMemo; //備註
if (!string.IsNullOrEmpty(strInvoiceNo)) //有付款記錄,設定為唯讀
{ dgvRow.ReadOnly = true; } dgvToPayPlan.Rows.Add(dgvRow); } } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
public void CreateAR(DataGridViewCellEventArgs e) //增加應收帳款記錄
{ try { //物件宣告
string strCustomerID = ""; string strCustomerName = ""; string strSalesOrderNo = ""; string strProjectCName = ""; string strProjectNumber = ""; string strReceiptNo = ""; string strReceiptDate = ""; string strReceiptAmount = ""; string strMemo = ""; string strDC = ""; string strSubAccountingForAR = ""; string strXMLPath = ConfigurationManager.AppSettings["XMLFilePath"].ToString() + this.Name.ToString() + "_Receipt.xml"; if (File.Exists(strXMLPath)) { XDocument xmlContent = XDocument.Load(strXMLPath); foreach (XElement xmlData in xmlContent.Descendants("Accounting")) { strDC = xmlData.Element("SubAccounting").Attribute("DC").Value.ToString(); switch (strDC) { case "D": //取得應收帳款的分錄編號
strSubAccountingForAR = xmlData.Element("SubAccounting").Value.ToString(); break; } }
//增加應收帳款
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) {
string strSQL = "Insert Into OTB_FNC_AccountReceivable (AccountingBookID, SalesOrderNo, ProjectNumber, ProjectCName, ReceiptNo, CustomerID, CustomerName, ActualReceiptDate, ReceiptAmount, ReceiveStatus, Memo, CreateDate, CreateUser, ModifyDate, ModifyUser) Values "; strSQL += "(@AccountingBookID, @SalesOrderNo, @ProjectNumber,@ProjectCName, @ReceiptNo, @CustomerID, @CustomerName, @ActualReceiptDate, @ReceiptAmount, 'N', @Memo, Getdate(), @CreateUser, Getdate(), @ModifyUser)";
strCustomerID = txtCustomerID.Text.Trim(); strCustomerName = txtCustomerName.Text.Trim(); strSalesOrderNo = txtSalesOrderNo.Text.Trim(); strProjectNumber = txtProjectNumber.Text.Trim(); strProjectCName = txtProjectName.Text.Trim(); strReceiptNo = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptNo"].Value; strReceiptDate = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cActualReceiptDate"].Value; strReceiptAmount = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptAmount"].Value; strMemo = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cMemo"].Value;
//添加參數
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = strSQL; sqlAdapter.InsertCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@AccountingBookID",string.IsNullOrEmpty(strAccountingBookID) ? "" : strAccountingBookID), new SqlParameter("@SalesOrderNo",string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo), new SqlParameter("@ProjectNumber",string.IsNullOrEmpty(strProjectNumber) ? "" : strProjectNumber), new SqlParameter("@ProjectCName",string.IsNullOrEmpty(strProjectCName) ? "" : strProjectCName), new SqlParameter("@ReceiptNo",string.IsNullOrEmpty(strReceiptNo) ? "" : strReceiptNo), new SqlParameter("@CustomerID",string.IsNullOrEmpty(strCustomerID) ? "" : strCustomerID), new SqlParameter("@CustomerName",string.IsNullOrEmpty(strCustomerName) ? "" : strCustomerName), new SqlParameter("@ReceiptAmount",string.IsNullOrEmpty(strReceiptAmount) ? "" : UtilityClass.EncryptDES(strReceiptAmount,strKey)), new SqlParameter("@Memo",string.IsNullOrEmpty(strMemo) ? "" : strMemo), new SqlParameter("@CreateUser",strActiveUserID), new SqlParameter("@ModifyUser",strActiveUserID) } );
SqlParameter spActualReceiptDate = new SqlParameter("@ActualReceiptDate", SqlDbType.DateTime); spActualReceiptDate.Value = !UtilityClass.IsDate(strReceiptDate) ? null : strReceiptDate + " 00:00:00"; sqlAdapter.InsertCommand.Parameters.Add(spActualReceiptDate);
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); }
sqlAdapter.InsertCommand.ExecuteNonQuery(); } } } catch (Exception ex) { throw ex; } }
public void CreateAP(DataGridViewCellEventArgs e) //增加應付帳款記錄
{ try { //物件宣告
string strCustomerID = ""; string strCustomerName = ""; string strSalesOrderNo = ""; string strProjectNumber = ""; string strProjectCName = ""; string strInvoiceNo = ""; string strActualPaiedDate = ""; string strPayAmount = ""; string strMemo = ""; string strDC = ""; string strSubAccountingForAP = ""; string strXMLPath = ConfigurationManager.AppSettings["XMLFilePath"].ToString() + this.Name.ToString() + "_Pay.xml"; if (File.Exists(strXMLPath)) { XDocument xmlContent = XDocument.Load(strXMLPath); foreach (XElement xmlData in xmlContent.Descendants("Accounting")) { strDC = xmlData.Element("SubAccounting").Attribute("DC").Value.ToString(); switch (strDC) { case "C": //取得應付帳款的分錄編號
strSubAccountingForAP = xmlData.Element("SubAccounting").Value.ToString(); break; } }
//增加應付帳款
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) {
string strSQL = "Insert Into OTB_FNC_AccountPayable (AccountingBookID, SalesOrderNo, ProjectNumber, ProjectCName, InvoiceNo, CustomerID, CustomerName, ActualPaiedDate, PayAmount, PayStatus, Memo, CreateDate, CreateUser, ModifyDate, ModifyUser) Values "; strSQL += "(@AccountingBookID, @SalesOrderNo, @ProjectNumber, @ProjectCName, @InvoiceNo, @CustomerID, @CustomerName, @ActualPaiedDate, @PayAmount, 'N', @Memo, Getdate(), @CreateUser, Getdate(), @ModifyUser)";
strCustomerID = txtCustomerID.Text.Trim(); strCustomerName = txtCustomerName.Text.Trim(); strSalesOrderNo = txtSalesOrderNo.Text.Trim(); strProjectNumber = txtProjectNumber.Text.Trim(); strProjectCName = txtProjectName.Text.Trim(); strInvoiceNo = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cInvoiceNo"].Value; strActualPaiedDate = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cActualPaiedDate"].Value; strPayAmount = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayAmount"].Value; strMemo = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayMemo"].Value;
//添加參數
sqlAdapter.InsertCommand = new SqlCommand(); sqlAdapter.InsertCommand.Connection = sqlConn; sqlAdapter.InsertCommand.Transaction = sqlTran; sqlAdapter.InsertCommand.CommandText = strSQL; sqlAdapter.InsertCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@AccountingBookID",string.IsNullOrEmpty(strAccountingBookID) ? "" : strAccountingBookID), new SqlParameter("@SalesOrderNo",string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo), new SqlParameter("@ProjectNumber",string.IsNullOrEmpty(strProjectNumber) ? "" : strProjectNumber), new SqlParameter("@ProjectCName",string.IsNullOrEmpty(strProjectCName) ? "" : strProjectCName), new SqlParameter("@InvoiceNo",string.IsNullOrEmpty(strInvoiceNo) ? "" : strInvoiceNo), new SqlParameter("@CustomerID",string.IsNullOrEmpty(strCustomerID) ? "" : strCustomerID), new SqlParameter("@CustomerName",string.IsNullOrEmpty(strCustomerName) ? "" : strCustomerName), new SqlParameter("@PayAmount",string.IsNullOrEmpty(strPayAmount) ? "" : UtilityClass.EncryptDES(strPayAmount,strKey)), new SqlParameter("@Memo",string.IsNullOrEmpty(strMemo) ? "" : strMemo), new SqlParameter("@CreateUser",strActiveUserID), new SqlParameter("@ModifyUser",strActiveUserID) } );
SqlParameter spActualPayDate = new SqlParameter("@ActualPaiedDate", SqlDbType.DateTime); spActualPayDate.Value = !UtilityClass.IsDate(strActualPaiedDate) ? null : strActualPaiedDate + " 00:00:00"; sqlAdapter.InsertCommand.Parameters.Add(spActualPayDate);
if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); } sqlAdapter.InsertCommand.ExecuteNonQuery(); } } } catch (Exception ex) { throw ex; } } #endregion
#region 事件觸發及問題處理
private void PayPlanManagement_Load(object sender, EventArgs e) { SetupStatus(); LockForm(); GetOrderList(); }
private void tsbExit_Click(object sender, EventArgs e) { this.Close(); }
private void btnGetCustomer_Click(object sender, EventArgs e) { PickCustomer pkItemForm = new PickCustomer(); pkItemForm.txtCustomerName.Text = txtCustomerName.Text.Trim(); pkItemForm.strOwnerForm = "PayPlanManagement"; pkItemForm.Owner = this; pkItemForm.StartPosition = FormStartPosition.CenterParent; pkItemForm.ShowDialog(); }
private void tsbClean_Click(object sender, EventArgs e) { CleanForm(); }
private void tsbCancel_Click(object sender, EventArgs e) { CleanToolbar(); StatusChange("NONE"); }
private void tsbSearch_Click(object sender, EventArgs e) { StatusChange("SEARCH"); }
private void tsbDelete_Click(object sender, EventArgs e) { if (txtSalesOrderNo.Text.Trim() == "") { MessageBox.Show("請選擇要刪除的訂單請款資料", "提示"); } else { if (MessageBox.Show("請問您是否要刪除本訂單的相關請款資料?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
{ sqlConn.Open(); } sqlTran = sqlConn.BeginTransaction();
StringBuilder sbSQL = new StringBuilder(); string strSalesOrderNo = txtSalesOrderNo.Text.Trim();
//清除訂單及委外內容
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { sbSQL.Clear(); sbSQL.Append("Delete OTB_SAL_OrderList Where SalesOrderNo = @SalesOrderNo "); sbSQL.Append("Delete OTB_SAL_OrderContent Where SalesOrderNo = @SalesOrderNo "); sbSQL.Append("Delete OTB_SAL_OutSourcingContent Where SalesOrderNo = @SalesOrderNo ");
//添加參數
sqlAdapter.DeleteCommand = new SqlCommand(); sqlAdapter.DeleteCommand.Connection = sqlConn; sqlAdapter.DeleteCommand.Transaction = sqlTran; sqlAdapter.DeleteCommand.CommandText = sbSQL.ToString(); sqlAdapter.DeleteCommand.Parameters.AddRange ( new SqlParameter[] { new SqlParameter("@SalesOrderNo",string.IsNullOrEmpty(strSalesOrderNo) ? "" : strSalesOrderNo) } ); sqlAdapter.DeleteCommand.ExecuteNonQuery(); sqlTran.Commit(); StatusChange("SEARCH"); GoEvent(); } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); sqlTran.Rollback(); } } } }
private void tsbEdit_Click(object sender, EventArgs e) { if (txtProjectName.Text.Trim() == "") { MessageBox.Show("請選擇要修改的資料!", "提示"); return; } else { StatusChange("MODIFY"); dgvOrderList.ReadOnly = true;
if (txtSalesOrderNo.Text != "") { txtSalesOrderNo.ReadOnly = true; btnGetSalesOrderNo.Enabled = false; txtCustomerName.ReadOnly = true; btnGetCustomer.Enabled = false; txtProjectName.ReadOnly = true; tcOrderData.SelectedTab = OrderTab; btnArrangeProject.Enabled = true; btnArrangToPayProject.Enabled = true; rbOrderStatusClose.Enabled = true; rbOrderStatusOpen.Enabled = true; } } }
private void tsbOK_Click(object sender, EventArgs e) { try { GoEvent();
//還原Toolbar狀態
tsbSearch.Enabled = true; tsbOK.Visible = false;
//關閉查詢條件
LockForm(); StatusChange("NONE"); } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void cbHistory_CheckedChanged(object sender, EventArgs e) { GetHistoryList(); }
private void dgvOrderList_CellClick(object sender, DataGridViewCellEventArgs e) { CleanForm(); LockForm(); string strCustomerID = dgvOrderList.CurrentRow.Cells["cCustomerID"].Value.ToString(); string strCustomerName = dgvOrderList.CurrentRow.Cells["cCustomerName"].Value.ToString(); string strSalesOrderID = dgvOrderList.CurrentRow.Cells["cOrderID"].Value.ToString(); string strProjectName = dgvOrderList.CurrentRow.Cells["cProjectName"].Value.ToString(); string strProjectNumber = dgvOrderList.CurrentRow.Cells["cProjectNumber"].Value.ToString(); string strPayType = dgvOrderList.CurrentRow.Cells["cPayType"].Value.ToString(); string strOrderStatus = dgvOrderList.CurrentRow.Cells["cOrderStatus"].Value.ToString(); ((MainForm)ParentForm).SsStatus.Items["tsslModifyUser"].Text = dgvOrderList.CurrentRow.Cells["cModifyUser"].Value.ToString(); ((MainForm)ParentForm).SsStatus.Items["tsslModifyDate"].Text = dgvOrderList.CurrentRow.Cells["cModifyDate"].Value.ToString(); GetOrderDetail(strCustomerID, strCustomerName, strSalesOrderID, strProjectName, strProjectNumber, strPayType, strOrderStatus); UtilityClass.SetGridColor(dgvOrderContent); UtilityClass.SetGridColor(dgvOutSourcingContent); UtilityClass.SetGridColor(dgvReceiptPlan); UtilityClass.SetGridColor(dgvToPayPlan); }
private void tsbSave_Click(object sender, EventArgs e) { GoEvent(); //儲存作業
}
private void btnGetSalesOrderNo_Click(object sender, EventArgs e) { txtSalesOrderNo.Text = GetSalesOrderNo(strAccountingBookID); }
private void dgvOrderContent_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { //設定項次
string strOrderItem = (string)dgvOrderContent.Rows[e.RowIndex].Cells[0].Value; if (!string.IsNullOrEmpty(strOrderItem)) { string strSQL = "Select OrderContent From OTB_SAL_OrderContent Where SalesOrderNo='" + txtSalesOrderNo.Text.Trim() + "' And ItemNo = '" + strOrderItem + "'"; string strPayContent = UtilityClass.GetSQLResult(strSQL).Tables["Result"].Rows[0]["OrderContent"].ToString();
//設定採購項目
DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvOrderContent.Rows[e.RowIndex].Cells["cOrderContent"]; cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; cbCell.Value = strPayContent; }
}
private void dgvOrderContent_CellEndEdit(object sender, DataGridViewCellEventArgs e) { //物件宣告
string strUnitPrice = ""; string strQuantity = ""; string strTax = ""; string strSub = ""; //Cell[0] : 項次(cOrderItem)
//Cell[1] : 採購項目(cOrderContent)
//Cell[2] : 單價(cUnitPrice)
//Cell[3] : 數量(cQuantity)
//Cell[4] : 稅額(cTax)
//Cell[5] : 總計(cAmount)
//加上三位一撇效果
if (dgvOrderContent.Columns[e.ColumnIndex].Name == "cUnitPrice") { strUnitPrice = (string)dgvOrderContent.Rows[e.RowIndex].Cells["cUnitPrice"].Value; if (string.IsNullOrEmpty(strUnitPrice)) { return; } else { dgvOrderContent.Rows[e.RowIndex].Cells["cUnitPrice"].Value = UtilityClass.MarkNumber(strUnitPrice); } }
if (dgvOrderContent.Columns[e.ColumnIndex].Name == "cQuantity") { strQuantity = (string)dgvOrderContent.Rows[e.RowIndex].Cells["cQuantity"].Value; if (string.IsNullOrEmpty(strQuantity)) { return; } else { dgvOrderContent.Rows[e.RowIndex].Cells["cQuantity"].Value = UtilityClass.MarkNumber(strQuantity, 2); } }
if (dgvOrderContent.Columns[e.ColumnIndex].Name == "cTax") { strTax = (string)dgvOrderContent.Rows[e.RowIndex].Cells["cTax"].Value; if (string.IsNullOrEmpty(strTax)) { return; } else { dgvOrderContent.Rows[e.RowIndex].Cells["cTax"].Value = UtilityClass.MarkNumber(strTax); } }
//數量變動
if (dgvOrderContent.Columns[e.ColumnIndex].Name.ToString() == "cQuantity" | dgvOrderContent.Columns[e.ColumnIndex].Name.ToString() == "cUnitPrice") { strUnitPrice = (string)dgvOrderContent.Rows[e.RowIndex].Cells["cUnitPrice"].Value; strQuantity = (string)dgvOrderContent.Rows[e.RowIndex].Cells["cQuantity"].Value; strTax = (string)dgvOrderContent.Rows[e.RowIndex].Cells["cTax"].Value; if (!string.IsNullOrEmpty(strUnitPrice) & !string.IsNullOrEmpty(strQuantity)) { if (strQuantity.IndexOf("%") == -1) { strSub = (Convert.ToDouble(strUnitPrice.Replace(",", "")) * Convert.ToDouble(strQuantity.Replace(",", ""))).ToString(); double dbTax = Convert.ToDouble(strSub.Replace(",", "")) * 0.05; dgvOrderContent.Rows[e.RowIndex].Cells["cTax"].Value = Utility.UtilityClass.MarkNumber(dbTax.ToString()); dgvOrderContent.Rows[e.RowIndex].Cells["cAmount"].Value = UtilityClass.MarkNumber(Convert.ToDouble(strSub) + dbTax); } else { strSub = (Convert.ToDouble(strUnitPrice.Replace(",", "")) * Convert.ToDouble(strQuantity.Replace("%", "")) / 100).ToString(); double dbTax = Convert.ToDouble(strSub.Replace(",", "")) * 0.05; dgvOrderContent.Rows[e.RowIndex].Cells["cTax"].Value = Utility.UtilityClass.MarkNumber(dbTax.ToString()); dgvOrderContent.Rows[e.RowIndex].Cells["cAmount"].Value = UtilityClass.MarkNumber(Convert.ToDouble(strSub) + dbTax); } } }
CountOrderSum(); //重新計算訂單總金額
}
private void dgvOrderContent_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { //物件宣告
string strUnitPrice = ""; string strQuantity = "";
//Cell[0] : 項次(cOrderItem)
//Cell[1] : 採購項目(cOrderContent)
//Cell[2] : 單價(cUnitPrice)
//Cell[3] : 數量(cQuantity)
//Cell[4] : 總計(cAmount)
if (dgvOrderContent.Columns[e.ColumnIndex].Name == "cUnitPrice") { strUnitPrice = (string)dgvOrderContent.Rows[e.RowIndex].Cells["cUnitPrice"].Value; if (string.IsNullOrEmpty(strUnitPrice)) { return; } else { dgvOrderContent.Rows[e.RowIndex].Cells["cUnitPrice"].Value = strUnitPrice.Replace(",", ""); } }
if (dgvOrderContent.Columns[e.ColumnIndex].Name == "cQuantity") { strQuantity = (string)dgvOrderContent.Rows[e.RowIndex].Cells["cQuantity"].Value; if (string.IsNullOrEmpty(strQuantity)) { return; } else { dgvOrderContent.Rows[e.RowIndex].Cells["cQuantity"].Value = strQuantity.Replace(",", ""); } } } private void dgvOrderContent_RowEnter(object sender, DataGridViewCellEventArgs e) { dgvOrderContent.Rows[e.RowIndex].Cells["cOrderItem"].Value = (e.RowIndex + 1).ToString(); DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvOrderContent.Rows[e.RowIndex].Cells["cOrderContent"]; if (cbCell.Items.Count == 0) { cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; } }
private void dgvOrderContent_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { string strErrorMsg = ""; int intMsgCount = 0; try { //進行資料檢查
DataGridViewComboBoxCell cbCheck = (DataGridViewComboBoxCell)dgvOrderContent.Rows[e.RowIndex].Cells["cOrderContent"]; if (string.IsNullOrEmpty((string)cbCheck.Value)) { strErrorMsg = "請選擇採購項目"; intMsgCount += 1; }
if (string.IsNullOrEmpty((string)dgvOrderContent.Rows[e.RowIndex].Cells["cUnitPrice"].Value)) { strErrorMsg = "請輸入採購單價"; intMsgCount += 1; }
if (string.IsNullOrEmpty((string)dgvOrderContent.Rows[e.RowIndex].Cells["cQuantity"].Value)) { strErrorMsg = "請輸入採購數量"; intMsgCount += 1; } //else if(!rbPayType.Checked == true)
//{
// if (dgvOrderContent.Rows[e.RowIndex].Cells["cQuantity"].Value.ToString().IndexOf("%") != -1)
// {
// strErrorMsg = "請款方式為專案形態才能以百分比方式請款!";
// intMsgCount += 1;
// }
//}
if (strErrorMsg != "" && intMsgCount < 3) { dgvOrderContent.Rows[e.RowIndex].ErrorText = strErrorMsg; e.Cancel = true; } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void dgvOrderContent_RowValidated(object sender, DataGridViewCellEventArgs e) { dgvOrderContent.Rows[e.RowIndex].ErrorText = ""; }
private void btnArrangeProject_Click(object sender, EventArgs e) { string strPayType = ""; int intPayPlanItem = 1; string strReceiptNo = ""; //發票編號
string strOrderSum = "0"; //訂單總金額
string strAmount = "0"; //請款金額
string strBalance = "0"; //餘額
string strQuantity = "0"; //數量
string strQuantityStyle = ""; //數量呈現模式(P:百分比、D:三位一撇)
string strQuantityAmount = "0"; //訂單總量
string strReceiptUnitPrice = "0"; //請款單價
string strReceiptQuantity = "0"; //請款數量
string strRestQuantity = "0"; //請款餘量
string strTax = "0"; //稅額
bool blFound = true; //允許建立
if (MessageBox.Show("請問您是否確認要產生請款計劃?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { foreach (DataGridViewRow drData in dgvReceiptPlan.Rows) { strReceiptNo = (string)drData.Cells["cReceiptNo"].Value; if (!string.IsNullOrEmpty(strReceiptNo)) { MessageBox.Show("目前已有請款計劃,無法重新產生請款計劃!", "提示"); return; } }
dgvReceiptPlan.Rows.Clear(); //重新產生,先清除舊資料
//取得資訊
if (rbPayType.Checked == true) { strPayType = "P"; //專案類別
foreach (DataGridViewRow drData in dgvOrderContent.Rows) //數量加總
{ strQuantity = (string)drData.Cells["cQuantity"].Value; if (!string.IsNullOrEmpty(strQuantity)) { if (strQuantity.IndexOf("%") == -1) { strQuantityAmount = ((string.IsNullOrEmpty(strQuantityAmount) ? 0 : Convert.ToDouble(strQuantityAmount)) + Convert.ToDouble(strQuantity.Replace(",", ""))).ToString(); strQuantityStyle = "D"; } else { strQuantityAmount = ((string.IsNullOrEmpty(strQuantityAmount) ? 0 : Convert.ToDouble(strQuantityAmount)) + Convert.ToDouble(strQuantity.Replace("%", ""))).ToString(); strQuantityStyle = "P"; } } strAmount = (string)drData.Cells["cAmount"].Value; //小計加總
strOrderSum = (Convert.ToDouble(strOrderSum) + (string.IsNullOrEmpty(strAmount) ? 0 : Convert.ToDouble(strAmount.Replace(",", "")))).ToString(); }
switch (strQuantityStyle) { case "P": strQuantityAmount += "%"; break; case "D": strQuantityAmount = UtilityClass.MarkNumber(strQuantityAmount, 2); break; } }
if (rbPayType1.Checked == true) { strPayType = "M"; //人月類別
foreach (DataGridViewRow drData in dgvOrderContent.Rows) { strAmount = (string)drData.Cells["cAmount"].Value; strOrderSum = (Convert.ToDouble(strOrderSum) + (string.IsNullOrEmpty(strAmount) ? 0 : Convert.ToDouble(strAmount.Replace(",", "")))).ToString(); } }
if (rbPayType2.Checked == true) { strPayType = "D"; }
if (rbPayType3.Checked == true) { strPayType = "H"; }
//資料處理
switch (strPayType) { case "P": strBalance = strOrderSum; //訂單總金額
strRestQuantity = strQuantityAmount; //總數量
foreach (DataGridViewRow drData in dgvOrderContent.Rows) { DataGridViewComboBoxCell cbCHeck = (DataGridViewComboBoxCell)drData.Cells["cOrderContent"]; if (!string.IsNullOrEmpty((string)cbCHeck.Value)) { DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(dgvReceiptPlan); DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvRow.Cells[1]; if (cbCell.Items.Count == 0) { cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; } cbCell.Value = drData.Cells["cOrderContent"].Value; //請款項目
dgvRow.Cells[2].Value = drData.Cells["cOrderItem"].Value; //項次
dgvRow.Cells[3].Value = (intPayPlanItem++).ToString(); //期數
strReceiptUnitPrice = (string)drData.Cells["cUnitPrice"].Value; dgvRow.Cells[5].Value = string.IsNullOrEmpty(strReceiptUnitPrice) ? "" : strReceiptUnitPrice; //請款單價
strReceiptQuantity = (string)drData.Cells["cQuantity"].Value; dgvRow.Cells[6].Value = string.IsNullOrEmpty(strReceiptQuantity) ? "" : strReceiptQuantity; //請款數量
if (strQuantityAmount.IndexOf("%") != -1) //請款餘量
{ strRestQuantity = ((string.IsNullOrEmpty(strRestQuantity) ? 0 : Convert.ToDouble(strRestQuantity.Replace("%", ""))) - (string.IsNullOrEmpty(strReceiptQuantity) ? 0 : Convert.ToDouble(strReceiptQuantity.Replace("%", "")))).ToString() + "%"; dgvRow.Cells[7].Value = strRestQuantity; } else if (strQuantityAmount.IndexOf(",") != -1) { strRestQuantity = ((string.IsNullOrEmpty(strRestQuantity) ? 0 : Convert.ToDouble(strRestQuantity.Replace(",", ""))) - (string.IsNullOrEmpty(strReceiptQuantity) ? 0 : Convert.ToDouble(strReceiptQuantity.Replace(",", "")))).ToString(); dgvRow.Cells[7].Value = UtilityClass.MarkNumber(strRestQuantity, 2); } strAmount = (string)drData.Cells["cAmount"].Value; //請款金額
strTax = (Convert.ToDouble(strAmount.Replace(",", "")) / 1.05 * 0.05).ToString(); dgvRow.Cells[12].Value = string.IsNullOrEmpty(strAmount) ? "0" : UtilityClass.MarkNumber(strTax); //稅額
dgvRow.Cells[13].Value = string.IsNullOrEmpty(strAmount) ? "" : strAmount; strBalance = ((string.IsNullOrEmpty(strBalance) ? 0 : Convert.ToDouble(strBalance.Replace(",", ""))) - (string.IsNullOrEmpty(strAmount) ? 0 : Convert.ToDouble(strAmount.Replace(",", "")))).ToString(); dgvRow.Cells[14].Value = UtilityClass.MarkNumber(strBalance); //待請餘額
dgvReceiptPlan.Rows.Add(dgvRow); } } break;
case "M": dgvReceiptPlan.Rows.Clear(); //重新產生計劃
double dbQuantity = 0; double dbRestReceiptQuantity = 0; double dbBalance = 0; double dbSpendQuantity = 0; double dbAmount = 0;
//確認每個月請款數量
InputDialog frmInput = new InputDialog(); frmInput.lbQuestionMessage.Text = "請輸入每月請款人力數!"; frmInput.txtInput.Text = "1"; frmInput.StartPosition = FormStartPosition.CenterParent; DialogResult dr = frmInput.ShowDialog(); if (dr == DialogResult.OK) { dbSpendQuantity = Convert.ToDouble(frmInput.GetMsg()); } foreach (DataGridViewRow drData in dgvOrderContent.Rows) { dbQuantity = 0; strQuantity = (string)drData.Cells["cQuantity"].Value; //數量
dbRestReceiptQuantity = Convert.ToDouble(string.IsNullOrEmpty(strQuantity) ? 0 : Convert.ToDouble(strQuantity.Replace(",", ""))); dbAmount = Convert.ToDouble(drData.Cells["cAmount"].Value); dbBalance = string.IsNullOrEmpty(dbAmount.ToString()) ? 0 : dbAmount; DataGridViewComboBoxCell cbCHeck = (DataGridViewComboBoxCell)drData.Cells["cOrderContent"]; blFound = false; if (!drData.IsNewRow) { dbQuantity = Convert.ToDouble(drData.Cells["cQuantity"].Value.ToString()); for (double dbCount = 1; dbCount <= dbQuantity; dbCount++) { DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(dgvReceiptPlan); DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvRow.Cells[1]; if (cbCell.Items.Count == 0) { cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; } cbCell.Value = cbCHeck.Value; //請款項目
dgvRow.Cells[2].Value = drData.Cells["cOrderItem"].Value; //項次
dgvRow.Cells[3].Value = (intPayPlanItem++).ToString(); //期數
strReceiptUnitPrice = (string)drData.Cells["cUnitPrice"].Value; dgvRow.Cells[5].Value = string.IsNullOrEmpty(strReceiptUnitPrice) ? "" : strReceiptUnitPrice; //請款單價
if (dbRestReceiptQuantity >= dbSpendQuantity) { dgvRow.Cells[6].Value = UtilityClass.MarkNumber(dbSpendQuantity, 2); //請款數量
dbRestReceiptQuantity = dbRestReceiptQuantity - dbSpendQuantity; dgvRow.Cells[7].Value = UtilityClass.MarkNumber(dbRestReceiptQuantity, 2); //請款餘量
} else { dgvRow.Cells[6].Value = UtilityClass.MarkNumber(dbRestReceiptQuantity, 2); //請款數量
dbRestReceiptQuantity = dbRestReceiptQuantity - dbSpendQuantity; if (dbRestReceiptQuantity < 0) dgvRow.Cells[7].Value = UtilityClass.MarkNumber(0, 2); //請款餘量
} dbAmount = Convert.ToDouble(drData.Cells["cUnitPrice"].Value) * Convert.ToDouble(dgvRow.Cells[6].Value); strTax = (dbAmount * 0.05).ToString(); dgvRow.Cells[12].Value = string.IsNullOrEmpty(dbAmount.ToString()) ? "0" : UtilityClass.MarkNumber(strTax); //稅額
dgvRow.Cells[13].Value = string.IsNullOrEmpty(dbAmount.ToString()) ? "0" : UtilityClass.MarkNumber(dbAmount * 1.05); //請款金額
dbBalance = dbBalance - (dbAmount * 1.05); dgvRow.Cells[14].Value = UtilityClass.MarkNumber(dbBalance); //請款餘額
if (Convert.ToDouble(dgvRow.Cells[6].Value) > 0) { dgvReceiptPlan.Rows.Add(dgvRow); } } } } break; case "D": MessageBox.Show("人日無法產生請款計劃!","提示"); break; case "H": MessageBox.Show("人時無法產生請款計劃!", "提示"); break; } } }
private void dgvOutSourcingContent_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { //物件宣告
string strUnitPrice = ""; string strQuantity = "";
//Cell[0] : 項次(cOutOrderItem)
//Cell[1] : 委外項目(cOutOrderContent)
//Cell[2] : 委外單價(cOutUnitPrice)
//Cell[3] : 委外數量(cOutQuantity)
//Cell[4] : 委外小計(cOutAmount)
if (dgvOutSourcingContent.Columns[e.ColumnIndex].Name == "cOutUnitPrice") { strUnitPrice = (string)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutUnitPrice"].Value; if (string.IsNullOrEmpty(strUnitPrice)) { return; } else { dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutUnitPrice"].Value = strUnitPrice.Replace(",", ""); } }
if (dgvOutSourcingContent.Columns[e.ColumnIndex].Name == "cOutQuantity") { strQuantity = (string)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutQuantity"].Value; if (string.IsNullOrEmpty(strQuantity)) { return; } else { dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutQuantity"].Value = strQuantity.Replace(",", ""); } } }
private void dgvOutSourcingContent_CellEndEdit(object sender, DataGridViewCellEventArgs e) { //物件宣告
string strOutUnitPrice = ""; string strOutQuantity = "";
//Cell[0] : 項次(cOutOrderItem)
//Cell[1] : 委外項目(cOutOrderContent)
//Cell[2] : 委外單價(cOutUnitPrice)
//Cell[3] : 委外數量(cOutQuantity)
//Cell[4] : 委外總計(cOutAmount)
//加上三位一撇效果
if (dgvOutSourcingContent.Columns[e.ColumnIndex].Name == "cOutUnitPrice") { strOutUnitPrice = (string)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutUnitPrice"].Value; if (string.IsNullOrEmpty(strOutUnitPrice)) { return; } else { dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutUnitPrice"].Value = UtilityClass.MarkNumber(strOutUnitPrice); } }
if (dgvOutSourcingContent.Columns[e.ColumnIndex].Name == "cOutQuantity") { strOutQuantity = (string)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutQuantity"].Value; if (string.IsNullOrEmpty(strOutQuantity)) { return; } else { dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutQuantity"].Value = UtilityClass.MarkNumber(strOutQuantity, 2); } }
//數量變動
if (dgvOutSourcingContent.Columns[e.ColumnIndex].Name.ToString() == "cOutQuantity" | dgvOutSourcingContent.Columns[e.ColumnIndex].Name.ToString() == "cOutUnitPrice") { strOutUnitPrice = (string)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutUnitPrice"].Value; strOutQuantity = (string)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutQuantity"].Value; if (!string.IsNullOrEmpty(strOutUnitPrice) & !string.IsNullOrEmpty(strOutQuantity)) { if (strOutQuantity.IndexOf("%") == -1) { dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutAmount"].Value = UtilityClass.MarkNumber(Convert.ToDouble(strOutUnitPrice.Replace(",", "")) * Convert.ToDouble(strOutQuantity.Replace(",", ""))); } else { dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutAmount"].Value = UtilityClass.MarkNumber(Convert.ToDouble(strOutUnitPrice.Replace(",", "")) * Convert.ToDouble(strOutQuantity.Replace("%", "")) / 100); } } }
CountOutSourcingSum(); //重新計算委外加總
}
private void dgvOutSourcingContent_RowEnter(object sender, DataGridViewCellEventArgs e) { dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutOrderItem"].Value = (e.RowIndex + 1).ToString(); DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutOrderContent"]; if (cbCell.Items.Count == 0) { cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; } }
private void dgvOutSourcingContent_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { //設定項次
string strOrderItem = (string)dgvOutSourcingContent.Rows[e.RowIndex].Cells[0].Value; if (!string.IsNullOrEmpty(strOrderItem)) { string strSQL = "Select OrderContent From OTB_SAL_OutSourcingContent Where SalesOrderNo='" + txtSalesOrderNo.Text.Trim() + "' And ItemNo = '" + strOrderItem + "'"; string strPayContent = UtilityClass.GetSQLResult(strSQL).Tables["Result"].Rows[0]["OrderContent"].ToString();
//設定採購項目
DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutOrderContent"]; cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; cbCell.Value = strPayContent; }
}
private void dgvOutSourcingContent_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { string strErrorMsg = ""; int intMsgCount = 0; try { //進行資料檢查
DataGridViewComboBoxCell cbCheck = (DataGridViewComboBoxCell)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutOrderContent"]; if (!string.IsNullOrEmpty((string)cbCheck.Value)) { if (string.IsNullOrEmpty((string)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutUnitPrice"].Value)) { strErrorMsg = "請輸入委外單價"; intMsgCount += 1; }
if (string.IsNullOrEmpty((string)dgvOutSourcingContent.Rows[e.RowIndex].Cells["cOutQuantity"].Value)) { strErrorMsg = "請輸入委外數量"; intMsgCount += 1; }
if (strErrorMsg != "" && intMsgCount < 2) { dgvOutSourcingContent.Rows[e.RowIndex].ErrorText = strErrorMsg; e.Cancel = true; } } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void dgvOutSourcingContent_RowValidated(object sender, DataGridViewCellEventArgs e) { dgvOutSourcingContent.Rows[e.RowIndex].ErrorText = ""; }
private void dgvReceiptPlan_RowEnter(object sender, DataGridViewCellEventArgs e) { dgvReceiptPlan.Rows[e.RowIndex].Cells["cPhase"].Value = (e.RowIndex + 1).ToString(); DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptItem"]; if (cbCell.Items.Count == 0) { cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; } }
private void dgvReceiptPlan_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { //項次(cItemNo)
//期數(cPhase)
//請款單號(cReceiptNo)
//請款項目(cReceiptItem)
//請款數量(cReceiptQuantity)
//請款餘量(cRestReceipt)
//預計請款日期(cPrePayDate)
//實際請款日期(cActualReceiptDate)
//預計付款日期(cExpectedReceiptedDate)
//實際付款日期(cActualReceiptedDate)
//請款金額(cReceiptAmount)
//餘額(cRestReceiptAmount)
//備註(cMemo)
string strErrorMsg = ""; string strExpectedReceiptDate = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cExpectedReceiptDate"].Value; string strExpectedReceiptedDate = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cExpectedReceiptedDate"].Value; string strReceiptNo = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptNo"].Value; string strItemNo = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cItemNo"].Value; string strReceiptAmount = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptAmount"].Value; string strActualReceiptDate = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cActualReceiptDate"].Value; string strActualReceiptedDate = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cActualReceiptedDate"].Value; string strReceiptQuantity = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptQuantity"].Value;
try { //標準資料檢查
if (!dgvReceiptPlan.Rows[e.RowIndex].IsNewRow) { DataGridViewComboBoxCell cbCheck = (DataGridViewComboBoxCell)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptItem"]; if (string.IsNullOrEmpty((string)cbCheck.Value)) { strErrorMsg = "請選擇請款項目"; }
if (!string.IsNullOrEmpty(strItemNo)) { if (string.IsNullOrEmpty(strItemNo)) { strErrorMsg = "請款項次為必填項目!"; } } if (!string.IsNullOrEmpty(strExpectedReceiptDate)) { if (!UtilityClass.IsDate(strExpectedReceiptDate)) { strErrorMsg = "預計請款日期格式錯誤(應為:yyyy/mm/dd)!"; } }
if (!string.IsNullOrEmpty(strExpectedReceiptedDate)) { if (!UtilityClass.IsDate(strExpectedReceiptedDate)) { strErrorMsg = "預計收款日期格式錯誤(應為:yyyy/mm/dd)!"; }
if (DateTime.Compare(Convert.ToDateTime(strExpectedReceiptDate + " 00:00:00"), Convert.ToDateTime(strExpectedReceiptedDate + " 00:00:00")) > 0) { strErrorMsg = "預計收款日期應大於等於預計請款日期!"; } } }
//進行資料檢查
if (!string.IsNullOrEmpty(strReceiptNo)) { if (string.IsNullOrEmpty(strReceiptQuantity)) { strErrorMsg = "請輸入請款數量"; } else { strReceiptQuantity = strReceiptQuantity.Replace(",", ""); if (strReceiptQuantity.IndexOf("%") == -1) { if (!UtilityClass.IsNumber(strReceiptQuantity)) { strErrorMsg = "請款數量,數字格式有誤!"; } } }
if (!string.IsNullOrEmpty(strReceiptAmount)) { strReceiptAmount = strReceiptAmount.Replace(",", ""); if (!UtilityClass.IsNumber(strReceiptAmount)) { strErrorMsg = "請款金額,數字格式有誤!"; } }
if (!string.IsNullOrEmpty(strActualReceiptDate)) { if (!UtilityClass.IsDate(strActualReceiptDate)) { strErrorMsg = "實際請款日期格式錯誤(應為:yyyy/mm/dd)!"; } }
if (!string.IsNullOrEmpty(strActualReceiptedDate)) { if (!UtilityClass.IsDate(strActualReceiptedDate)) { strErrorMsg = "實際收款日期格式錯誤(應為:yyyy/mm/dd)!"; }
if (DateTime.Compare(Convert.ToDateTime(strActualReceiptDate + " 00:00:00"), Convert.ToDateTime(strActualReceiptedDate + " 00:00:00")) > 0) { strErrorMsg = "實際收款日期應大於等於實際請款日期!"; } } }
if (strErrorMsg != "") { dgvReceiptPlan.Rows[e.RowIndex].ErrorText = strErrorMsg; e.Cancel = true; } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void dgvReceiptPlan_RowValidated(object sender, DataGridViewCellEventArgs e) { ReArrangeReceipt(e); dgvReceiptPlan.Rows[e.RowIndex].ErrorText = ""; } private void dgvReceiptPlan_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { //設定項次
string strItemNo = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cItemNo"].Value; string strPhase = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cPhase"].Value; string strReceiptNo = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptNo"].Value;
if (!string.IsNullOrEmpty(strPhase)) { string strSQL = "Select ReceiptItem From OTB_SAL_ReceiptPlan Where SalesOrderNo='" + txtSalesOrderNo.Text.Trim() + "' And ItemNo = '" + strItemNo + "' And Phase = '" + strPhase + "'"; using(DataTable dtTemp =UtilityClass.GetSQLResult(strSQL).Tables["Result"]) { if(dtTemp.Rows.Count >0) { string strReceiptItem = dtTemp.Rows[0]["ReceiptItem"].ToString();
//設定採購項目
DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptItem"]; cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; cbCell.Value = strReceiptItem; } } }
if (!string.IsNullOrEmpty(strReceiptNo)) //判斷條件,設定該Row不可編輯
{ dgvReceiptPlan.Rows[e.RowIndex].ReadOnly = true; } }
private void tsbSetup_Click(object sender, EventArgs e) { PayPlanManagementSetup frmSettingForm = new PayPlanManagementSetup(); frmSettingForm.Owner = this; frmSettingForm.strOwnerForm = this.Name.ToString(); frmSettingForm.strXMLName = this.Name.ToString(); frmSettingForm.StartPosition = FormStartPosition.CenterParent; frmSettingForm.ShowDialog(); }
private void dgvReceiptPlan_CellContentClick(object sender, DataGridViewCellEventArgs e) { //物件宣告
string strDC = ""; string strReceipt = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptNo"].Value; string strReceiptAmount = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptAmount"].Value; try { //當GridView中的Button被按下
var SenderGrid = (DataGridView)sender; if (SenderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { if (string.IsNullOrEmpty(strReceipt)) { MessageBox.Show("請輸入發票號碼!", "提示"); return; }
if (SenderGrid.Rows[e.RowIndex].ReadOnly == true) //判定唯讀則不處理
{ return; } //Form設定
AccountingEntries acItemForm = new AccountingEntries(); acItemForm.strOwnerForm = "PayPlanManagement_Receive"; acItemForm.Owner = this; acItemForm.StartPosition = FormStartPosition.CenterParent; acItemForm.strFrmStatus = "ADD"; acItemForm.txtProjectName.Text = txtProjectName.Text; acItemForm.txtProjectNumber.Text = txtProjectNumber.Text; string strXMLPath = ConfigurationManager.AppSettings["XMLFilePath"].ToString() + this.Name.ToString() + "_Receipt.xml"; if (File.Exists(strXMLPath)) { XDocument xmlContent = XDocument.Load(strXMLPath);
foreach (XElement xmlData in xmlContent.Descendants("Accounting")) { DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(acItemForm.dgvDataMaintain); strDC = xmlData.Element("SubAccounting").Attribute("DC").Value.ToString(); switch (strDC) { case "D": dgvRow.Cells[1].Value = xmlData.Element("SubAccounting").Value.ToString(); dgvRow.Cells[2].Value = xmlData.Element("SubAccounting").Attribute("SubName").Value.ToString(); dgvRow.Cells[3].Value = "發票號碼:" + strReceipt; dgvRow.Cells[4].Value = strReceiptAmount; break; case "C": dgvRow.Cells[1].Value = xmlData.Element("SubAccounting").Value.ToString(); dgvRow.Cells[2].Value = xmlData.Element("SubAccounting").Attribute("SubName").Value.ToString(); dgvRow.Cells[3].Value = "發票號碼:" + strReceipt; dgvRow.Cells[5].Value = strReceiptAmount; break; } blIsAdded = false; if (string.IsNullOrEmpty((string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cActualReceiptDate"].Value)) { dgvReceiptPlan.Rows[e.RowIndex].Cells["cActualReceiptDate"].Value = DateTime.Now.ToString("yyyy/MM/dd"); } acItemForm.dgvDataMaintain.Rows.Add(dgvRow); } acItemForm.dgeArgs = e; } acItemForm.ShowDialog(); } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void dgvReceiptPlan_CellEnter(object sender, DataGridViewCellEventArgs e) { try { ReArrangeReceipt(e); } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void dgvReceiptPlan_CellEndEdit(object sender, DataGridViewCellEventArgs e) { //宣告物件
string strReceiptUnitPrice = ""; //請款單價
string strReceiptQuantity = ""; //請款數量
string strReceiptNo = ""; //發票號碼
//發票號碼變大寫
if (dgvReceiptPlan.Columns[e.ColumnIndex].Name == "cReceiptNo") { strReceiptNo = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptNo"].Value; dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptNo"].Value = string.IsNullOrEmpty(strReceiptNo) ? "" : strReceiptNo.ToUpper(); }
//加上三位一撇效果
if (dgvReceiptPlan.Columns[e.ColumnIndex].Name == "cReceiptUnitPrice") { strReceiptUnitPrice = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptUnitPrice"].Value; if (string.IsNullOrEmpty(strReceiptUnitPrice)) { return; } else { dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptUnitPrice"].Value = UtilityClass.MarkNumber(strReceiptUnitPrice); } }
if (dgvReceiptPlan.Columns[e.ColumnIndex].Name == "cReceiptQuantity") { //回傳處理後的數量
strReceiptQuantity = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptQuantity"].Value; if (string.IsNullOrEmpty(strReceiptQuantity)) { return; } else { dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptQuantity"].Value = UtilityClass.MarkNumber(strReceiptQuantity, 2); } }
//輸入值為請款金額回推試算
//if (dgvReceiptPlan.Columns[e.ColumnIndex].Name == "cReceiptAmount")
//{
// string strUnitPrice = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptUnitPrice"].Value;
// if (!string.IsNullOrEmpty(strUnitPrice))
// {
// string strReceiptAmount = (string)dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptAmount"].Value;
// double dbRecmiptAmount = Convert.ToDouble(strReceiptAmount.Replace(",",""));
// dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptTax"].Value = UtilityClass.MarkNumber(dbRecmiptAmount / 1.05 * 0.05); //計算稅額
// dgvReceiptPlan.Rows[e.RowIndex].Cells["cReceiptQuantity"].Value = UtilityClass.MarkNumber(dbRecmiptAmount / Convert.ToDouble(strUnitPrice.Replace(",",""))); //計算數量
// }
//}
}
private void btnArrangToPayProject_Click(object sender, EventArgs e) { string strPayType = ""; int intPayPlanItem = 1; string strInvoiceNo = ""; //付款單號
string strPurchaseOrderSum = "0"; //採購單總金額
string strPayAmount = "0"; //付款金額
string strPayBalance = "0"; //餘額
string strQuantityStyle = ""; //數量呈現模式(P:百分比、D:三位一撇)
string strPayQuantityAmount = "0"; //採購單總量
string strPayUnitPrice = "0"; //付款單價
string strPayQuantity = "0"; //付款數量
string strRestPayQuantity = "0"; //付款餘量
bool blFound = true; //允許建立
if (MessageBox.Show("請問您是否確認要產生付款計劃?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { foreach (DataGridViewRow drData in dgvToPayPlan.Rows) { strInvoiceNo = (string)drData.Cells["cInvoiceNo"].Value; if (!string.IsNullOrEmpty(strInvoiceNo)) { MessageBox.Show("目前已有付款計劃,無法重新產生付款計劃!", "提示"); return; } }
dgvToPayPlan.Rows.Clear(); //重新產生,先清除舊資料
//取得資訊
if (rbPayType.Checked == true) {
strPayType = "P"; //專案類別
foreach (DataGridViewRow drData in dgvOutSourcingContent.Rows) //數量加總
{ strPayQuantity = (string)drData.Cells["cOutQuantity"].Value; if (!string.IsNullOrEmpty(strPayQuantity)) { if (strPayQuantity.IndexOf("%") != -1) { strPayQuantityAmount = ((string.IsNullOrEmpty(strPayQuantity) ? 0 : Convert.ToDouble(strPayQuantityAmount)) + Convert.ToDouble(strPayQuantity.Replace("%", ""))).ToString(); strQuantityStyle = "P"; } else { strPayQuantityAmount = ((string.IsNullOrEmpty(strPayQuantity) ? 0 : Convert.ToDouble(strPayQuantityAmount)) + Convert.ToDouble(strPayQuantity.Replace(",", ""))).ToString(); strQuantityStyle = "D"; } } strPayAmount = (string)drData.Cells["cOutAmount"].Value; //小計加總
strPurchaseOrderSum = (Convert.ToDouble(strPurchaseOrderSum) + (string.IsNullOrEmpty(strPayAmount) ? 0 : Convert.ToDouble(strPayAmount.Replace(",", "")))).ToString(); }
switch (strQuantityStyle) { case "P": strPayQuantityAmount += "%"; break; case "D": strPayQuantityAmount = UtilityClass.MarkNumber(strPayQuantityAmount, 2); break; }
}
if (rbPayType1.Checked == true) { strPayType = "M"; //人月類別
foreach (DataGridViewRow drData in dgvOutSourcingContent.Rows) { strPayAmount = (string)drData.Cells["cOutAmount"].Value; strPurchaseOrderSum = (Convert.ToDouble(strPurchaseOrderSum) + (string.IsNullOrEmpty(strPayAmount) ? 0 : Convert.ToDouble(strPayAmount.Replace(",", "")))).ToString(); } }
if (rbPayType2.Checked == true) { strPayType = "D"; }
if (rbPayType3.Checked == true) { strPayType = "H"; }
//資料處理
switch (strPayType) { case "P": strPayBalance = strPurchaseOrderSum; //採購總金額
strRestPayQuantity = strPayQuantityAmount; //採購總數量
foreach (DataGridViewRow drData in dgvOutSourcingContent.Rows) { DataGridViewComboBoxCell cbCHeck = (DataGridViewComboBoxCell)drData.Cells["cOutOrderContent"];
if (!string.IsNullOrEmpty((string)cbCHeck.Value)) { DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(dgvToPayPlan); DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvRow.Cells[1]; if (cbCell.Items.Count == 0) { cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; } cbCell.Value = drData.Cells["cOutOrderContent"].Value; //付款項目
dgvRow.Cells[2].Value = drData.Cells["cOutOrderItem"].Value; //項次
dgvRow.Cells[3].Value = (intPayPlanItem++).ToString(); //期數
strPayUnitPrice = (string)drData.Cells["cOutUnitPrice"].Value; dgvRow.Cells[5].Value = string.IsNullOrEmpty(strPayUnitPrice) ? "" : strPayUnitPrice; //付款單價
strPayQuantity = (string)drData.Cells["cOutQuantity"].Value; dgvRow.Cells[6].Value = string.IsNullOrEmpty(strPayQuantity) ? "" : strPayQuantity; //付款數量
if (strRestPayQuantity.IndexOf("%") != -1) //付款餘量
{ strRestPayQuantity = ((string.IsNullOrEmpty(strRestPayQuantity) ? 0 : Convert.ToDouble(strRestPayQuantity.Replace("%", ""))) - (string.IsNullOrEmpty(strPayQuantity) ? 0 : Convert.ToDouble(strPayQuantity.Replace("%", "")))).ToString() + "%"; dgvRow.Cells[7].Value = strRestPayQuantity; } else if (strRestPayQuantity.IndexOf(",") != -1) { strRestPayQuantity = ((string.IsNullOrEmpty(strRestPayQuantity) ? 0 : Convert.ToDouble(strRestPayQuantity.Replace(",", ""))) - (string.IsNullOrEmpty(strPayQuantity) ? 0 : Convert.ToDouble(strPayQuantity.Replace(",", "")))).ToString(); dgvRow.Cells[7].Value = UtilityClass.MarkNumber(strRestPayQuantity, 2); }
strPayAmount = (string)drData.Cells["cOutAmount"].Value; //付款金額
dgvRow.Cells[10].Value = string.IsNullOrEmpty(strPayAmount) ? "" : strPayAmount; strPayBalance = ((string.IsNullOrEmpty(strPayBalance) ? 0 : Convert.ToDouble(strPayBalance.Replace(",", ""))) - (string.IsNullOrEmpty(strPayAmount) ? 0 : Convert.ToDouble(strPayAmount.Replace(",", "")))).ToString(); dgvRow.Cells[11].Value = UtilityClass.MarkNumber(strPayBalance); //待付餘額
dgvToPayPlan.Rows.Add(dgvRow); } } break;
case "M": dgvToPayPlan.Rows.Clear(); //重新產生計劃
double dbQuantity = 0; double dbRestPayQuantity = 0; double dbBalance = 0; double dbPayQuantity = 0; double dbPayAmount = 0; //確認每個月付款數量
InputDialog frmInput = new InputDialog(); frmInput.lbQuestionMessage.Text = "請輸入每月付款人力數!"; frmInput.txtInput.Text = "1"; frmInput.StartPosition = FormStartPosition.CenterParent; DialogResult dr = frmInput.ShowDialog(); if (dr == DialogResult.OK) { dbPayQuantity = Convert.ToDouble(frmInput.GetMsg()); }
foreach (DataGridViewRow drData in dgvOutSourcingContent.Rows) { dbQuantity = 0; strPayQuantity = (string)drData.Cells["cOutQuantity"].Value; //數量
dbRestPayQuantity = Convert.ToDouble(string.IsNullOrEmpty(strPayQuantity) ? 0 : Convert.ToDouble(strPayQuantity.Replace(",", ""))); dbPayAmount = Convert.ToDouble(drData.Cells["cOutAmount"].Value); dbBalance = Convert.ToDouble(string.IsNullOrEmpty(dbPayAmount.ToString()) ? 0 : dbPayAmount); DataGridViewComboBoxCell cbCHeck = (DataGridViewComboBoxCell)drData.Cells["cOutOrderContent"]; blFound = false; if (!drData.IsNewRow) { dbQuantity = Convert.ToDouble(drData.Cells["cOutQuantity"].Value.ToString()); for (double dbCount = 1; dbCount <= dbQuantity; dbCount++) { DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(dgvToPayPlan); DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvRow.Cells[1]; if (cbCell.Items.Count == 0) { cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; } cbCell.Value = cbCHeck.Value; //付款項目
dgvRow.Cells[2].Value = drData.Cells["cOutOrderItem"].Value; //項次
dgvRow.Cells[3].Value = (intPayPlanItem++).ToString(); //期數
strPayUnitPrice = (string)drData.Cells["cOutUnitPrice"].Value; dgvRow.Cells[5].Value = string.IsNullOrEmpty(strPayUnitPrice) ? "" : UtilityClass.MarkNumber(strPayUnitPrice); //付款單價
if (dbRestPayQuantity >= dbPayQuantity) { dgvRow.Cells[6].Value = UtilityClass.MarkNumber(dbPayQuantity, 2); //付款數量
dbRestPayQuantity = dbRestPayQuantity - dbPayQuantity; dgvRow.Cells[7].Value = UtilityClass.MarkNumber(dbRestPayQuantity, 2); //付款餘量
} else { dgvRow.Cells[6].Value = UtilityClass.MarkNumber(dbRestPayQuantity, 2); //付款數量
dbRestPayQuantity = dbRestPayQuantity - dbPayQuantity; if (dbRestPayQuantity < 0) dgvRow.Cells[7].Value = UtilityClass.MarkNumber(0, 2); //付款餘量
} dbPayAmount = Convert.ToDouble(drData.Cells["cOutUnitPrice"].Value) * Convert.ToDouble(dgvRow.Cells[6].Value); dgvRow.Cells[10].Value = string.IsNullOrEmpty(dbPayAmount.ToString()) ? "0" : UtilityClass.MarkNumber(dbPayAmount); //付款金額
dbBalance = dbBalance - dbPayAmount; dgvRow.Cells[11].Value = UtilityClass.MarkNumber(dbBalance); //付款餘額
if (Convert.ToDouble(dgvRow.Cells[6].Value) > 0) { dgvToPayPlan.Rows.Add(dgvRow); } } } } break; case "D": MessageBox.Show("人日無法產生付款計劃!", "提示"); break; case "H": MessageBox.Show("人時無法產生付款計劃!", "提示"); break; } } }
private void dgvToPayPlan_CellEndEdit(object sender, DataGridViewCellEventArgs e) { //宣告物件
string strPayUnitPrice = ""; //請款單價
string strPayQuantity = ""; //請款數量
string strInvoiceNo = ""; //發票號碼
//發票號碼變大寫
if (dgvToPayPlan.Columns[e.ColumnIndex].Name == "cInvoiceNo") { strInvoiceNo = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cInvoiceNo"].Value; dgvToPayPlan.Rows[e.RowIndex].Cells["cInvoiceNo"].Value = strInvoiceNo.ToUpper(); }
//加上三位一撇效果
if (dgvToPayPlan.Columns[e.ColumnIndex].Name == "cPayUnitPrice") { strPayUnitPrice = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayUnitPrice"].Value; if (string.IsNullOrEmpty(strPayUnitPrice)) { return; } else { dgvToPayPlan.Rows[e.RowIndex].Cells["cPayUnitPrice"].Value = UtilityClass.MarkNumber(strPayUnitPrice); } }
if (dgvToPayPlan.Columns[e.ColumnIndex].Name == "cPayQuantity") { strPayQuantity = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayQuantity"].Value; if (string.IsNullOrEmpty(strPayQuantity)) { return; } else { dgvToPayPlan.Rows[e.RowIndex].Cells["cPayQuantity"].Value = UtilityClass.MarkNumber(strPayQuantity, 2); } } }
private void dgvToPayPlan_CellEnter(object sender, DataGridViewCellEventArgs e) { try { ReArrangePay(e); } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void dgvToPayPlan_RowValidated(object sender, DataGridViewCellEventArgs e) { ReArrangePay(e); dgvToPayPlan.Rows[e.RowIndex].ErrorText = ""; }
private void dgvToPayPlan_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { //設定項次
string strItemNo = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayItemNo"].Value; string strPayPhase = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayPhase"].Value; string strInvoiceNo = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cInvoiceNo"].Value;
if (!string.IsNullOrEmpty(strPayPhase)) { string strSQL = "Select PayItem From OTB_SAL_PayPlan Where SalesOrderNo='" + txtSalesOrderNo.Text.Trim() + "' And ItemNo = '" + strItemNo + "' And PhaseNo = '" + strPayPhase + "'"; using (DataTable dtTemp = UtilityClass.GetSQLResult(strSQL).Tables["Result"]) { if (dtTemp.Rows.Count > 0) { string strPayItem = dtTemp.Rows[0]["PayItem"].ToString();
//設定採購項目
DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayItem"]; cbCell.DataSource = UtilityClass.GetSystemArgument("PayItem", "zh-TW").Tables["Arguments"]; cbCell.DisplayMember = "ArgumentValue"; cbCell.ValueMember = "ArgumentID"; cbCell.Value = strPayItem; } } }
if (!string.IsNullOrEmpty(strInvoiceNo)) //判斷條件,設定該Row不可編輯
{ dgvToPayPlan.Rows[e.RowIndex].ReadOnly = true; } }
private void dgvToPayPlan_CellContentClick(object sender, DataGridViewCellEventArgs e) { //物件宣告
string strDC = ""; string strInvoiceNo = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cInvoiceNo"].Value; string strPayAmount = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayAmount"].Value; try { //當GridView中的Button被按下
var SenderGrid = (DataGridView)sender; if (SenderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { if (string.IsNullOrEmpty(strInvoiceNo)) { MessageBox.Show("請輸入發票號碼!", "提示"); return; }
if (SenderGrid.Rows[e.RowIndex].ReadOnly == true) //判定唯讀則不處理
{ return; } //Form設定
AccountingEntries acItemForm = new AccountingEntries(); acItemForm.strOwnerForm = "PayPlanManagement_Pay"; acItemForm.Owner = this; acItemForm.StartPosition = FormStartPosition.CenterParent; acItemForm.strFrmStatus = "ADD"; acItemForm.txtProjectName.Text = txtProjectName.Text; acItemForm.txtProjectNumber.Text = txtProjectNumber.Text; string strXMLPath = ConfigurationManager.AppSettings["XMLFilePath"].ToString() + this.Name.ToString() + "_Pay.xml"; if (File.Exists(strXMLPath)) { XDocument xmlContent = XDocument.Load(strXMLPath);
foreach (XElement xmlData in xmlContent.Descendants("Accounting")) { DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(acItemForm.dgvDataMaintain); strDC = xmlData.Element("SubAccounting").Attribute("DC").Value.ToString(); switch (strDC) { case "D": dgvRow.Cells[1].Value = xmlData.Element("SubAccounting").Value.ToString(); dgvRow.Cells[2].Value = xmlData.Element("SubAccounting").Attribute("SubName").Value.ToString(); dgvRow.Cells[4].Value = strPayAmount; break; case "C": dgvRow.Cells[1].Value = xmlData.Element("SubAccounting").Value.ToString(); dgvRow.Cells[2].Value = xmlData.Element("SubAccounting").Attribute("SubName").Value.ToString(); dgvRow.Cells[3].Value = "發票號碼:" + strInvoiceNo; dgvRow.Cells[5].Value = strPayAmount; break; } blIsAdded = false; if (string.IsNullOrEmpty((string)dgvToPayPlan.Rows[e.RowIndex].Cells["cActualPaiedDate"].Value)) { dgvToPayPlan.Rows[e.RowIndex].Cells["cActualPaiedDate"].Value = DateTime.Now.ToString("yyyy/MM/dd"); } acItemForm.dgvDataMaintain.Rows.Add(dgvRow); } acItemForm.dgeArgs = e; } acItemForm.ShowDialog(); } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void dgvToPayPlan_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { //期數(cPhase)
//發票號碼(cInvoiceNo)
//付款項目(cPayItem)
//付款數量(cReceiptQuantity)
//付款餘量(cRestReceipt)
//預計付款日期(cExpectedPayDate)
//實際付款日期(cActualPaiedDate)
//付款金額(cPayAmount)
//餘額(cRestPayAmount)
//備註(cPayMemo)
string strErrorMsg = ""; string strInvoiceNo = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cInvoiceNo"].Value; string strPayAmount = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayAmount"].Value; string strExpectedPayDate = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cExpectedPayDate"].Value; string strActualPayDate = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cActualPaiedDate"].Value; string strPayQuantity = (string)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayQuantity"].Value; try { //標準資料檢查
if (!dgvToPayPlan.Rows[e.RowIndex].IsNewRow) {
if (!string.IsNullOrEmpty(strExpectedPayDate)) { if (!UtilityClass.IsDate(strExpectedPayDate)) { strErrorMsg = "預計付款日期格式錯誤(應為:yyyy/mm/dd)!"; } }
if (!string.IsNullOrEmpty(strActualPayDate)) { if (!UtilityClass.IsDate(strActualPayDate)) { strErrorMsg = "實計付款日期格式錯誤(應為:yyyy/mm/dd)!"; } } }
//進行資料檢查
if (!string.IsNullOrEmpty(strInvoiceNo)) { DataGridViewComboBoxCell cbCheck = (DataGridViewComboBoxCell)dgvToPayPlan.Rows[e.RowIndex].Cells["cPayItem"]; if (string.IsNullOrEmpty((string)cbCheck.Value)) { strErrorMsg = "請選擇付款項目"; }
if (string.IsNullOrEmpty(strPayQuantity)) { strErrorMsg = "請輸入付款數量"; } else { strPayQuantity = strPayQuantity.Replace(",", ""); if (strPayQuantity.IndexOf("%") == -1) { if (!UtilityClass.IsNumber(strPayQuantity)) { strErrorMsg = "請款數量,數字格式有誤!"; } } }
if (!string.IsNullOrEmpty(strPayAmount)) { strPayAmount = strPayAmount.Replace(",", ""); if (!UtilityClass.IsNumber(strPayAmount)) { strErrorMsg = "請款金額,數字格式有誤!"; } } }
if (strErrorMsg != "") { dgvToPayPlan.Rows[e.RowIndex].ErrorText = strErrorMsg; e.Cancel = true; } } catch (Exception ex) { ErrorHandler.WriteErrorLog("PayPlanManagement.cs", ex); } }
private void txtSalesOrderNo_Leave(object sender, EventArgs e) { txtSalesOrderNo.Text = txtSalesOrderNo.Text.ToUpper(); } #endregion
} }
|