using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.Common; using Wellan.Data; using Wellan.Common; using System.Text; using System.IO; using System.Drawing; /// /// 人員薪資調整項目處理 /// public partial class forms_worker_fmRsaj : Wellan.Web.UI.WUserControlBase { protected DateTime _YYMM; protected string _RSENO = ""; protected string _RSPYN = ""; private TextBox[] RSYMMs = new TextBox[10]; private DropDownList[] RSENOs = new DropDownList[10]; private TextBox[] RSAMTs = new TextBox[10]; private TextBox[] RSDOCs = new TextBox[10]; private DateTime[] RSYMMValues = new DateTime[10]; private int[] RSAMTValues = new int[10]; protected void Page_Load(object sender, EventArgs e) { _RSENO = GetStringViewState("RSENO"); _RSPYN = GetStringViewState("RSPYN"); _YYMM = GetDateTimeViewState("YYMM"); //if (IsPostBack) // RSAJGrid.DataBind(); } protected override void OnInit(EventArgs e) { base.OnInit(e); dsRSAJForm.ConnectionString = ConnectionString; dsRSAJ_RSENO.ConnectionString = ConnectionString; dsRSAJ_RSENO.SelectCommand = @"IF @RSPYN = '-ALL-' BEGIN SELECT DISTINCT A.BPENO, A.BPENO + ' ' + A.BPNME BPNME FROM BPSNView A INNER JOIN RASN B ON A.BPENO=B.RANUM ORDER BY A.BPENO END ELSE IF @RSPYN<>'000000001' BEGIN SELECT DISTINCT A.BPENO, A.BPENO + ' ' + A.BPNME BPNME FROM BPSNView A INNER JOIN RASN B ON A.BPENO=B.RANUM WHERE B.RAPYN=@RSPYN ORDER BY A.BPENO END ELSE BEGIN SELECT DISTINCT BPENO, BPENO + ' ' + BPNME BPNME, BPSDY, BPEDY FROM BPSNView WHERE ( (BPSDY <= @YYMM1 AND BPEDY >= @YYMM2) OR (BPSDY <= @YYMM1 AND BPEDY IS NULL) OR (BPSDY <= @YYMM1 AND BPEDY >= @YYMM1 AND BPEDY <= @YYMM2) OR (BPSDY >= @YYMM1 AND BPSDY <= @YYMM2 AND BPEDY >= @YYMM2) OR (BPSDY >= @YYMM1 AND BPSDY <= @YYMM2 AND BPEDY IS NULL) OR (BPSDY >= @YYMM1 AND BPSDY <= @YYMM2 AND BPEDY >= @YYMM1 AND BPEDY <= @YYMM2)) AND BPENO NOT IN (SELECT RANUM FROM RASN WHERE ( (RASDT <= @YYMM3 AND RAEDT >= @YYMM4) OR (RASDT <= @YYMM3 AND RAEDT IS NULL) OR (RASDT <= @YYMM3 AND RAEDT >= @YYMM3 AND RAEDT <= @YYMM4) OR (RASDT >= @YYMM3 AND RASDT <= @YYMM4 AND RAEDT >= @YYMM4) OR (RASDT >= @YYMM3 AND RASDT <= @YYMM4 AND RAEDT IS NULL) OR (RASDT >= @YYMM3 AND RASDT <= @YYMM4 AND RAEDT >= @YYMM3 AND RAEDT <= @YYMM4))) ORDER BY BPENO END"; ListItem item = ddlRSPYN.Items.FindByValue(_RSPYN); if (item != null) item.Selected = true; SetClientFocus(txtYYMM); MultiView1.Visible = _RSPYN != ""; GetRsenoDropDownData(); RSYMMs[0] = txtRSAJ_RSYMM_01; RSYMMs[1] = txtRSAJ_RSYMM_02; RSYMMs[2] = txtRSAJ_RSYMM_03; RSYMMs[3] = txtRSAJ_RSYMM_04; RSYMMs[4] = txtRSAJ_RSYMM_05; RSYMMs[5] = txtRSAJ_RSYMM_06; RSYMMs[6] = txtRSAJ_RSYMM_07; RSYMMs[7] = txtRSAJ_RSYMM_08; RSYMMs[8] = txtRSAJ_RSYMM_09; RSYMMs[9] = txtRSAJ_RSYMM_10; RSENOs[0] = ddlRSAJ_RSENO_01; RSENOs[1] = ddlRSAJ_RSENO_02; RSENOs[2] = ddlRSAJ_RSENO_03; RSENOs[3] = ddlRSAJ_RSENO_04; RSENOs[4] = ddlRSAJ_RSENO_05; RSENOs[5] = ddlRSAJ_RSENO_06; RSENOs[6] = ddlRSAJ_RSENO_07; RSENOs[7] = ddlRSAJ_RSENO_08; RSENOs[8] = ddlRSAJ_RSENO_09; RSENOs[9] = ddlRSAJ_RSENO_10; RSAMTs[0] = txtRSAJ_RSAMT_01; RSAMTs[1] = txtRSAJ_RSAMT_02; RSAMTs[2] = txtRSAJ_RSAMT_03; RSAMTs[3] = txtRSAJ_RSAMT_04; RSAMTs[4] = txtRSAJ_RSAMT_05; RSAMTs[5] = txtRSAJ_RSAMT_06; RSAMTs[6] = txtRSAJ_RSAMT_07; RSAMTs[7] = txtRSAJ_RSAMT_08; RSAMTs[8] = txtRSAJ_RSAMT_09; RSAMTs[9] = txtRSAJ_RSAMT_10; RSDOCs[0] = txtRSAJ_RSDOC_01; RSDOCs[1] = txtRSAJ_RSDOC_02; RSDOCs[2] = txtRSAJ_RSDOC_03; RSDOCs[3] = txtRSAJ_RSDOC_04; RSDOCs[4] = txtRSAJ_RSDOC_05; RSDOCs[5] = txtRSAJ_RSDOC_06; RSDOCs[6] = txtRSAJ_RSDOC_07; RSDOCs[7] = txtRSAJ_RSDOC_08; RSDOCs[8] = txtRSAJ_RSDOC_09; RSDOCs[9] = txtRSAJ_RSDOC_10; StringBuilder sb1 = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); StringBuilder sb3 = new StringBuilder(); for (int i = 0; i < 10; i++) { sb1.Append(String.Format("\"{0}\"", RSYMMs[i].ClientID) + (i < 9 ? "," : "")); sb2.Append(String.Format("\"{0}\"", RSAMTs[i].ClientID) + (i < 9 ? "," : "")); sb3.Append(String.Format("\"{0}\"", RSDOCs[i].ClientID) + (i < 9 ? "," : "")); } Page.ClientScript.RegisterArrayDeclaration("RSYMMIds", sb1.ToString()); Page.ClientScript.RegisterArrayDeclaration("RSAMTIds", sb2.ToString()); Page.ClientScript.RegisterArrayDeclaration("RSDOCIds", sb3.ToString()); GetGridViewRowColor(RSAJGrid); switch (MultiView1.ActiveViewIndex) { case 1: SetClientFocus(txtRSAJ_RSYMM_01); Search(); break; case 2: Search(); break; } } // 查詢按鈕 protected void btnSearch_Click(object sender, EventArgs e) { ViewState["RSENO"] = txtRSENO.Text; _RSENO = txtRSENO.Text; if (_RSENO.Length == 0) { lbMessage.Text = GetString("NOSRHCOND"); lbMessage.Visible = true; } else { MultiView1.ActiveViewIndex = 1; Search(); RSAJGrid.PageIndex = 0; RSAJGrid.SelectedIndex = 0; RSAJGrid.DataBind(); } } // 取消查詢按鈕 protected void btnCancel_Click(object sender, EventArgs e) { ViewState.Remove("RSENO"); Search(); MultiView1.ActiveViewIndex = 1; } // 查詢動作 private new void Search() { dsRSAJGrid.SelectParameters["RSENO"].DefaultValue = _RSENO; dsRSAJGrid.SelectParameters["RSPYN"].DefaultValue = _RSPYN; } // 存檔前的計算動作 private new void CalcFields(SqlDataSourceCommandEventArgs e) { } protected void dsRSAJForm_Inserting(object sender, SqlDataSourceCommandEventArgs e) { CalcFields(e); } protected void dsRSAJForm_Updating(object sender, SqlDataSourceCommandEventArgs e) { CalcFields(e); } protected void RSAJGrid_DataBound(object sender, EventArgs e) { GridView_DataBound(sender, e); if (RSAJGrid.Rows.Count > 0) { RSAJGrid.Visible = true; if (RSAJGrid.SelectedIndex == -1) RSAJGrid.SelectedIndex = 0; if (RSAJGrid.SelectedIndex > RSAJGrid.Rows.Count - 1) RSAJGrid.SelectedIndex = RSAJGrid.Rows.Count - 1; //if (RSAJGrid.SelectedIndex != -1) //{ // dsRSAJ_RSENO.SelectParameters["RSPYN"].DefaultValue = RSAJGrid.SelectedDataKey["RSPYN"].ToString(); //} RSAJForm.DataBind(); } } protected void RSAJGrid_PageIndexChanged(object sender, EventArgs e) { Search(); RSAJGrid.SelectedIndex = 0; RSAJGrid.DataBind(); } protected void dsRSAJGrid_Selected(object sender, ObjectDataSourceStatusEventArgs e) { if (e.ReturnValue is Int32 && WDAC.GetInt32Value(e.ReturnValue) == 0) { /* if (ForwardSource != "") RSAJForm.ChangeMode(FormViewMode.Insert); else { MultiView1.ActiveViewIndex = 0; lbMessage.Text = GetString("NODATA"); lbMessage.Visible = true; } */ } } protected void RSAJForm_ItemCommand(object sender, FormViewCommandEventArgs e) { switch (e.CommandName) { case "APPEND": MultiView1.ActiveViewIndex = 1; GetRsenoDropDownData(); break; case "Search": MultiView1.ActiveViewIndex = 0; break; case "Cancel": Search(); break; } } private void GetRsenoDropDownData() { if (_YYMM.Ticks != 0) { if (string.IsNullOrEmpty(_RSPYN)) { dsRSAJ_RSENO.SelectParameters["RSPYN"].DefaultValue = "-ALL-"; } else { dsRSAJ_RSENO.SelectParameters["RSPYN"].DefaultValue = _RSPYN; } dsRSAJ_RSENO.SelectParameters["YYMM1"].DefaultValue = WGuard1.GetMonthBegin(_YYMM, -1).ToString("yyyy/MM/dd", WGuard1.InvariantCulture); // 上個月月初日 dsRSAJ_RSENO.SelectParameters["YYMM2"].DefaultValue = WGuard1.GetMonthEnd(_YYMM, 1).ToString("yyyy/MM/dd", WGuard1.InvariantCulture); // 下個月月底日 dsRSAJ_RSENO.SelectParameters["YYMM3"].DefaultValue = WGuard1.GetMonthBegin(_YYMM, 0).ToString("yyyy/MM/dd", WGuard1.InvariantCulture); // 本月月初日 dsRSAJ_RSENO.SelectParameters["YYMM4"].DefaultValue = WGuard1.GetMonthEnd(_YYMM, 0).ToString("yyyy/MM/dd", WGuard1.InvariantCulture); // 本月月底日 } } // 取得該職稱及等級之薪資資料 protected DataTable GetBPJB(string bpjno, string bpcno) { DbCommand cmd = Query.NewCommand( @"SELECT BPSRM, BPSRD, BPP01, BPP02, BPP03, BPP04, BPP05 FROM BPJB WHERE BPPYN=@BPPYN AND BPJNO=@BPJNO AND BPCNO=@BPCNO "); cmd.Parameters.Add(Query.NewParameter("BPPYN", _RSPYN)); cmd.Parameters.Add(Query.NewParameter("BPJNO", bpjno)); cmd.Parameters.Add(Query.NewParameter("BPCNO", bpcno)); return Query.Select(cmd); } protected void RSAJForm_ItemDeleted(object sender, FormViewDeletedEventArgs e) { Search(); RSAJGrid.DataBind(); RSAJForm.DataBind(); } protected void RSAJForm_ItemInserted(object sender, FormViewInsertedEventArgs e) { Search(); } protected void RSAJForm_ItemUpdated(object sender, FormViewUpdatedEventArgs e) { Search(); } protected void RSAJForm_ModeChanged(object sender, EventArgs e) { if (RSAJForm.CurrentMode == FormViewMode.ReadOnly) { RSAJGrid.Visible = true; RSAJGrid.DataBind(); if (RSAJGrid.Rows.Count > 0 && RSAJGrid.SelectedIndex == -1) { RSAJGrid.SelectedIndex = 0; } if (OldMode == FormViewMode.Insert && RSAJGrid.Rows.Count > 0) { RSAJGrid.PageIndex = RSAJGrid.PageCount - 1; RSAJGrid.DataBind(); RSAJGrid.SelectedIndex = RSAJGrid.Rows.Count - 1; } } else { switch (RSAJForm.CurrentMode) { case FormViewMode.Edit: break; case FormViewMode.Insert: break; } RSAJGrid.Visible = false; } } protected void RSAJForm_ModeChanging(object sender, FormViewModeEventArgs e) { OldMode = (sender as FormView).CurrentMode; } protected void RSAJForm_DataBinding(object sender, EventArgs e) { //if (RSAJForm.FindControl("lbRSAJ_RSPYN") as ITextControl != null) //{ // dsRSAJ_RSENO.SelectParameters["RSPYN"].DefaultValue = (RSAJForm.FindControl("lbRSAJ_RSPYN") as ITextControl).Text; //} //if (RSAJGrid.Rows.Count > 0) //{ // RSAJGrid.Visible = true; // if (RSAJGrid.SelectedIndex == -1) // RSAJGrid.SelectedIndex = 0; // if (RSAJGrid.SelectedIndex > RSAJGrid.Rows.Count - 1) // RSAJGrid.SelectedIndex = RSAJGrid.Rows.Count - 1; // if (RSAJGrid.SelectedIndex != -1 && RSAJGrid.SelectedDataKey != null) // { // dsRSAJ_RSENO.SelectParameters["RSPYN"].DefaultValue = RSAJGrid.SelectedDataKey["RSPYN"].ToString(); // } // else // { // dsRSAJ_RSENO.SelectParameters["RSPYN"].DefaultValue = ""; // } //} } protected void RSAJForm_DataBound(object sender, EventArgs e) { var c = RSAJForm.FindControl("lbRSAJ_RSPYN") as ITextControl; if (c != null) { var t = (c as ITextControl).Text; if (!string.IsNullOrEmpty(t)) dsRSAJ_RSENO.SelectParameters["RSPYN"].DefaultValue = t; else dsRSAJ_RSENO.SelectParameters["RSPYN"].DefaultValue = "-ALL-"; } if (RSAJForm.CurrentMode == FormViewMode.Edit) { SetClientFocus(RSAJForm, "txtRSAJ_RSYMM"); // (RSAJForm.FindControl("ddlRSAJ_RSENO_10") as DropDownList).DataBind(); } } protected void dsRSAJForm_Deleted(object sender, SqlDataSourceStatusEventArgs e) { } protected void cvRAS01_ServerValidate(object source, ServerValidateEventArgs args) { int i; args.IsValid = args.Value != "" && Int32.TryParse(args.Value, out i) && i >= 0 && i <= 6; } protected void RSAJGrid_SelectedIndexChanged(object sender, EventArgs e) { foreach (GridViewRow row in RSAJGrid.Rows) SetGridViewMouseBehavier(RSAJGrid, row); } protected void RSAJGrid_RowDataBound(object sender, GridViewRowEventArgs e) { SetGridViewMouseBehavier(RSAJGrid, e.Row); //GridView_RowDataBound_Shrink_ViewState(sender, e); } protected string GetRAJNOName(string rapyn, string rajno) { DbCommand cmd = Query.NewCommand("SELECT BPJME FROM BPJA WHERE (BPPYN = @BPPYN) AND (BPJNO=@BPJNO)"); cmd.Parameters.Add(Query.NewParameter("BPPYN", rapyn)); cmd.Parameters.Add(Query.NewParameter("BPJNO", rajno)); object o = Query.ExecuteScalar(cmd); if (o == null) return ""; else return o.ToString(); } protected string GetRACNOName(string rapyn, string rajno, string racno) { DbCommand cmd = Query.NewCommand("SELECT BPCME FROM BPJB WHERE (BPPYN = @BPPYN) AND (BPJNO=@BPJNO) AND (BPCNO=@BPCNO)"); cmd.Parameters.Add(Query.NewParameter("BPPYN", rapyn)); cmd.Parameters.Add(Query.NewParameter("BPJNO", rajno)); cmd.Parameters.Add(Query.NewParameter("BPCNO", racno)); object o = Query.ExecuteScalar(cmd); if (o == null) return ""; else return o.ToString(); } protected void RSAJForm_ItemCreated(object sender, EventArgs e) { if (RSAJForm.CurrentMode == FormViewMode.Insert) { (RSAJForm.FindControl("txtRSAJ_RASDT") as TextBox).Text = _RSPYN.Substring(0, _RSPYN.Length - 4) + "0101"; (RSAJForm.FindControl("txtRSAJ_RAS01") as TextBox).Text = "0"; } } protected new bool CheckInput(System.Collections.Specialized.IOrderedDictionary values) { cvMessage.ErrorMessage = ""; cvMessage.IsValid = true; bool result = true; values["RSYMM"] = CheckDate(values["RSYMM"] + "01", "請輸入正確的年月", ref result, cvMessage); ProcessCustomValidatorMessage(cvMessage); return result; } protected void RSAJForm_ItemInserting(object sender, FormViewInsertEventArgs e) { e.Cancel = !CheckInput(e.Values); } protected void RSAJForm_ItemUpdating(object sender, FormViewUpdateEventArgs e) { e.Cancel = !CheckInput(e.NewValues); } protected void Next_Click(object sender, EventArgs e) { string rspyn = ddlRSPYN.SelectedValue; ViewState["RSPYN"] = rspyn; _RSPYN = rspyn; // 檢查此使用者是否有權限處理這個專案 BprmDAC bprm = new BprmDAC(Query); if (!bprm.GetRight(rspyn, UserId)) { MultiView1.Visible = false; cvMessage.ErrorMessage = "對不起,你沒有處理這個專案的權限!"; cvMessage.IsValid = false; return; } //DoAfterCommand("RSAJ"); MultiView1.Visible = true; MultiView1.ActiveViewIndex = 1; GetRsenoDropDownData(); } private int CheckInsertInput(int index) { RSYMMs[index].Text = RSYMMs[index].Text.Trim(); RSAMTs[index].Text = RSAMTs[index].Text.Trim(); RSDOCs[index].Text = RSDOCs[index].Text.Trim(); // 有輸入的條件為:日期有輸入且合理,金額不等於0,備註無所謂 bool rsymmValid = false; bool rsamtValid = false; rsymmValid = CheckDate(RSYMMs[index].Text + "01", out RSYMMValues[index]); rsamtValid = Int32.TryParse(RSAMTs[index].Text, out RSAMTValues[index]); if (RSYMMs[index].Text != "" && rsymmValid && RSAMTs[index].Text != "" && rsamtValid && RSAMTValues[index] != 0) { return 0; } if (RSYMMs[index].Text == "" && RSAMTs[index].Text == "") { return 1; } int returnValue = 0; if (RSYMMs[index].Text != "" && !rsymmValid) { returnValue -= 1; } if (RSAMTs[index].Text != "" && !rsamtValid) { returnValue -= 2; } return returnValue; } protected void btnSave1_Click(object sender, EventArgs e) { // 存檔 // 1. 檢查各組輸入 int[] hasInput = new int[10]; bool valid = true; bool needSave = false; cvMessage.ErrorMessage = ""; cvMessage.IsValid = true; for (int i = 0; i < RSYMMs.Length; i++) { hasInput[i] = CheckInsertInput(i); switch (hasInput[i]) { case 0: needSave = true; break; case -1: valid = false; cvMessage.ErrorMessage += String.Format("第{0}組輸入月份不合理
", i + 1); break; case -2: valid = false; cvMessage.ErrorMessage += String.Format("第{0}組輸入金額不合理
", i + 1); break; case -3: valid = false; cvMessage.ErrorMessage += String.Format("第{0}組輸入月份與金額不合理
", i + 1); break; } } if (!valid) { cvMessage.IsValid = false; ProcessCustomValidatorMessage(cvMessage); return; } if (!needSave) return; // 2. 各組輸入存檔 DbCommand cmd1 = Query.NewCommand( @"INSERT INTO dbo.RSAJ (RSREN, RSENO, RSPYN, RSYMM, RSAMT, RSDOC, APPNO, TRDAT, TRMOD, TRUSR) VALUES (@RSREN, @RSENO, @RSPYN, @RSYMM, @RSAMT, @RSDOC, 1, GETDATE(), 'INSERT', @TRUSR)"); cmd1.Parameters.Add(Query.NewParameter("RSREN", DbType.String)); cmd1.Parameters.Add(Query.NewParameter("RSENO", DbType.String)); cmd1.Parameters.Add(Query.NewParameter("RSPYN", _RSPYN)); cmd1.Parameters.Add(Query.NewParameter("RSYMM", DbType.DateTime)); cmd1.Parameters.Add(Query.NewParameter("RSAMT", DbType.Int32)); cmd1.Parameters.Add(Query.NewParameter("RSDOC", DbType.String)); cmd1.Parameters.Add(Query.NewParameter("TRUSR", UserId)); DbConnection conn = Query.NewConnection(ConnectionString); cmd1.Connection = conn; conn.Open(); DbTransaction tran = conn.BeginTransaction(); cmd1.Transaction = tran; try { for (int i = 0; i < RSYMMs.Length; i++) { if (hasInput[i] == 0) { string rpren = WGuard1.WNextRen(RSYMMValues[i], "RSAJ", "RSREN", "YYYYMM<9999>", "", tran); cmd1.Parameters["RSREN"].Value = rpren; cmd1.Parameters["RSENO"].Value = RSENOs[i].SelectedValue; cmd1.Parameters["RSYMM"].Value = RSYMMValues[i]; cmd1.Parameters["RSAMT"].Value = RSAMTValues[i]; cmd1.Parameters["RSDOC"].Value = RSDOCs[i].Text; cmd1.ExecuteNonQuery(); } } tran.Commit(); // 清除畫面資料 for (int i = 0; i < RSYMMs.Length; i++) { RSYMMs[i].Text = ""; RSAMTs[i].Text = ""; RSDOCs[i].Text = ""; } cvMessage.ErrorMessage = "存檔完成"; cvMessage.IsValid = false; } catch (Exception ex) { tran.Rollback(); cvMessage.ErrorMessage = ex.Message; cvMessage.IsValid = false; } finally { conn.Close(); } } protected void btnCancel1_Click(object sender, EventArgs e) { // 回到處理畫面 Search(); MultiView1.Visible = true; MultiView1.ActiveViewIndex = 2; } protected void btnSSMS_Click(object sender, EventArgs e) { cvMessage.IsValid = true; cvMessage.ErrorMessage = ""; bool result = true; DateTime aYYMM = CheckDate(txtYYMM.Text + "01", "請輸入正確的年月", ref result, cvMessage); if (result) { MultiView1.Visible = false; ViewState["YYMM"] = aYYMM; _YYMM = aYYMM; ddlRSPYN.DataSource = new BpaaDAC().GetBpaaWithTY(aYYMM.Year); ddlRSPYN.DataBind(); } } }