/// <summary> /// 保存按鈕事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { string OTDate = ""; string YearMonth = ""; double strLvTotal = Convert.ToDouble(this.txtHours.Text); string OTType = this.txtOTType.Text; if (OTType.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.OTMType + Message.Required + "')", true); } else { string LHZBIsDisplayG2G3 = ""; try { LHZBIsDisplayG2G3 = ConfigurationManager.AppSettings["LHZBIsDisplayG2G3"]; } catch { LHZBIsDisplayG2G3 = "N"; } if (LHZBIsDisplayG2G3 == "Y") { OTType = OTType.Substring(0, 2); } try { OTDate = DateTime.Parse(this.txtOTDate.Text.ToString()).ToString("yyyy/MM/dd"); YearMonth = DateTime.Parse(this.txtOTDate.Text.ToString()).ToString("yyyy-MM").Replace("-", ""); } catch (Exception) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.ErrDate + "')", true); return; } string WorkNo = this.txtEmployeeNo.Text.Trim().ToUpper(); if (strLvTotal < 0.5) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.ActivityHoursError + "')", true); } else if ((OTType == "G1") && (strLvTotal > 16.0)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.ActivityHoursG1Error + "')", true); } else if (((OTType == "G2") || (OTType == "G3")) && (strLvTotal > 24.0)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.ActivityHoursG2Error + "')", true); } else { DataRow row; if (this.ProcessFlag.Value.Equals("Add")) { model = new ActivityModel(); model.WorkNo = this.txtEmployeeNo.Text.Trim().ToUpper(); model.Remark = OTDate; if (int.Parse(activityApplyBll.GetValue("condition15", model)) == 1) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.ActivityHoursCountError + "')", true); return; } tempDataTable = activityApplyBll.GetLHZBData("", "", "", "condition3"); if (tempDataTable.Rows.Count >= 1) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.duplicate + "')", true); return; } row = tempDataTable.NewRow(); tempDataTable.Columns["StartTime"].DataType = typeof(string); tempDataTable.Columns["EndTime"].DataType = typeof(string); row.BeginEdit(); row["WorkNo"] = WorkNo; row["OTDate"] = OTDate; row["ConfirmHours"] = strLvTotal; row["OTType"] = OTType; row["WorkDesc"] = this.txtWorkDesc.Text.Trim().Replace("'", ""); row["Status"] = "0"; row["YearMonth"] = YearMonth; row["UPDATE_USER"] = CurrentUserInfo.Personcode; row["UPDATE_DATE"] = DateTime.Now.ToString("yyyy/MM/dd"); row["StartTime"] = this.txtStartTime.Text.Trim(); row["EndTime"] = this.txtEndTime.Text.Trim(); row.EndEdit(); this.tempDataTable.Rows.Add(row); this.tempDataTable.AcceptChanges(); logmodel.ProcessFlag = "insert"; activityApplyBll.LHZBSaveData(this.ProcessFlag.Value, tempDataTable, CurrentUserInfo.Personcode,logmodel); this.HiddenSave.Value = "Save"; } else if (this.ProcessFlag.Value.Equals("Modify")) { string M_ID = this.HiddenID.Value; tempDataTable = activityApplyBll.GetLHZBData(WorkNo, M_ID, OTDate, "condition4"); if (this.tempDataTable.Rows.Count > 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.ActivityHoursCountError + "')", true); return; } tempDataTable = activityApplyBll.GetLHZBData("", M_ID, "", "condition5"); if (this.tempDataTable.Rows.Count == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.AtLastOneChoose + "')", true); return; } row = this.tempDataTable.Rows[0]; tempDataTable.Columns["StartTime"].DataType = typeof(string); tempDataTable.Columns["EndTime"].DataType = typeof(string); row.BeginEdit(); row["ID"] = M_ID; row["WORKNO"] = WorkNo; row["OTDate"] = OTDate; row["ConfirmHours"] = strLvTotal; row["OTType"] = OTType; row["WorkDesc"] = this.txtWorkDesc.Text.Trim().Replace("'", ""); row["YearMonth"] = YearMonth; row["StartTime"] = this.txtStartTime.Text.Trim(); row["EndTime"] = this.txtEndTime.Text.Trim(); row.EndEdit(); this.tempDataTable.AcceptChanges(); logmodel.ProcessFlag = "update"; activityApplyBll.LHZBSaveData(this.ProcessFlag.Value, this.tempDataTable, CurrentUserInfo.Personcode,logmodel); } //if (this.ProcessFlag.Value == "Add") //{ // ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.AddSuccess + "')", true); // this.Add(); //} //else //{ // base.Response.Write("<script type='text/javascript'>window.parent.document.all.btnQuery.click();</script>"); //} //新增和修改之後直接返回上頁面 //base.Response.Write("<script type='text/javascript'>window.parent.document.all.btnQuery.click();</script>"); //新增修改之後添加提示再返回之前頁面 if (this.ProcessFlag.Value == "Add") { //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.AddSuccess + "');window.parent.document.all.btnQuery.click();", true); base.Response.Write("<script type='text/javascript'>alert('" + Message.AddSuccess + "');window.parent.document.all.btnQuery.click();</script>"); } else { //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "show", "alert('" + Message.UpdateSuccess + "')", true); base.Response.Write("<script type='text/javascript'>alert('" + Message.UpdateSuccess + "');window.parent.document.all.btnQuery.click();</script>"); } } } }
/// <summary> /// 重載Ajax方法 /// </summary> protected override void AjaxProcess() { string noticeJson = null; if (Request.Form["ActionFlag"] == "FindOTType") { string OTDate = Request.Form["OTDate"].ToString(); string WorkNo = Request.Form["WorkNo"].ToString(); string OTType = FindOTType(OTDate, WorkNo); Response.Clear(); Response.Write(OTType); Response.End(); } if (Request.Form["ActionFlag"] == "GetOTMFlag") { string OTDate = Request.Form["OTDate"].ToString(); string WorkNo = Request.Form["WorkNo"].ToString(); string OTMFlag = GetOTMFlag(WorkNo, OTDate); Response.Clear(); Response.Write(OTMFlag); Response.End(); } if (Request.Form["ActionFlag"] == "GetEmp") { if (!string.IsNullOrEmpty(Request.Form["WorkNo"])) { string WorkNo = Request.Form["WorkNo"].ToString(); string sqlDep = Request.Form["SqlDep"]; DataTable temp = new DataTable(); temp = GetEmp(WorkNo, sqlDep); ActivityModel model = new ActivityModel(); if (temp.Rows.Count != 0) { model.WorkNo = temp.Rows[0]["WorkNo"].ToString(); model.LocalName = temp.Rows[0]["LocalName"].ToString(); model.DepName = temp.Rows[0]["DepName"].ToString(); model.OverTimeType = temp.Rows[0]["Flag"].ToString(); } if (model != null) { noticeJson = JsSerializer.Serialize(model); } Response.Clear(); Response.Write(noticeJson); Response.End(); } } if (Request.Form["ActionFlag"] == "Get_MonthOverTime") { if (!string.IsNullOrEmpty(Request.Form["WorkNo"])) { string WorkNo = Request.Form["WorkNo"].ToString(); string MonthTotal = Get_MonthOverTime(WorkNo); Response.Clear(); Response.Write(MonthTotal); Response.End(); } } if (Request.Form["ActionFlag"] == "GetOTHours") { if (!string.IsNullOrEmpty(Request.Form["WorkNo"])) { string WorkNo = Request.Form["WorkNo"].ToString(); string OTDate = Request.Form["OTDate"].ToString(); string BeginTime = Request.Form["BeginTime"].ToString(); string EndTime = Request.Form["EndTime"].ToString(); string OTType = Request.Form["OTType"].ToString(); string OTHours = GetOTHours(WorkNo, OTDate, BeginTime, EndTime, OTType); Response.Clear(); Response.Write(OTHours); Response.End(); } } }