You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
442 lines
21 KiB
442 lines
21 KiB
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.IO;
|
|
using System.Xml.Linq;
|
|
using ManagementSystem.Utility;
|
|
|
|
namespace ManagementSystem
|
|
{
|
|
public partial class IncomeStatement : Form
|
|
{
|
|
//程式內共用物件
|
|
string strFrmStatus = ""; //表單狀態
|
|
string strActiveUserID = ""; //取得登入作用的使用者帳號
|
|
string strAccountingBookID = ""; //取得作用中的帳本
|
|
SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID);
|
|
SqlCommand sqlCmd = new SqlCommand();
|
|
DataSet sdInsurance = new System.Data.DataSet();
|
|
string strKey = ""; //程式內加密的Key值
|
|
string strTaxAccountingID = ""; //所得稅科目ID
|
|
|
|
public IncomeStatement()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region 自定義程式
|
|
public void StatusChange(string strStatus) //變更主畫面狀態
|
|
{
|
|
switch (strStatus.ToUpper())
|
|
{
|
|
case "NONE":
|
|
CleanForm();
|
|
CleanToolbar();
|
|
LockForm();
|
|
((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "";
|
|
strFrmStatus = "";
|
|
tsbSearch.Enabled = true;
|
|
break;
|
|
case "SEARCH":
|
|
UnLockForm();
|
|
Application.DoEvents();
|
|
tsbSearch.Enabled = false;
|
|
tsbOK.Visible = true;
|
|
tsbCancel.Visible = true;
|
|
((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "搜尋";
|
|
strFrmStatus = "SEARCH";
|
|
break;
|
|
case "ADD":
|
|
//本功能不提供新增
|
|
((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "新增";
|
|
strFrmStatus = "ADD";
|
|
break;
|
|
case "MODIFY":
|
|
//本功能不提供修改
|
|
((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "修改";
|
|
strFrmStatus = "MODIFY";
|
|
break;
|
|
case "DEL":
|
|
//本功能不提供刪除
|
|
((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "刪除";
|
|
strFrmStatus = "DEL";
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void CleanForm()
|
|
{
|
|
dpAccStart.Text = dpAccStart.Text = DateTime.Now.Year.ToString() + "/1/1";
|
|
dpAccEnd.Text = DateTime.Now.ToShortDateString();
|
|
lbExpense.Text = "";
|
|
lbIncome.Text = "";
|
|
lbNetAfterTax.Text = "";
|
|
crNet.Series["Series1"].Points.Clear();
|
|
crIncomeList.Series["Series1"].Points.Clear();
|
|
crExpendList.Series["Series1"].Points.Clear();
|
|
dgvExpense.Rows.Clear();
|
|
dgvIncome.Rows.Clear();
|
|
tbCharts.SelectedTab = tabNet;
|
|
}
|
|
|
|
private void CleanToolbar()
|
|
{
|
|
tsbSearch.Enabled = true;
|
|
tsbClean.Enabled = true;
|
|
tsbExit.Enabled = true;
|
|
tsbOK.Visible = false;
|
|
tsbCancel.Visible = false;
|
|
}
|
|
|
|
private void LockForm()
|
|
{
|
|
dpAccEnd.Enabled = false;
|
|
dpAccStart.Enabled = false;
|
|
}
|
|
|
|
private void UnLockForm()
|
|
{
|
|
dpAccEnd.Enabled = true;
|
|
dpAccStart.Enabled = true;
|
|
}
|
|
|
|
private void IncomeCount() //計算收入總額
|
|
{
|
|
StringBuilder sbSQL = new StringBuilder();
|
|
string strAccountingSubID = "";
|
|
string strAccountingSubName = "";
|
|
string strAccountingAmount = "0";
|
|
string strCredit = "";
|
|
string strDebit = "";
|
|
string strIncomeCount = "0";
|
|
try
|
|
{
|
|
sbSQL.Append(" Select J.AccountingBookID, J.AccountingID, J.AccountingDate, J.AccountingSubID, J.AccountingSubName,J.Debit, J.Credit, A.DCClass ");
|
|
sbSQL.Append(" From OTB_FNC_AccountingJournal J, OTB_FNC_AccountingSubjects A ");
|
|
sbSQL.Append(" Where J.AccountingSubID = A.AccountingSubID And A.AccountingBookID = '" + strAccountingBookID + "'");
|
|
sbSQL.Append(" And ISNULL(J.ClosedAccounting,'N') != 'Y'");
|
|
sbSQL.Append(" And J.AccountingBookID ='" + strAccountingBookID + "' ");
|
|
sbSQL.Append(" And J.AccountingDate Between '" + dpAccStart.Text + " 00:00:00' And '" + dpAccEnd.Text + " 23:59:59' ");
|
|
sbSQL.Append(" And J.AccountingSubID IN (Select AccountingSubID From OTB_FNC_AccountingSubjects Where AccountingBookID = '" + strAccountingBookID + "' And AccountingClass = 'I') ");
|
|
sbSQL.Append(" Order by J.AccountingSubID ");
|
|
|
|
using (DataTable dtTemp = UtilityClass.GetSQLResult(sbSQL.ToString()).Tables["Result"])
|
|
{
|
|
if (dtTemp.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow drIncomeData in dtTemp.Rows)
|
|
{
|
|
if (strAccountingSubID == drIncomeData["AccountingSubID"].ToString())
|
|
{
|
|
strCredit = string.IsNullOrEmpty(drIncomeData["Credit"].ToString()) ? "0" : UtilityClass.DecryptDES(drIncomeData["Credit"].ToString(),strKey).Replace(",", "");
|
|
strDebit = string.IsNullOrEmpty(drIncomeData["Debit"].ToString()) ? "0" : UtilityClass.DecryptDES(drIncomeData["Debit"].ToString(), strKey).Replace(",", "");
|
|
if (drIncomeData["DCClass"].ToString() == "C")
|
|
{
|
|
strAccountingAmount = (Convert.ToInt32(strAccountingAmount) + Convert.ToInt32(strCredit) - Convert.ToInt32(strDebit)).ToString();
|
|
}
|
|
else
|
|
{
|
|
strAccountingAmount = (Convert.ToInt32(strAccountingAmount) - Convert.ToInt32(strCredit) + Convert.ToInt32(strDebit)).ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(strAccountingSubID) && strAccountingAmount != "0")
|
|
{
|
|
DataGridViewRow dgvRow = new DataGridViewRow();
|
|
dgvRow.CreateCells(dgvIncome);
|
|
dgvRow.Cells[0].Value = strAccountingSubID; //科目代號
|
|
dgvRow.Cells[1].Value = strAccountingSubName; //科目名稱
|
|
dgvRow.Cells[2].Value = UtilityClass.MarkNumber(strAccountingAmount); //金額
|
|
dgvIncome.Rows.Add(dgvRow);
|
|
strIncomeCount = (Convert.ToInt32(strIncomeCount) + Convert.ToInt32(strAccountingAmount)).ToString();
|
|
strAccountingAmount = "0";
|
|
}
|
|
|
|
//清空數值
|
|
strAccountingSubID = drIncomeData["AccountingSubID"].ToString();
|
|
strAccountingSubName = drIncomeData["AccountingSubName"].ToString();
|
|
strCredit = string.IsNullOrEmpty(drIncomeData["Credit"].ToString()) ? "0" : UtilityClass.DecryptDES(drIncomeData["Credit"].ToString(), strKey).Replace(",", "");
|
|
strDebit = string.IsNullOrEmpty(drIncomeData["Debit"].ToString()) ? "0" : UtilityClass.DecryptDES(drIncomeData["Debit"].ToString(), strKey).Replace(",", "");
|
|
if (drIncomeData["DCClass"].ToString() == "C")
|
|
{
|
|
strAccountingAmount = (Convert.ToInt32(strAccountingAmount) + Convert.ToInt32(strCredit) - Convert.ToInt32(strDebit)).ToString();
|
|
}
|
|
else
|
|
{
|
|
strAccountingAmount = (Convert.ToInt32(strAccountingAmount) - Convert.ToInt32(strCredit) + Convert.ToInt32(strDebit)).ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(strAccountingSubID) && strAccountingAmount != "0")
|
|
{
|
|
DataGridViewRow dgvRow = new DataGridViewRow();
|
|
dgvRow.CreateCells(dgvIncome);
|
|
dgvRow.Cells[0].Value = strAccountingSubID; //科目代號
|
|
dgvRow.Cells[1].Value = strAccountingSubName; //科目名稱
|
|
dgvRow.Cells[2].Value = UtilityClass.MarkNumber(strAccountingAmount); //金額
|
|
dgvIncome.Rows.Add(dgvRow);
|
|
strIncomeCount = (Convert.ToInt32(strIncomeCount) + Convert.ToInt32(strAccountingAmount)).ToString();
|
|
}
|
|
}
|
|
lbIncome.Text = UtilityClass.MarkNumber(strIncomeCount);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorHandler.WriteErrorLog("IncomeStatement.cs", ex);
|
|
}
|
|
}
|
|
|
|
private void ExpenseCount() //計算費用總額
|
|
{
|
|
StringBuilder sbSQL = new StringBuilder();
|
|
string strAccountingSubID = "";
|
|
string strAccountingSubName = "";
|
|
string strAccountingAmount = "0";
|
|
string strCredit = "";
|
|
string strDebit = "";
|
|
string strExpenseCount = "0";
|
|
try
|
|
{
|
|
sbSQL.Append(" Select J.AccountingBookID, J.AccountingID, J.AccountingDate, J.AccountingSubID, J.AccountingSubName,J.Debit, J.Credit, A.DCClass ");
|
|
sbSQL.Append(" From OTB_FNC_AccountingJournal J, OTB_FNC_AccountingSubjects A ");
|
|
sbSQL.Append(" Where J.AccountingSubID = A.AccountingSubID And A.AccountingBookID = '" + strAccountingBookID + "'");
|
|
sbSQL.Append(" And ISNULL(J.ClosedAccounting,'N') != 'Y'");
|
|
sbSQL.Append(" And J.AccountingBookID ='" + strAccountingBookID + "' ");
|
|
sbSQL.Append(" And J.AccountingDate Between '" + dpAccStart.Text + " 00:00:00' And '" + dpAccEnd.Text + " 23:59:59' ");
|
|
sbSQL.Append(" And J.AccountingSubID IN (Select AccountingSubID From OTB_FNC_AccountingSubjects Where AccountingBookID = '" + strAccountingBookID + "' And AccountingClass = 'E') ");
|
|
sbSQL.Append(" Order by J.AccountingSubID ");
|
|
|
|
using (DataTable dtTemp = UtilityClass.GetSQLResult(sbSQL.ToString()).Tables["Result"])
|
|
{
|
|
if (dtTemp.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow drExpenseData in dtTemp.Rows)
|
|
{
|
|
if (strAccountingSubID == drExpenseData["AccountingSubID"].ToString())
|
|
{
|
|
strCredit = string.IsNullOrEmpty(drExpenseData["Credit"].ToString()) ? "0" : UtilityClass.DecryptDES(drExpenseData["Credit"].ToString(), strKey).Replace(",", "");
|
|
strDebit = string.IsNullOrEmpty(drExpenseData["Debit"].ToString()) ? "0" : UtilityClass.DecryptDES(drExpenseData["Debit"].ToString(), strKey).Replace(",", "");
|
|
if (drExpenseData["DCClass"].ToString() == "D")
|
|
{
|
|
strAccountingAmount = (Convert.ToInt32(strAccountingAmount) - Convert.ToInt32(strCredit) + Convert.ToInt32(strDebit)).ToString();
|
|
}
|
|
else
|
|
{
|
|
strAccountingAmount = (Convert.ToInt32(strAccountingAmount) + Convert.ToInt32(strCredit) - Convert.ToInt32(strDebit)).ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(strAccountingSubID) && strAccountingAmount != "0")
|
|
{
|
|
DataGridViewRow dgvRow = new DataGridViewRow();
|
|
dgvRow.CreateCells(dgvExpense);
|
|
dgvRow.Cells[0].Value = strAccountingSubID; //科目代號
|
|
dgvRow.Cells[1].Value = strAccountingSubName; //科目名稱
|
|
dgvRow.Cells[2].Value = UtilityClass.MarkNumber(strAccountingAmount); //金額
|
|
dgvExpense.Rows.Add(dgvRow);
|
|
strExpenseCount = (Convert.ToInt32(strExpenseCount) + Convert.ToInt32(strAccountingAmount)).ToString();
|
|
strAccountingAmount = "0";
|
|
}
|
|
|
|
//清空數值
|
|
strAccountingSubID = drExpenseData["AccountingSubID"].ToString();
|
|
strAccountingSubName = drExpenseData["AccountingSubName"].ToString();
|
|
strCredit = string.IsNullOrEmpty(drExpenseData["Credit"].ToString()) ? "0" : UtilityClass.DecryptDES(drExpenseData["Credit"].ToString(), strKey).Replace(",", "");
|
|
strDebit = string.IsNullOrEmpty(drExpenseData["Debit"].ToString()) ? "0" : UtilityClass.DecryptDES(drExpenseData["Debit"].ToString(), strKey).Replace(",", "");
|
|
if (drExpenseData["DCClass"].ToString() == "D")
|
|
{
|
|
strAccountingAmount = (Convert.ToInt32(strAccountingAmount) - Convert.ToInt32(strCredit) + Convert.ToInt32(strDebit)).ToString();
|
|
}
|
|
else
|
|
{
|
|
strAccountingAmount = (Convert.ToInt32(strAccountingAmount) + Convert.ToInt32(strCredit) - Convert.ToInt32(strDebit)).ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(strAccountingSubID) && strAccountingAmount != "0")
|
|
{
|
|
DataGridViewRow dgvRow = new DataGridViewRow();
|
|
dgvRow.CreateCells(dgvExpense);
|
|
dgvRow.Cells[0].Value = strAccountingSubID; //科目代號
|
|
dgvRow.Cells[1].Value = strAccountingSubName; //科目名稱
|
|
dgvRow.Cells[2].Value = UtilityClass.MarkNumber(strAccountingAmount); //金額
|
|
dgvExpense.Rows.Add(dgvRow);
|
|
strExpenseCount = (Convert.ToInt32(strExpenseCount) + Convert.ToInt32(strAccountingAmount)).ToString();
|
|
}
|
|
}
|
|
lbExpense.Text = UtilityClass.MarkNumber(strExpenseCount);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorHandler.WriteErrorLog("IncomeStatement.cs", ex);
|
|
}
|
|
}
|
|
|
|
private void GoEvent()
|
|
{
|
|
IncomeCount();
|
|
ExpenseCount();
|
|
UtilityClass.SetGridColor(dgvIncome);
|
|
UtilityClass.SetGridColor(dgvExpense);
|
|
|
|
//計算稅前淨利
|
|
string strIncome = lbIncome.Text.ToString();
|
|
string strExpenxe = lbExpense.Text.ToString();
|
|
strIncome = string.IsNullOrEmpty(strIncome) ? "0" : strIncome.Replace(",", "");
|
|
strExpenxe = string.IsNullOrEmpty(strExpenxe) ? "0" : strExpenxe.Replace(",", "");
|
|
lbNetAfterTax.Text = UtilityClass.MarkNumber(Convert.ToInt32(strIncome) - Convert.ToInt32(strExpenxe));
|
|
ShowIncomeExpendChar();
|
|
ShowIncomeListChar();
|
|
ShowExpendListChar();
|
|
}
|
|
|
|
private void ShowIncomeExpendChar()
|
|
{
|
|
string[] strItems = {"收入總計", "費用總計" };
|
|
int[] intValues = { Convert.ToInt32(lbIncome.Text.Replace(",","")), Convert.ToInt32(lbExpense.Text.Replace(",","")) };
|
|
crNet.Series["Series1"]["PieLabelStyle"] = "Inside";
|
|
crNet.Series["Series1"].Points.DataBindXY(strItems, intValues);
|
|
crNet.Series["Series1"].IsValueShownAsLabel = true;
|
|
}
|
|
|
|
private void ShowIncomeListChar()
|
|
{
|
|
string[] strItems = new string[dgvIncome.Rows.Count];
|
|
int[] intValues = new int[dgvIncome.Rows.Count];
|
|
for (int intCount = 0; intCount < dgvIncome.Rows.Count; intCount++ )
|
|
{
|
|
strItems[intCount] = dgvIncome.Rows[intCount].Cells["cInAccountingSubject"].Value.ToString();
|
|
intValues[intCount] = Convert.ToInt32(dgvIncome.Rows[intCount].Cells["cInAccountingAmount"].Value.ToString().Replace(",",""));
|
|
}
|
|
crIncomeList.Series["Series1"].Points.DataBindXY(strItems, intValues);
|
|
crIncomeList.Series["Series1"].IsValueShownAsLabel = true;
|
|
}
|
|
|
|
private void ShowExpendListChar()
|
|
{
|
|
string[] strItems = new string[dgvExpense.Rows.Count];
|
|
int[] intValues = new int[dgvExpense.Rows.Count];
|
|
for (int intCount = 0; intCount < dgvExpense.Rows.Count; intCount++)
|
|
{
|
|
strItems[intCount] = dgvExpense.Rows[intCount].Cells["cExAccountingSubject"].Value.ToString();
|
|
intValues[intCount] = Convert.ToInt32(dgvExpense.Rows[intCount].Cells["cExAccountingAmount"].Value.ToString().Replace(",", ""));
|
|
}
|
|
crExpendList.Series["Series1"].Points.DataBindXY(strItems, intValues);
|
|
crExpendList.Series["Series1"].IsValueShownAsLabel = true;
|
|
}
|
|
#endregion
|
|
|
|
#region 事件觸發及問題處理
|
|
private void IncomeStatement_Load(object sender, EventArgs e)//畫面載入設定
|
|
{
|
|
try
|
|
{
|
|
strActiveUserID = MainForm.strActiveUserID;
|
|
strAccountingBookID = MainForm.strAccountingBookID;
|
|
strKey = MainForm.strKey;
|
|
string strXMLPath = ConfigurationManager.AppSettings["XMLFilePath"].ToString() + this.Name.ToString() + ".xml";
|
|
string strDC = "";
|
|
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":
|
|
strTaxAccountingID = xmlData.Element("SubAccounting").Value.ToString();
|
|
break;
|
|
case "C":
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
if (MainForm.strKey == "")
|
|
{
|
|
//設定Toolbar初始狀態
|
|
tsbSearch.Enabled = false;
|
|
}
|
|
|
|
//設定畫面初始狀態
|
|
StatusChange("NONE");
|
|
GoEvent();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorHandler.WriteErrorLog("IncomeStatement.cs", ex);
|
|
}
|
|
}
|
|
|
|
private void tsbSearch_Click(object sender, EventArgs e)
|
|
{
|
|
CleanForm();
|
|
tsbSearch.Visible = false;
|
|
tsbOK.Visible = true;
|
|
tsbCancel.Visible = true;
|
|
dpAccStart.Enabled = true;
|
|
dpAccEnd.Enabled = true;
|
|
|
|
}
|
|
|
|
private void tsbCancel_Click(object sender, EventArgs e)
|
|
{
|
|
tsbSearch.Visible = true;
|
|
tsbOK.Visible = false;
|
|
tsbCancel.Visible = false;
|
|
LockForm();
|
|
}
|
|
|
|
private void tsbOK_Click(object sender, EventArgs e)
|
|
{
|
|
GoEvent();
|
|
tsbSearch.Visible = true;
|
|
tsbOK.Visible = false;
|
|
tsbCancel.Visible = false;
|
|
LockForm();
|
|
}
|
|
|
|
private void tsbExit_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void tsbSetup_Click(object sender, EventArgs e)
|
|
{
|
|
XMLSetting frmSettingForm = new XMLSetting();
|
|
frmSettingForm.Owner = this;
|
|
frmSettingForm.strOwnerForm = this.Name.ToString();
|
|
frmSettingForm.strXMLName = this.Name.ToString();
|
|
frmSettingForm.StartPosition = FormStartPosition.CenterParent;
|
|
frmSettingForm.ShowDialog();
|
|
}
|
|
|
|
private void tsbClean_Click(object sender, EventArgs e)
|
|
{
|
|
CleanForm();
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|