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.
 
 

186 lines
6.1 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 ManagementSystem.Utility;
namespace ManagementSystem
{
public partial class PickAccountingSubject : Form
{
//程式內共用物件
public string strFrmStatus = ""; //表單狀態
public string strPKey = ""; //程式內的Key值
public int intIndex = 0;
public string strOwnerForm = ""; //設定表單的擁有者
public string strAccountingBookID = ""; //取得作用中的帳本
SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID);
SqlCommand sqlCmd = new SqlCommand();
DataSet sdInsurance = new System.Data.DataSet();
public PickAccountingSubject()
{
InitializeComponent();
}
#region 自定義程式
private void SearchEvent(string strAccID,string strAccName)
{
try
{
StringBuilder strSQL = new StringBuilder("");
strSQL.Append("Select AccountingSubID, AccountingSubName ");
strSQL.Append("From OTB_FNC_AccountingSubjects ");
strSQL.Append("Where AccountingBookID ='" + strAccountingBookID + "' ");
if (strAccID != "") //科目代碼
{
strSQL.Append("And AccountingSubID like '" + strAccID + "' ");
}
if (strAccName != "") //身份證字號
{
strSQL.Append("And AccountingSubName like '" + strAccName + "' ");
}
//進行查詢
dgvDataMaintain.DataSource = UtilityClass.GetSQLResult(strSQL.ToString()).Tables[0];
}
catch (Exception ex)
{
ErrorHandler.WriteErrorLog("PickAccountingSubject.cs", ex);
}
}
private void CleanForm()
{
txtAccountingSubID.Text = "";
txtAccountingSubName.Text = "";
}
private void PickItem()
{
try
{
//取得資料
string strReturnItem = "";
string strAccountingSubID = "";
foreach (DataGridViewRow dgvRow in dgvDataMaintain.SelectedRows)
{
strAccountingSubID = (string)dgvRow.Cells["cAccountingSubID"].Value;
if (!string.IsNullOrEmpty(strAccountingSubID))
{
strReturnItem = intIndex.ToString() + "|" + strAccountingSubID + "|" + dgvRow.Cells["cAccountingSubName"].Value.ToString();
}
}
switch(strOwnerForm)
{
case "AccountingEntries":
//回傳資料
AccountingEntries frmParent = (AccountingEntries)this.Owner;
frmParent.ReturnAccountList(strReturnItem);
break;
case "AccountingLedger":
//回傳資料
AccountingLedger frmParent1 = (AccountingLedger)this.Owner;
frmParent1.ReturnAccountList(strReturnItem);
break;
case "XMLSetting":
//回傳資料
XMLSetting frmParent2 = (XMLSetting)this.Owner;
frmParent2.ReturnAccountList(strReturnItem);
break;
}
this.Close();
}
catch (Exception ex)
{
ErrorHandler.WriteErrorLog("PickAccountingSubject.cs", ex);
}
}
#endregion
#region 事件觸發及問題處理
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnPick_Click(object sender, EventArgs e)
{
PickItem();
}
private void btnClean_Click(object sender, EventArgs e)
{
CleanForm();
string strAccID = txtAccountingSubID.Text.Trim();
string strAccName = txtAccountingSubName.Text.Trim();
SearchEvent(strAccID, strAccName);
}
private void PickAccountingSubject_Load(object sender, EventArgs e)
{
string strAccID = txtAccountingSubID.Text.Trim();
string strAccName = txtAccountingSubName.Text.Trim();
SearchEvent(strAccID, strAccName);
}
private void btnSearch_Click(object sender, EventArgs e)
{
string strAccID = txtAccountingSubID.Text.Trim();
string strAccName = txtAccountingSubName.Text.Trim();
SearchEvent(strAccID, strAccName);
}
private void dgvDataMaintain_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
PickItem();
}
private void txtAccountingSubID_TextChanged(object sender, EventArgs e)
{
string strAccID = txtAccountingSubID.Text.Trim();
string strAccName = txtAccountingSubName.Text.Trim();
strAccID = string.IsNullOrEmpty(strAccID) ? "" : strAccID + "%";
strAccName = string.IsNullOrEmpty(strAccName) ? "" : "%" + strAccName + "%";
SearchEvent(strAccID, strAccName);
}
private void txtAccountingSubName_TextChanged(object sender, EventArgs e)
{
string strAccID = txtAccountingSubID.Text.Trim();
string strAccName = txtAccountingSubName.Text.Trim();
strAccID = string.IsNullOrEmpty(strAccID) ? "" : strAccID + "%";
strAccName = string.IsNullOrEmpty(strAccName) ? "" : "%" + strAccName + "%";
SearchEvent(strAccID, strAccName);
}
#endregion
}
}