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.
|
|
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 PickProject : Form { //程式內共用物件
public string strFrmStatus = ""; //表單狀態
public string strPKey = ""; //程式內的Key值
public string strOwnerForm = ""; //設定表單的擁有者
public int intIndex = 0; //設定被觸發的Grid筆數
SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID); SqlCommand sqlCmd = new SqlCommand(); DataSet sdInsurance = new System.Data.DataSet();
public PickProject() { InitializeComponent(); }
#region 自定義程式
private void SearchEvent(string strProjectNumber, string strProjectName) { try { StringBuilder strSQL = new StringBuilder(""); strSQL.Append("Select ProjectNumber, ProjectCName "); strSQL.Append("From OTB_PRJ_ProjectInfo "); strSQL.Append("Where 1 = 1 "); if (strProjectNumber != "") //專案編號
{ strSQL.Append("And ProjectNumber like '" + strProjectNumber + "' "); } if (strProjectName != "") //專案名稱
{ strSQL.Append("And ProjectCName like '" + strProjectName + "' "); }
if (cbClosed.Checked) { strSQL.Append("Union "); strSQL.Append("Select ProjectNumber, ProjectCName "); strSQL.Append("From OTB_PRJ_ProjectInfo_Closed "); strSQL.Append("Where 1 = 1 "); if (strProjectNumber != "") //專案編號
{ strSQL.Append("And ProjectNumber like '" + strProjectNumber + "' "); } if (strProjectName != "") //專案名稱
{ strSQL.Append("And ProjectCName like '" + strProjectName + "' "); } } //進行查詢
dgvDataMaintain.DataSource = UtilityClass.GetSQLResult(strSQL.ToString()).Tables[0];
} catch (Exception ex) { ErrorHandler.WriteErrorLog("PickProject.cs", ex); } }
private void CleanForm() { txtProjectName.Text = ""; txtProjectNumber.Text = ""; cbClosed.Checked = false; }
private void PickItem() //取得資料
{ try { string strReturnItem = ""; string strProjectID = ""; foreach (DataGridViewRow dgvRow in dgvDataMaintain.SelectedRows) { strProjectID = (string)dgvRow.Cells["cProjectID"].Value; if (!string.IsNullOrEmpty(strProjectID)) { strReturnItem = strProjectID + "|" + dgvRow.Cells["cProjectName"].Value.ToString(); } }
switch (strOwnerForm) { case "AccountingEntries_Header": AccountingEntries frmParent = (AccountingEntries)this.Owner; frmParent.ReturnProjectInfo(strReturnItem.Split('|')); break;
case "AccountingEntries_Detail": AccountingEntries frmParent1 = (AccountingEntries)this.Owner; frmParent1.ReturnProjectInfo(intIndex, strReturnItem.Split('|')); break;
case "ProjectIncomeStatement": ProjectIncomeStatement frmParent2 = (ProjectIncomeStatement)this.Owner; frmParent2.ReturnProjectInfo(strReturnItem.Split('|')); break;
case "CashFlowForecastEdit": CashFlowForecastEdit frmParent3 = (CashFlowForecastEdit)this.Owner; frmParent3.ReturnProjectInfo(strReturnItem.Split('|')); break; case "HRDataCorrect": HRDataCorrect frmParent4 = (HRDataCorrect)this.Owner; frmParent4.ReturnProjectInfo(strReturnItem.Split('|')); break; } this.Close(); } catch (Exception ex) { ErrorHandler.WriteErrorLog("PickProject.cs", ex); } } #endregion
#region 事件觸發及問題處理
private void btnClose_Click(object sender, EventArgs e) { this.Close(); }
private void btnClean_Click(object sender, EventArgs e) { CleanForm(); string strProjectNumber = txtProjectNumber.Text.Trim(); string strProjectName = txtProjectName.Text.Trim(); SearchEvent(strProjectNumber, strProjectName); }
private void btnSearch_Click(object sender, EventArgs e) { string strProjectNumber = txtProjectNumber.Text.Trim(); string strProjectName = txtProjectName.Text.Trim(); SearchEvent(strProjectNumber, strProjectName); }
private void txtProjectNumber_TextChanged(object sender, EventArgs e) { string strProjuectNumber = txtProjectNumber.Text.Trim(); string strProjectName = txtProjectName.Text.Trim();
strProjuectNumber = string.IsNullOrEmpty(strProjuectNumber) ? "" : strProjuectNumber + "%"; strProjectName = string.IsNullOrEmpty(strProjectName) ? "" : "%" + strProjectName + "%"; SearchEvent(strProjuectNumber, strProjectName); }
private void txtProjectName_TextChanged(object sender, EventArgs e) { string strProjuectNumber = txtProjectNumber.Text.Trim(); string strProjectName = txtProjectName.Text.Trim();
strProjuectNumber = string.IsNullOrEmpty(strProjuectNumber) ? "" : strProjuectNumber + "%"; strProjectName = string.IsNullOrEmpty(strProjectName) ? "" : "%" + strProjectName + "%"; SearchEvent(strProjuectNumber, strProjectName); }
private void btnPick_Click(object sender, EventArgs e) { PickItem(); }
private void dgvDataMaintain_DoubleClick(object sender, EventArgs e) { PickItem(); }
private void PickProject_Load(object sender, EventArgs e) { SearchEvent("", ""); }
private void cbClosed_CheckedChanged(object sender, EventArgs e) { string strProjectNumber = txtProjectNumber.Text.Trim(); string strProjectName = txtProjectName.Text.Trim(); SearchEvent(strProjectNumber, strProjectName); }
#endregion
} }
|