private void btnSave_Click(object sender, EventArgs e) { if (this.txtCustId.Text.Trim() == "") { MessageBox.Show("客户代码不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (this.txtInMoney.Text.Trim() != "" && !Util.IsNumberic(this.txtInMoney)) { MessageBox.Show("核销金额只能为数值型数据!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } List<string> sqls = new List<string>(); string custId = this.txtCustId.Text.Trim(); string custName = this.txtCustName.Text.Trim(); string payMethod = ""; if (this.comboBoxPayMethod.SelectedIndex != 0) payMethod = this.comboBoxPayMethod.Text.Trim(); string bankAccount = this.txtBankAccount.Text.Trim(); double inMoney = 0.0; if (this.txtInMoney.Text.Trim() != "") inMoney = Convert.ToDouble(this.txtInMoney.Text.Trim()); string pinZhengHao = this.txtPinZhengHao.Text.Trim(); string abstact = this.txtAbstract.Text.Trim(); string record = this.txtRecord.Text.Trim(); string memo = this.txtMemo.Text.Trim(); string financialId = ""; if (this.financialType == "收入") { //产生单据号,并返回更新"T_ReceiptRule"的SQL语句 string SqlUpdateBillRullYS = ""; financialId = DBUtil.Produce_Bill_Id("YS", DBUtil.getServerTime().ToString().Trim(), ref SqlUpdateBillRullYS); //插入账务主表 string strSqlMain = "insert into T_Financial(FinancialId,CurWorkMonth,FinancialType,CustId,CustName,PayMethod,BankAccount,InMoney," + "OccurTime,PinZhengHao,Abstract,Record,OperatePerson,Memo) " + "values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')"; strSqlMain = string.Format(strSqlMain, financialId, this.curWorkMonth, "收入", custId, custName, payMethod, bankAccount, inMoney, DBUtil.getServerTime().ToString().Trim(), pinZhengHao, abstact, record, this.curUserName, memo); sqls.Add(strSqlMain); sqls.Add(SqlUpdateBillRullYS);//更新单据号 } else if (this.financialType == "支出") { //产生单据号,并返回更新"T_ReceiptRule"的SQL语句 string SqlUpdateBillRullYF = ""; financialId = DBUtil.Produce_Bill_Id("YF", DBUtil.getServerTime().ToString().Trim(), ref SqlUpdateBillRullYF); //插入账务主表 string strSqlMain = "insert into T_Financial(FinancialId,CurWorkMonth,FinancialType,CustId,CustName,PayMethod,BankAccount,OutMoney," + "OccurTime,PinZhengHao,Abstract,Record,OperatePerson,Memo) " + "values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')"; strSqlMain = string.Format(strSqlMain, financialId, this.curWorkMonth, "支出", custId, custName, payMethod, bankAccount, inMoney, DBUtil.getServerTime().ToString().Trim(), pinZhengHao, abstact, record, this.curUserName, memo); sqls.Add(strSqlMain); sqls.Add(SqlUpdateBillRullYF);//更新单据号 } //插入账务子表 foreach (DataGridViewRow dgvr in this.dataGridView1.Rows) { if (dgvr.Cells["单据号"].Value == null || dgvr.Cells["单据号"].Value.ToString().Trim() == "") continue; string workMonth = dgvr.Cells["单据工作月"].Value.ToString().Trim(); string receiptId = dgvr.Cells["单据号"].Value.ToString().Trim(); string orderNo = dgvr.Cells["分录号"].Value.ToString().Trim(); double moneyPayed = 0.0; if (dgvr.Cells["实核销金额"].Value != null && dgvr.Cells["实核销金额"].Value.ToString().Trim() != "") moneyPayed = Convert.ToDouble(dgvr.Cells["实核销金额"].Value.ToString().Trim()); string strSqlDet = "insert into T_Financial_Det(FinancialId,workMonth,ReceiptId,OrderNo,MoneyPayed) " + "values('{0}','{1}','{2}','{3}','{4}')"; strSqlDet = string.Format(strSqlDet, financialId, workMonth, receiptId, orderNo, moneyPayed); sqls.Add(strSqlDet); //更新单据子表的MoneyPayed string strSqlUpdate = "update T_Receipts_Det set MoneyPayed = MoneyPayed + {0} where ReceiptId='{1}' and OrderNo='{2}'"; strSqlUpdate = string.Format(strSqlUpdate, moneyPayed, receiptId, orderNo); sqls.Add(strSqlUpdate); } //执行事务处理所有的Sql SqlDBConnect db = new SqlDBConnect(); db.Exec_Tansaction(sqls); MessageBox.Show("保存成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); //保存后,新建一个 if (this.financialType == "收入") { FinancialForm form = new FinancialForm("收入"); form.MdiParent = this.MdiParent as MainForm; form.Show(); } if (this.financialType == "支出") { FinancialForm form = new FinancialForm("支出"); form.MdiParent = this.MdiParent as MainForm; form.Show(); } this.Close(); }
private void 应收账务ToolStripMenuItem_Click(object sender, EventArgs e) { FinancialForm form = new FinancialForm("收入"); form.MdiParent = this; form.Show(); }
private void btnSave_Click(object sender, EventArgs e) { if (this.txtCustId.Text.Trim() == "") { MessageBox.Show("客户代码不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (this.txtInMoney.Text.Trim() != "" && !Util.IsNumberic(this.txtInMoney)) { MessageBox.Show("核销金额只能为数值型数据!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } List <string> sqls = new List <string>(); string custId = this.txtCustId.Text.Trim(); string custName = this.txtCustName.Text.Trim(); string payMethod = ""; if (this.comboBoxPayMethod.SelectedIndex != 0) { payMethod = this.comboBoxPayMethod.Text.Trim(); } string bankAccount = this.txtBankAccount.Text.Trim(); double inMoney = 0.0; if (this.txtInMoney.Text.Trim() != "") { inMoney = Convert.ToDouble(this.txtInMoney.Text.Trim()); } string pinZhengHao = this.txtPinZhengHao.Text.Trim(); string abstact = this.txtAbstract.Text.Trim(); string record = this.txtRecord.Text.Trim(); string memo = this.txtMemo.Text.Trim(); string financialId = ""; if (this.financialType == "收入") { //产生单据号,并返回更新"T_ReceiptRule"的SQL语句 string SqlUpdateBillRullYS = ""; financialId = DBUtil.Produce_Bill_Id("YS", DBUtil.getServerTime().ToString().Trim(), ref SqlUpdateBillRullYS); //插入账务主表 string strSqlMain = "insert into T_Financial(FinancialId,CurWorkMonth,FinancialType,CustId,CustName,PayMethod,BankAccount,InMoney," + "OccurTime,PinZhengHao,Abstract,Record,OperatePerson,Memo) " + "values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')"; strSqlMain = string.Format(strSqlMain, financialId, this.curWorkMonth, "收入", custId, custName, payMethod, bankAccount, inMoney, DBUtil.getServerTime().ToString().Trim(), pinZhengHao, abstact, record, this.curUserName, memo); sqls.Add(strSqlMain); sqls.Add(SqlUpdateBillRullYS);//更新单据号 } else if (this.financialType == "支出") { //产生单据号,并返回更新"T_ReceiptRule"的SQL语句 string SqlUpdateBillRullYF = ""; financialId = DBUtil.Produce_Bill_Id("YF", DBUtil.getServerTime().ToString().Trim(), ref SqlUpdateBillRullYF); //插入账务主表 string strSqlMain = "insert into T_Financial(FinancialId,CurWorkMonth,FinancialType,CustId,CustName,PayMethod,BankAccount,OutMoney," + "OccurTime,PinZhengHao,Abstract,Record,OperatePerson,Memo) " + "values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')"; strSqlMain = string.Format(strSqlMain, financialId, this.curWorkMonth, "支出", custId, custName, payMethod, bankAccount, inMoney, DBUtil.getServerTime().ToString().Trim(), pinZhengHao, abstact, record, this.curUserName, memo); sqls.Add(strSqlMain); sqls.Add(SqlUpdateBillRullYF);//更新单据号 } //插入账务子表 foreach (DataGridViewRow dgvr in this.dataGridView1.Rows) { if (dgvr.Cells["单据号"].Value == null || dgvr.Cells["单据号"].Value.ToString().Trim() == "") { continue; } string workMonth = dgvr.Cells["单据工作月"].Value.ToString().Trim(); string receiptId = dgvr.Cells["单据号"].Value.ToString().Trim(); string orderNo = dgvr.Cells["分录号"].Value.ToString().Trim(); double moneyPayed = 0.0; if (dgvr.Cells["实核销金额"].Value != null && dgvr.Cells["实核销金额"].Value.ToString().Trim() != "") { moneyPayed = Convert.ToDouble(dgvr.Cells["实核销金额"].Value.ToString().Trim()); } string strSqlDet = "insert into T_Financial_Det(FinancialId,workMonth,ReceiptId,OrderNo,MoneyPayed) " + "values('{0}','{1}','{2}','{3}','{4}')"; strSqlDet = string.Format(strSqlDet, financialId, workMonth, receiptId, orderNo, moneyPayed); sqls.Add(strSqlDet); //更新单据子表的MoneyPayed string strSqlUpdate = "update T_Receipts_Det set MoneyPayed = MoneyPayed + {0} where ReceiptId='{1}' and OrderNo='{2}'"; strSqlUpdate = string.Format(strSqlUpdate, moneyPayed, receiptId, orderNo); sqls.Add(strSqlUpdate); } //执行事务处理所有的Sql SqlDBConnect db = new SqlDBConnect(); db.Exec_Tansaction(sqls); MessageBox.Show("保存成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); //保存后,新建一个 if (this.financialType == "收入") { FinancialForm form = new FinancialForm("收入"); form.MdiParent = this.MdiParent as MainForm; form.Show(); } if (this.financialType == "支出") { FinancialForm form = new FinancialForm("支出"); form.MdiParent = this.MdiParent as MainForm; form.Show(); } this.Close(); }