protected void btnSave_Click(object sender, EventArgs e)
    {
        //----------UPDATE PSST_PERSON----------
        string SQL = "";
        SQL = " SELECT * \n";
        SQL += "  FROM PSST_PERSON \n";
        SQL += " WHERE ID="+ PSN_ID ;
        SqlDataAdapter DA = OPM_BL.GetNewSqlDataAdapter(SQL);
        DataTable DT = new DataTable();
        DA.Fill(DT);

        DataRow DR = null;
        if (DT.Rows.Count == 1)
        {
            DR = DT.Rows[0];
        }
        DR["TEL"] = ctlTEL.Text;
        DR["FAX"] = ctlFAX.Text;
        DR["MOBILE"] = ctlMOBILE.Text;
        //DR["EMAIL"] = ctlEMAIL.Text;    // แก้ไม่ได้
        DR["TEL_ORG"] = ctlTEL_ORG.Text;
        DR["TEL_ORG_EXT"] = ctlTEL_ORG_EXT.Text;
        //DR["USER_ID"] = Session["USER_PSNL_NO"];
        DR["LAST_DATE"] = DateTime.Now;
        if (DT.Rows.Count == 0)
            DT.Rows.Add(DR);
        SqlCommandBuilder cmd = new SqlCommandBuilder(DA);
        try
        {
            DA.Update(DT);

            LogFileEng.SaveActionTransLog("HRM_UT0301", "UPDATE", "บันทึกข้อมูลการติดต่อพนักงานรหัส ID='" + PSN_ID + "'", "PSST_PERSON", "ID='" + PSN_ID + " ", "", Request);

            string ret = "";
            HRMWebService.HRMWebService ws = new HRMWebService.HRMWebService();
            ws.Url = OPM_BL.GetSysconfig("OPMWebServiceURL");
            ws.Timeout = 10000;
            ret = ws.HRMUpdatePerson(LoginUserData.getLoginPerIdDPIS(Request), ctlTEL.Text.Trim(), ctlFAX.Text.Trim(), ctlMOBILE.Text.Trim(), ctlTEL_ORG.Text.Trim(), ctlTEL_ORG_EXT.Text.Trim(), ctlEMAIL.Text.Trim());

            OPM_BL.SetAlertTextBox(this.Page, "บันทึกเรียบร้อย", ctlTEL_ORG);

        }
        catch (Exception ex)
        {
            OPM_BL.SetAlertTextBox(this.Page, "ไม่สามารถบันทึกได้", ctlTEL_ORG);
        }

            Response.Redirect("PSST_PERSON_ListView.aspx");
    }
Пример #2
0
    //protected void gv_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
    //{
    //    if (e.RowType == GridViewRowType.Data)
    //    {
    //        ASPxGridView gv = (ASPxGridView)sender;
    //        GridViewDataColumn colStatus = (GridViewDataColumn)gv.Columns["leave_status_name"];
    //        ASPxLabel lblLeaveStatus = (ASPxLabel)gv.FindRowCellTemplateControl(e.VisibleIndex, colStatus, "lblLeaveStatus");
    //        ASPxLabel lblLeaveStatusName = (ASPxLabel)gv.FindRowCellTemplateControl(e.VisibleIndex, colStatus, "lblStatusName");
    //        GridViewDataColumn colID = (GridViewDataColumn)gv.Columns["id"];
    //        ImageButton btnLeaveDetail = (ImageButton)gv.FindRowCellTemplateControl(e.VisibleIndex, colID, "btnLeaveDetail");
    //        //ASPxLabel lblLeaveApproveBy = (ASPxLabel)gv.FindRowCellTemplateControl(e.VisibleIndex, colID, "lblLeaveApproveBy");
    //        //GridViewDataColumn colChk = (GridViewDataColumn)gv.DataColumns[6];
    //        //ASPxCheckBox chkItem = (ASPxCheckBox)gv.FindRowCellTemplateControl(e.VisibleIndex, colChk, "chkItem");
    //        //GridViewDataColumn colApproveDate = (GridViewDataColumn)gv.DataColumns[7];;
    //        //ASPxDateEdit txtApproveDate = (ASPxDateEdit)gv.FindRowCellTemplateControl(e.VisibleIndex, colApproveDate, "txtApproveDate");
    //        //ASPxLabel lblApproveDate = (ASPxLabel)gv.FindRowCellTemplateControl(e.VisibleIndex, colApproveDate, "lblApproveDate");
    //        long vLeaveID = Convert.ToInt64(gv.GetRowValues(e.VisibleIndex, "id"));
    //        if (vLeaveID > 0)
    //        {
    //            GridViewDataTextColumn colApproveDate = (GridViewDataTextColumn)gv.DataColumns[5];
    //            GridViewDataColumn colLeaveID = (GridViewDataColumn)gv.Columns["id"];
    //            ASPxLabel lblLeaveApproveBy = (ASPxLabel)gv.FindRowCellTemplateControl(e.VisibleIndex, colLeaveID, "lblLeaveApproveBy");
    //            UserControl_txtDatePicker txtApproveDate = (UserControl_txtDatePicker)gv.FindRowCellTemplateControl(e.VisibleIndex, colApproveDate, "txtApproveDate");
    //            if (lblLeaveApproveBy.Text == "0")
    //            {
    //                //อนุญาตโดยผู้บังคับบัญชา
    //                bool isApprover = false;
    //                string ApproveStatus = "0";
    //                string ApproveDate = "";
    //                string sql = "select id, approve_status, approve_date ";
    //                sql += " from hrm_leave_his_approver";
    //                sql += " where leave_his_id = @_ID";
    //                sql += " and person_id_approve = @_PERSON_ID";
    //                SqlParameter[] param = new SqlParameter[2];
    //                param[0] = OPM_BL.setParameter("@_ID", SqlDbType.BigInt, vLeaveID);
    //                param[1] = OPM_BL.setParameter("@_PERSON_ID", SqlDbType.BigInt, Convert.ToInt64(LoginUserData.getLoginUserID(Request)));
    //                DataTable aDt = OPM_BL.GetDatatable(sql, param);
    //                if (aDt.Rows.Count > 0)
    //                {
    //                    isApprover = true;
    //                    ApproveStatus = aDt.Rows[0]["approve_status"].ToString();
    //                    if (Convert.IsDBNull(aDt.Rows[0]["approve_date"]) == false)
    //                    {
    //                        ApproveDate = Convert.ToDateTime(aDt.Rows[0]["approve_date"]).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH"));
    //                    }
    //                }
    //                aDt.Dispose();
    //                //lblApproveDate.Text = ApproveDate;
    //                //ถ้าสถานะ รออนุญาต ให้ตรวจสอบว่ามีสิทธิ์อนุญาติหรือไม่
    //                if (lblLeaveStatus.Text == "2" && isApprover == true && ApproveStatus == "4")
    //                {
    //                    btnLeaveDetail.ImageUrl = "~/images/edit.png";
    //                    //chkItem.Visible = true;
    //                    //txtApproveDate.Visible = true;
    //                    //lblApproveDate.Visible = false;
    //                }
    //                else
    //                { // if (lblLeaveStatus.Text != "2" || isApprover==false || ApproveStatus != "4") {
    //                    //ถ้าสถานะ รอตรวจสอบ/อนุญาติ หรือรออนุญาตแต่ไม่มีสิทธิ์อนุญาติ
    //                    btnLeaveDetail.ImageUrl = "~/images/view.png";
    //                    //chkItem.Visible = false;
    //                    //txtApproveDate.Visible = false;
    //                    //lblApproveDate.Visible = true;
    //                }
    //            }
    //            else
    //            {
    //                //อนุญาตโดยกองการเจ้าหน้าที่
    //                //ถ้า Status เป็น ไม่ได้ส่งใบลาเพื่อพิจารณา หรือ รออนุญาติ ให้แสดงเป็นคำว่ารออนุญาติ
    //                if (lblLeaveStatus.Text == "1" || lblLeaveStatus.Text == "2")
    //                {
    //                    lblLeaveStatusName.Text = "รออนุญาต";
    //                    btnLeaveDetail.ImageUrl = "~/images/edit.png";
    //                    //chkItem.Visible = true;
    //                    //txtApproveDate.Visible = true;
    //                    //lblApproveDate.Visible = false;
    //                }
    //                else
    //                {
    //                    btnLeaveDetail.ImageUrl = "~/images/view.png";
    //                    //chkItem.Visible = false;
    //                    //txtApproveDate.Visible = false;
    //                    //lblApproveDate.Visible = true;
    //                }
    //            }
    //            //รายละเอียดเกี่ยวกับการยกเลิกวันลา ถ้ามี
    //            //lblCancelDetail
    //        }
    //    }
    //}
    protected void btnApprove_Click(object sender, EventArgs e)
    {
        if (ValidateApprove() == true)
        {
            for (int i = 0; i < gv.VisibleRowCount-1; i++)
            {
                GridViewDataColumn colChk = (GridViewDataColumn)gv.DataColumns[6];
                DevExpress.Web.ASPxEditors.ASPxCheckBox chkItem = (DevExpress.Web.ASPxEditors.ASPxCheckBox)gv.FindRowCellTemplateControl(i, colChk, "chkItem");
                if (chkItem != null)
                {
                    if (chkItem.Visible == true)
                    {
                        if (chkItem.Checked == true)
                        {
                            long vLeaveID = Convert.ToInt64(gv.GetRowValues(i, "id").ToString());
                            GridViewDataColumn colID = (GridViewDataColumn)gv.Columns["id"];
                            ASPxLabel lblLeaveApproveBy = (ASPxLabel)gv.FindRowCellTemplateControl(i, colID, "lblLeaveApproveBy");

                            GridViewDataColumn colApproveDate = (GridViewDataColumn)gv.DataColumns[7]; ;
                            UserControl_txtDatePicker txtApproveDate = (UserControl_txtDatePicker)gv.FindRowCellTemplateControl(i, colApproveDate, "txtApproveDate");
                            //if (lblLeaveApproveBy.Text == "0")
                            //{   //ถ้าเป็นรายการที่อนุญาตโดยผู้บังคับบัญชา
                            //    OPM_BL.ApproveLeaveData(this.Page, txtApproveDate.txtDatePicker,txtApproveDate.Value.Value, vLeaveID, Request,"1");
                            //}
                            //else
                            //{
                            //ถ้าเป็นรายการที่อนุญาตโดยกองการเจ้าหน้าที่
                            string sql = "update hrm_leave_his";
                            sql += " set leave_status=@_LEAVE_STATUS";
                            sql += " ,comm_date = @_APPROVE_DATE";
                            sql += " ,comm_date_active = @_APPROVE_DATE";
                            sql += " output inserted.leave_day, inserted.leave_id,inserted.person_id,inserted.budget_year";
                            sql += " where id=@_ID";

                            SqlParameter[] param = new SqlParameter[3];
                            param[0] = OPM_BL.setParameter("@_LEAVE_STATUS", SqlDbType.VarChar, "3");  //อนุญาตแล้ว
                            param[1] = OPM_BL.setParameter("@_APPROVE_DATE", SqlDbType.Date, Convert.ToDateTime(txtApproveDate.Value));
                            param[2] = OPM_BL.setParameter("@_ID", SqlDbType.BigInt, vLeaveID);

                            DataTable lDt = OPM_BL.GetDatatable(sql, param);
                            if (lDt.Rows.Count == 0)
                            {
                                OPM_BL.SetAlertTextDate(this.Page, "พบปัญหาการบันทึกข้อมูล SQL=" + sql + " ###LeaveID=" + vLeaveID.ToString(), txtApproveDate.txtDatePicker);
                                return;
                            }
                            else
                            {
                                //กรณีเป็นการลาพักผ่อน
                                //ให้ไป Update ข้อมูลการลาพักผ่อนสะสมด้วย
                                if (lDt.Rows[0]["leave_id"].ToString() == "4")
                                {
                                    //Update HRM_SUM_VACATION
                                    sql = "update HRM_SUM_VACATION";
                                    sql += " set leave_rest = leave_rest+@_LEAVE_QTY";
                                    sql += " where person_id=@_PERSON_ID";
                                    sql += " and budget_year=@_BUDGET_YEAR";

                                    param = new SqlParameter[3];
                                    param[0] = OPM_BL.setParameter("@_LEAVE_QTY", SqlDbType.Float, Convert.ToDouble(lDt.Rows[0]["leave_day"]));
                                    param[1] = OPM_BL.setParameter("@_PERSON_ID", SqlDbType.BigInt, Convert.ToInt64(lDt.Rows[0]["person_id"]));
                                    param[2] = OPM_BL.setParameter("@_BUDGET_YEAR", SqlDbType.Int, Convert.ToInt16(lDt.Rows[0]["budget_year"]));

                                    string ret = OPM_BL.ExecuteNoneQuery(sql, param);
                                    if (ret != "true")
                                    {
                                        OPM_BL.SetAlertTextDate(this.Page, "พบปัญหาการบันทึกข้อมูล SQL=" + sql + " ###LeaveID=" + vLeaveID.ToString(), txtApproveDate.txtDatePicker);
                                        return;
                                    }
                                }

                                //Update ข้อมูลไปยัง DPIS ผ่าน Web service
                                HRMWebService.HRMWebService ws = new HRMWebService.HRMWebService();
                                ws.Url = OPM_BL.GetSysconfig("OPMWebServiceURL");
                                ws.Timeout = 10000;
                                ws.SendLeaveDataToDPIS(vLeaveID);
                                ws.Dispose();
                            }
                            //}

                        }
                    }
                }
            }

            OPM_BL.SetAlertComboBox(this.Page, "อนุญาตใบลาเรียบร้อย", cmbLeaveType);
            btnSearch_Click(null, null);
        }
    }
Пример #3
0
    void Save(string Level,  string ORG_NAME, string ORG_ABBR, string ORG_SERIAL, string UPPER_ORG_SERIAL , Boolean Active)
    {
        try
        {
            //   ตรวจสอบ ค่าเดิมก่อนบันทึกข้อมูล  (Save)
            string SQL = "";
            SQL = "SELECT * ";
            SQL += " FROM CTLT_ORGANIZE ";
            SQL += " WHERE ORG_SERIAL=" + ORG_SERIAL + "\n";
            SqlDataAdapter DA = new SqlDataAdapter(SQL, OPM_BL.DefaultConnectionString);
            DataTable DT = new DataTable();
            DA.Fill(DT);

            DataTable DT_Data = new DataTable();
            if (UPPER_ORG_SERIAL != "0")
                {
                    //หาข้อมูลอ้างอิงหน่วยงานตาม Level
                    String Sql_Data = " SELECT TOP 1 * ";
                    Sql_Data += " FROM CTLT_ORGANIZE ";
                    Sql_Data += " WHERE ORG_SERIAL=" + UPPER_ORG_SERIAL + "\n";
                    Sql_Data += " Order By org_serial desc ";
                    SqlDataAdapter DA_Data = new SqlDataAdapter(Sql_Data, OPM_BL.DefaultConnectionString);
                    DA_Data.Fill(DT_Data);
                }

            DataRow DR;
            string Log_Desc = "";
            if (DT.Rows.Count == 0)
            {
                DR = DT.NewRow();
                DR["ORG_SERIAL"] = ORG_SERIAL.Replace("'", "''");
                DR["ORG_TYPE"] = "10";
                DR["ROOT_LEVEL1"] = DBNull .Value ;
                DR["ROOT_LEVEL2"] = DBNull.Value;
                DR["ROOT_LEVEL3"] = DBNull.Value;
                DR["ROOT_LEVEL4"] = DBNull.Value;
                DR["ROOT_LEVEL5"] = DBNull.Value;
                DR["ORG_LEVEL"] = DBNull.Value;
                Log_Desc += " ORG_SERIAL " + ORG_SERIAL.Replace("'", "''");
                switch (Level)
                {
                    case "0":       //เพิ่ม  กระทรวง level 1
                        DR["ORG_LEVEL"] = "1";
                        Log_Desc += " Level 1";
                        break;

                    case "1":   //เพิ่มกรม level 2
                        if (DT_Data.Rows.Count > 0)
                        {
                            DR["ROOT_LEVEL1"] = DT_Data.Rows[0]["ROOT_LEVEL1"];
                        }
                        DR["ORG_LEVEL"] = "2";
                        Log_Desc += " Level 2";
                        break;

                    case "2":  //เพิ่มกอง level 3
                        if (DT_Data.Rows.Count > 0)
                        {
                            DR["ROOT_LEVEL1"] = DT_Data.Rows[0]["ROOT_LEVEL1"];
                            DR["ROOT_LEVEL2"] = DT_Data.Rows[0]["ROOT_LEVEL2"];
                        }
                        DR["ORG_LEVEL"] = "3";
                        Log_Desc += " Level 2";
                        break;

                    case "3":  //เพิ่มฝ่าย level 4
                        if (DT_Data.Rows.Count > 0)
                        {
                            DR["ROOT_LEVEL3"] = DT_Data.Rows[0]["ROOT_LEVEL3"];
                        }
                        DR["ORG_LEVEL"] = "4";
                        Log_Desc += " Level 4";
                        break;

                    case "4":  //เพิ่มงาาน level 5
                        if (DT_Data.Rows.Count > 0)
                        {
                            DR["ROOT_LEVEL4"] = DT_Data.Rows[0]["ROOT_LEVEL4"];
                        }
                        DR["ORG_LEVEL"] = "5";
                        Log_Desc += " Level 5";
                        break;

                    default:
                        break;
                }
            DR["UPPER_ORG_SERIAL"] = UPPER_ORG_SERIAL;  //"76" สปน.
            DR["ORG_ID"] = DBNull.Value;        // Null สำหรับหน่วยงานลอย
            DR["ORG_CODE_DPIS"] = DBNull .Value ;
            DR["CREATE_BY"] = user_Code;
            DR["CREATE_DATE"] =  DateTime.Now;

            LogFileEng.SaveActionTransLog("CMN_UT0201", "ADD", "เพิ่ม หน่วยงานลอย : " + Log_Desc, "CTLT_ORGANIZE", txtSerialLevel0.Text.Trim(), "", Request);
            }
            else
            {
                DR = DT.Rows[0];
                DR["USER_ID"] = user_Code;
                DR["LAST_DATE"] =  DateTime.Now;
                Log_Desc += " ORG_SERIAL " + ORG_SERIAL.Replace("'", "''");

                LogFileEng.SaveActionTransLog("CMN_UT0201", "UPDATE", "แก้ไข " + Log_Desc, "CTLT_ORGANIZE", txtSerialLevel0.Text.Trim(), "", Request);

            }
                      DR["ORG_NAME"] = ORG_NAME.Replace("'", "''");
                      DR["ORG_ABBR"] = ORG_ABBR.Replace("'", "''");
                    // ชื่อ  และ  ชื่อเต็ม
                  if (Level == "0")
                  {
                      DR["ORG_FULL"] = ORG_NAME.Replace("'", "''");
                      DR["ORG_FULL_ABBR"] = ORG_ABBR.Replace("'", "''");

                  }else {
                      if (DT_Data.Rows.Count > 0)
                      {
                          DR["ORG_FULL"] = DT_Data.Rows[0]["ORG_NAME"].ToString() + " " + ORG_NAME.Replace("'", "''");
                          DR["ORG_FULL_ABBR"] = DT_Data.Rows[0]["ORG_ABBR"].ToString() + " " + ORG_ABBR.Replace("'", "''");
                      }
                  }
                  if (Active == true)
                  {
                      DR["ORG_STATUS"] = "A";          // สถานะใช้งาน A = ใช้งาน
                  }
                  else {
                      DR["ORG_STATUS"] = "C";          // สถานะใช้งาน C = ยกเลิก
                  }

            if (DT.Rows.Count == 0) DT.Rows.Add(DR);
            SqlCommandBuilder cmd = new SqlCommandBuilder(DA);
            DA.Update(DT);

            HRMWebService.HRMWebService ws = new HRMWebService.HRMWebService();
            ws.Timeout = 10000;
            ws.Url = OPM_BL.GetSysconfig("OPMWebServiceURL");
            string re = ws.CMNSaveOrganize(Convert.ToInt64(ORG_SERIAL.Replace("'", "''")));
            ws.Dispose();

            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "alert", "alert('บันทึกสำเร็จ');", true);
            SetParamLevel0();
            SetParamLevel1(ORG_SERIAL_Level0);
            SetParamLevel2(ORG_SERIAL_Level1);
            SetParamLevel3(ORG_SERIAL_Level2);
            SetParamLevel4(ORG_SERIAL_Level3);
        }

        catch (Exception ex)
        {
            string err = ex.ToString();
            if (ex.ToString().Length > 500)
            {
                err = ex.ToString().Substring(0, 499);
            }
            LogFileEng.SaveActionTransLog("CMN_UT0201", "SAVE", err, "CTLT_ORGANIZE", "", "", Request);
            ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "alert", "alert('" + err.Replace("'", "") + "');", true);
        }
    }
Пример #4
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string userCodeName = ODSAuthenEngine.LoginUserData.getLoginUserCode(Request);
        string UserID = ODSAuthenEngine.LoginUserData.getLoginUserID(Request);

        if (txtOldPass.Text == "")
        {
            Alert("กรุณากรอกรหัสผ่านเดิม", this.Page);
        }
        else if (txtNewPass.Text == "")
        {
            Alert("กรุณากรอกรหัสผ่านใหม่", this.Page);
        }
        else if (txtConfirmPass.Text == "")
        {
            Alert("กรุณายืนยันรหัสผ่านใหม่", this.Page);
        }
        else if (txtNewPass.Text != txtConfirmPass.Text)
        {
            Alert("รหัสผ่านใหม่ไม่ตรงกัน", this.Page);
        }
        else if (txtNewPass.Text == txtConfirmPass.Text)
        {
            string ret = ODSAuthenEngine.LoginUserData.ChangePassword(userCodeName, UserID, txtOldPass.Text.Trim(), txtNewPass.Text.Trim(), txtTEL.Text.Trim(), txtMOBILE.Text.Trim(), txtTEL_ORG.Text.Trim(), txtTEL_ORG_EXT.Text.Trim(), txtFAX.Text.Trim(), txtEmail.Text.Trim());
            if (ret == "true")
            {
                HRMWebService.HRMWebService ws = new HRMWebService.HRMWebService();
                ws.Url = OPM_BL.GetSysconfig("OPMWebServiceURL");
                ws.Timeout = 10000;
                ret = ws.ChangePassword(UserID, userCodeName, txtNewPass.Text, LoginUserData.getLoginPerIdDPIS(Request), txtTEL.Text.Trim(), txtFAX.Text.Trim(), txtMOBILE.Text.Trim(), txtTEL_ORG.Text.Trim(), txtTEL_ORG_EXT.Text.Trim(), txtEmail.Text.Trim());
                if (ret == "true")
                {
                    Response.Redirect("Login.aspx");
                }
                else
                {
                    Alert(ret, this.Page);
                }
            }
            else
            {
                Alert(ret, this.Page);
            }
        }

        pnlDialog.Visible = false;
    }
Пример #5
0
    //แก้ไขข้อมูลผู้ใช้ แท็บข้อมูลติดต่อ
    protected void btnSaveTab2_Click(object sender, EventArgs e)
    {
        string userCodeName = ODSAuthenEngine.LoginUserData.getLoginUserCode(Request);
        string UserID = ODSAuthenEngine.LoginUserData.getLoginUserID(Request);

        // บันทึกลง database OPM

        String SQL = "SELECT ID,TEL,MOBILE,TEL_ORG,TEL_ORG_EXT,FAX,EMAIL FROM PSST_PERSON WHERE ID='" + UserID + "'";
        SqlDataAdapter DA = new SqlDataAdapter(SQL, OPM_BL.DefaultConnectionString);
        DataTable DT_Update = new DataTable();
        DA.Fill(DT_Update);
        DataRow DR = null;

        if (DT_Update.Rows.Count == 1)
        {
            DR = DT_Update.Rows[0];
            //DR["ID"] = UserID;
            // IT ให้ตัด 27/10/59
            //if (txtTEL.Text != "")
            //{
            //    DR["TEL"] = txtTEL.Text;
            //}
            //else {
            //    DR["TEL"] = DBNull.Value;
            //}
            if (txtMOBILE.Text != "")
            {
                DR["MOBILE"] = txtMOBILE.Text;
            }
            else
            {
                DR["MOBILE"] = DBNull.Value;
            }

            if (txtTEL_ORG.Text != "")
            {
                DR["TEL_ORG"] = txtTEL_ORG.Text;
            }
            else
            {
                DR["TEL_ORG"] = DBNull.Value;
            }
            if (txtTEL_ORG_EXT.Text != "")
            {
                DR["TEL_ORG_EXT"] = txtTEL_ORG_EXT.Text;
            }
            else
            {
                DR["TEL_ORG_EXT"] = DBNull.Value;
            }

            if (txtFAX.Text != "")
            {
                DR["FAX"] = txtFAX.Text;
            }
            else
            {
                DR["FAX"] = DBNull.Value;
            }
            if (txtEmail.Text != "")
            {
                DR["EMAIL"] = txtEmail.Text;
            }
            else
            {
                DR["EMAIL"] = DBNull.Value;
            }

            SqlCommandBuilder cmd = new SqlCommandBuilder(DA);

            try
            {
                DA.Update(DT_Update);
                string ret = "";
                HRMWebService.HRMWebService ws = new HRMWebService.HRMWebService();
                ws.Url = OPM_BL.GetSysconfig("OPMWebServiceURL");
                ws.Timeout = 10000;
                ret = ws.HRMUpdatePerson(LoginUserData.getLoginPerIdDPIS(Request), txtTEL.Text.Trim(), txtFAX.Text.Trim(), txtMOBILE.Text.Trim(), txtTEL_ORG.Text.Trim(), txtTEL_ORG_EXT.Text.Trim(), txtEmail.Text.Trim());

                li_tab1.Attributes["class"] = "";
                tabpage1.Attributes["class"] = "tab-pane";
                pnlDialog.Visible = false;
            }
            catch (Exception ex)
            {
            }

        }
    }
Пример #6
0
    protected void SaveAll(string CCode, string pCode, string assign, string IsAuto)
    {
        string ACT_ORG_SERIAL = null;

        //if (txtPerson_ActORG.Text == "")
        //{
        String SQL = " select ACT_ORG_SERIAL org_serial ,com_code,Pos_ID,PER_TYPE from CTLT_COMMAND_LINE where com_code='" + pCode + "'  ";
        SqlDataAdapter DA = new SqlDataAdapter(SQL, OPM_BL.DefaultConnectionString);
        DataTable DT = new DataTable();
        DA.Fill(DT);
        if (DT.Rows.Count == 1)
        {
            if (DT.Rows[0]["Pos_ID"].ToString() != "")  // ตำแหน่งจริง
            {
                //SqlDataAdapter DA_St = new SqlDataAdapter(" select org_serial,Pos_ID,PER_TYPE from PSST_POSITION where Pos_ID='" + DT.Rows[0]["Pos_ID"].ToString() + "' AND PER_TYPE='" + DT.Rows[0]["PER_TYPE"].ToString() + "' ", OPM_BL.DefaultConnectionString);
                //DataTable DT_St = new DataTable();
                //DA_St.Fill(DT_St);
                //if (DT_St.Rows.Count == 1)
                //{
                //    ACT_ORG_SERIAL = DT_St.Rows[0]["org_serial"].ToString();
                //}

                if (cb_ORG_Help.Value == "" || cb_ORG_Help.SelectedIndex == -1 || cb_ORG_Help.Value == "A0000")
                {
                    // ยังไม่กำหนดหน่วยงานที่ช่วย
                    ACT_ORG_SERIAL = "null";
                }
                else
                {
                    // กำหนดหน่วยงานที่ช่วย
                    ACT_ORG_SERIAL = cb_ORG_Help.Value.ToString();       //หน่วยงานที่เลือก

                }
            }
            else
            {

                if (cb_ORG_Help.Value == "" || cb_ORG_Help.SelectedIndex == -1 || cb_ORG_Help.Value  == "A0000")
                {
                    // ยังไม่กำหนดหน่วยงานที่ช่วย
                    ACT_ORG_SERIAL = "null";
                }
                else
                {
                    // กำหนดหน่วยงานที่ช่วย
                    ACT_ORG_SERIAL = cb_ORG_Help.Value.ToString ();       //หน่วยงานที่เลือก

                }
            }

        }
        //}

        bool result = false;
        SqlConnection conn = null;

        using (TransactionScope scope = new TransactionScope())
        {

            //if (lbl_title_dialog.Text == "กำหนด")
            //{
                try
                {
                    conn = new SqlConnection(OPM_BL.DefaultConnectionString);
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    String CommandText_IsAuto = " ";
                    if (IsAuto == "Y")
                    {
                        CommandText_IsAuto = "";
                    }
                    else {
                        CommandText_IsAuto = " ,ACT_ORG_SERIAL=" + ACT_ORG_SERIAL;

                    }

                        if (assign.ToString() == "")
                        {
                            //cmd.CommandText = string.Format("UPDATE [CTLT_COMMAND_LINE] SET [PARENT_COM_CODE] ={0} ,ACT_ORG_SERIAL=" + ACT_ORG_SERIAL + "  WHERE [COM_CODE] = {1}", pCode, CCode);

                            cmd.CommandText = string.Format("UPDATE [CTLT_COMMAND_LINE] SET [PARENT_COM_CODE] ={0} " + CommandText_IsAuto + "  WHERE [COM_CODE] = {1}", pCode, CCode);
                        }
                        else
                        {
                            if (assign.ToString() == "A0000")   // กำหนดเป็นตำแหน่งว่าง
                            {
                                cmd.CommandText = string.Format("UPDATE [CTLT_COMMAND_LINE] SET [PARENT_COM_CODE] ={0}  , ID=null,ACT_ORG_SERIAL=null WHERE [COM_CODE] = {1}", pCode, CCode);

                            }
                            else
                            {
                                // กำหนด คนลงตำแหน่ง
                            }
                            {
                                //cmd.CommandText = string.Format("UPDATE [CTLT_COMMAND_LINE] SET [PARENT_COM_CODE] ={0}  , ID='" + assign + "',ACT_ORG_SERIAL='" + ACT_ORG_SERIAL + "' WHERE [COM_CODE] = {1}", pCode, CCode);
                                cmd.CommandText = string.Format("UPDATE [CTLT_COMMAND_LINE] SET [PARENT_COM_CODE] ={0}  , ID='" + assign + "' " + CommandText_IsAuto + " WHERE [COM_CODE] = {1}", pCode, CCode);

                            }

                        }

                        cmd.CommandType = CommandType.Text;
                        if (conn.State == ConnectionState.Closed) conn.Open();

                        result = Convert.ToBoolean(cmd.ExecuteNonQuery());
                        scope.Complete();

                        DataRow dr = TreeDataSource.AsEnumerable().Where(r => (r["COM_CODE"] + "" == CCode)).First();
                        dr["PARENT_COM_CODE"] = pCode;
                        JS = "alert('บันทึก');";

                }
                catch (Exception ex)
                {
                }
                finally
                {
                    conn.Close();
                    scope.Dispose();

                }

            //}
            //else if (lbl_title_dialog.Text == "เพิ่มตำแหน่งช่วย")
            //{
            //    try
            //    {
            //        // เพิ่มตำแหน่งช่วย
            //        String New_Com_Code = OPM_BL.GetNewID("CTLT_COMMAND_LINE", "COM_CODE");
            //        String insert_SQL = "";

            //        insert_SQL = "";
            //        insert_SQL += " INSERT INTO CTLT_COMMAND_LINE ";
            //        insert_SQL += " (COM_CODE ,POS_ID ,PER_TYPE ,PARENT_COM_CODE ,USER_ID ,LAST_DATE ";
            //        insert_SQL += " ,ID ,ACT_ORG_SERIAL ,BOSS_FLAG ,ISFOLDER ,COM_LEVEL) ";
            //        insert_SQL += " VALUES ";
            //        insert_SQL += " (" + New_Com_Code + " ";
            //        insert_SQL += " ,null ,null ";
            //        insert_SQL += " ," + pCode + " ";
            //        insert_SQL += " ,'" + user_Code + "'";
            //        //insert_SQL += " ,null" +  " ";
            //        insert_SQL += " ,'" + DateTime.Now.ToString("yyyy/MM/dd") + "' ";
            //        if (assign.ToString() == "A0000")
            //        {
            //            insert_SQL += " ,null ";
            //        }
            //        else
            //        {
            //            insert_SQL += " ," + assign + " ";
            //        }
            //        insert_SQL += " ," + ACT_ORG_SERIAL + " ";
            //        insert_SQL += " ,'Y','N' ,null) ";
            //        SqlDataAdapter DA_insert = new SqlDataAdapter(insert_SQL, OPM_BL.DefaultConnectionString);
            //        DataTable DT_insert = new DataTable();
            //        DA_insert.Fill(DT_insert);
            //        //string rt = OPM_BL.ExecuteNoneQuery(insert_SQL, null );
            //    }
            //    catch (Exception ex)
            //    {
            //    }

            //}

            //try
            //{
            //    conn = new SqlConnection(OPM_BL.DefaultConnectionString);
            //    SqlCommand cmd = new SqlCommand();
            //    cmd.Connection = conn;
            //    if (lbl_title_dialog.Text  == "กำหนด")
            //    {
            //        // เปลี่ยนผู้บังคับบัญชา  แก้ไขตำแหน่งลอย

            //    //}
            //    //else if (Mode == "เพิ่มตำแหน่งช่วย")
            //    //{
            //    //    // เพิ่มตำแหน่งช่วย

            //    //}

            //    if (assign.ToString() == "")
            //    {

            //        cmd.CommandText = string.Format("UPDATE [CTLT_COMMAND_LINE] SET [PARENT_COM_CODE] ={0} ,ACT_ORG_SERIAL='" + ACT_ORG_SERIAL + "'  WHERE [COM_CODE] = {1}", pCode, CCode);
            //    }
            //    else
            //    {
            //        if (assign.ToString() == "A0000")
            //        {
            //            cmd.CommandText = string.Format("UPDATE [CTLT_COMMAND_LINE] SET [PARENT_COM_CODE] ={0}  , ID=null,ACT_ORG_SERIAL=null WHERE [COM_CODE] = {1}", pCode, CCode);

            //        }
            //        else
            //        {
            //            cmd.CommandText = string.Format("UPDATE [CTLT_COMMAND_LINE] SET [PARENT_COM_CODE] ={0}  , ID='" + assign + "',ACT_ORG_SERIAL='" + ACT_ORG_SERIAL + "' WHERE [COM_CODE] = {1}", pCode, CCode);

            //        }

            //    }

            //    cmd.CommandType = CommandType.Text;
            //    if (conn.State == ConnectionState.Closed) conn.Open();

            //    result = Convert.ToBoolean(cmd.ExecuteNonQuery());
            //    scope.Complete();

            //    DataRow dr = TreeDataSource.AsEnumerable().Where(r => (r["COM_CODE"] + "" == CCode)).First();
            //    dr["PARENT_COM_CODE"] = pCode;
            //    JS = "alert('บันทึก');";

            //    }
            //    else if (lbl_title_dialog.Text  == "เพิ่มตำแหน่งช่วย")
            //    {
            //        // เพิ่มตำแหน่งช่วย
            //        String  New_Com_Code = OPM_BL.GetNewID("CTLT_COMMAND_LINE", "COM_CODE");
            //        String insert_SQL = "";

            //        insert_SQL = "";
            //        insert_SQL += " INSERT INTO CTLT_COMMAND_LINE ";
            //        insert_SQL += " (COM_CODE ,POS_ID ,PER_TYPE ,PARENT_COM_CODE ,USER_ID ,LAST_DATE ";
            //        insert_SQL += " ,ID ,ACT_ORG_SERIAL ,BOSS_FLAG ,ISFOLDER ,COM_LEVEL) ";
            //        insert_SQL += " VALUES ";
            //        insert_SQL += " (" + New_Com_Code + " ";
            //        insert_SQL += " ,null ,null ";
            //        insert_SQL += " ," + pCode + " ";
            //        insert_SQL += " ,'" + user_Code + "'";
            //        insert_SQL += " ," + DateTime.Now.ToString("yyyy/MM/dd") + " ";

            //       if (assign.ToString() == "A0000")
            //       {
            //           insert_SQL += " ,null ";
            //       }
            //       else
            //       {
            //           insert_SQL += " ," + assign + " ";
            //       }
            //       insert_SQL += " ," + ACT_ORG_SERIAL + " ";
            //       insert_SQL +=  " ,'Y','N' ,null) ";

            //       SqlDataAdapter da = new SqlDataAdapter(insert_SQL, OPM_BL .DefaultConnectionString );
            //       DataTable dt = new DataTable();
            //       da.Fill(dt);

            //    }

            //    //cmd.CommandType = CommandType.Text;

            //    //if (conn.State == ConnectionState.Closed) conn.Open();

            //    //result = Convert.ToBoolean(cmd.ExecuteNonQuery());
            //    //scope.Complete();

            //    //DataRow dr = TreeDataSource.AsEnumerable().Where(r => (r["COM_CODE"] + "" == CCode)).First();
            //    //dr["PARENT_COM_CODE"] = pCode;
            //    //JS = "alert('บันทึก');";

            //}
            //catch (Exception ex)
            //{
            //}
            //finally
            //{
            //    conn.Close();
            //    scope.Dispose();

            //}
        }

        LogFileEng.SaveActionTransLog("ODS_UT0407", "UPDATE", "กำหนดผู้บังคับบัญชา COM_CODE :" + CCode, "CTLT_COMMAND_LINE", CCode, "", Request);

        //GetAllDataSource_Tree();
        //Update To OPM Oracle
        HRMWebService.HRMWebService ws = new HRMWebService.HRMWebService();
        ws.Timeout = 10000;
        ws.Url = OPM_BL.GetSysconfig("OPMWebServiceURL");
        string re = ws.SMMSaveCommandLine(Convert.ToInt64(CCode));
        ws.Dispose();
    }
Пример #7
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //----------check Validate------------

            if (string.IsNullOrEmpty(cmbPREFIX_TH.Text))
            {
                OPM_BL.SetAlertComboBox(this.Page, "เลือกคำนำหน้า", cmb_PER_STATUS);
                return ;
            }

            if (string.IsNullOrEmpty(txtNAME_TH.Text) || string.IsNullOrEmpty(txtSURNAME_TH.Text))
            {
                OPM_BL.SetAlertComboBox(this.Page, "กรอกรายละเอียดชื่อภาษาไทย", cmb_PER_STATUS);
                return;
            }

            if (string.IsNullOrEmpty(txtNAME_ENG .Text) || string.IsNullOrEmpty(txtSURNAME_ENG.Text))
            {
                OPM_BL.SetAlertComboBox(this.Page, "กรอกรายละเอียดชื่อภาษาอังกฤษ", cmb_PER_STATUS);
                return;
            }

            if (txtSTART_DATE.DateValue.ToString("yyyy-MM-dd", ct_en) == "0001-01-01")
            {
                OPM_BL.SetAlertComboBox(this.Page, "เลือกวันที่เริ่ม", cmb_PER_STATUS);
                return;
            }
            if (txtRETIRE_DATE.DateValue.ToString("yyyy-MM-dd", ct_en) == "0001-01-01")
            {
                OPM_BL.SetAlertComboBox(this.Page, "เลือกวันที่สิ้นสุด", cmb_PER_STATUS);
                return;
            }

            if (string.IsNullOrEmpty(txtID_CARD.Text))
            {
                OPM_BL.SetAlertComboBox(this.Page, "กรอกเลขประจำตัวประชาชน", cmb_PER_STATUS);
                return;
            }

            if (txtID_CARD.Text.Length < 13)
            {
                OPM_BL.SetAlertComboBox(this.Page, "กรอกเลขประจำตัวประชาชน 13 หลัก", cmb_PER_STATUS);
                return;
            }

            if (VerifyPeopleID(txtID_CARD.Text))
            {
                //OPM_BL.SetAlertComboBox(this.Page, "รหัสบัตรประชาชนถูกต้อง", cmb_PER_STATUS);
            }
            else
            {
                OPM_BL.SetAlertTextBox(this.Page, "รหัสบัตรประชาชนไม่ถูกต้อง", txtID_CARD);
            }

            if (txtBORN_DATE.DateValue.ToString("yyyy-MM-dd", ct_en) == "0001-01-01")
            {
                OPM_BL.SetAlertComboBox(this.Page, "เลือกวันเดือนปี เกิด", cmb_PER_STATUS);
                return;
            }

            //if (string.IsNullOrEmpty(txtMOBILE.Text))
            //{
            //    OPM_BL.SetAlertComboBox(this.Page, "กรอกมือถือ", cmb_PER_STATUS);
            //    return;
            //}

            //OPM_BL.SetAlertComboBox(this.Page, "บันทึกเรียบร้อย", cmb_PER_STATUS);

            //if (string.IsNullOrEmpty(txtNAME_TH.Text) || string.IsNullOrEmpty(txtSURNAME_TH.Text))
            //{
                //ScriptManager.RegisterStartupScript(this.Page, typeof(string), "Alert", "showAlert('กรอกรายละเอียดชื่อภาษาไทย');", true);
                //return;
            //}

        try{

            //----------Save PSST_PERSON----------
            string SQL = "";
            SQL = " SELECT * \n";
            SQL += "  FROM PSST_PERSON \n";

            switch (PSN_ID)
            {
                case null:
                    SQL += " WHERE 0=1";
                    PSN_ID = OPM_BL.GetNewID("PSST_PERSON", "ID");
                    break;
                default:
                    SQL += " WHERE ID='" + PSN_ID + "'";
                    break;
            }

            SqlDataAdapter DA = OPM_BL.GetNewSqlDataAdapter(SQL);
            DataTable DT = new DataTable();
            DA.Fill(DT);
            DataRow DR = null;
            if (DT.Rows.Count == 0)
            {
                DR = DT.NewRow();
                DR["ID"] = PSN_ID;
                DR["ID_CARD"] = txtID_CARD.Text;
            }
            else
            {
                DR = DT.Rows[0];
                DR["ID_CARD"] = txtID_CARD.Text;
            }
            DR["PER_TYPE"] = cmbPER_TYPE.Value;
            if (cmbPREFIX_TH.SelectedIndex != -1)
            {
                DR["PREFIX_CODE"] = cmbPREFIX_TH.Value;
            }
            DR["NAME"] = txtNAME_TH.Text;
            DR["SURNAME"] = txtSURNAME_TH.Text;
            DR["NAME_ENG"] = txtNAME_ENG.Text;
            DR["SURNAME_ENG"] = txtSURNAME_ENG.Text;

            if (cmb_ORG.SelectedIndex != -1) //หน่วยงาน
            {
                DR["PER_ORG_SERIAL"] = cmb_ORG.Value;
            }
            if (cmb_POS.SelectedIndex != -1)
            {
                DR["PER_LINE_CODE"] = cmb_POS.Value;
            }

            if (txtSTART_DATE.DateValue.ToString("yyyy-MM-dd", ct_en) != "0001-01-01")
            {
                DR["START_DATE"] = Convert.ToDateTime(txtSTART_DATE.Value);
                DR["ENTER_DATE"] = Convert.ToDateTime(txtSTART_DATE.Value);
            }
            if (txtRETIRE_DATE.DateValue.ToString("yyyy-MM-dd", ct_en) != "0001-01-01")
            {
                DR["RETIRE_DATE"] = Convert.ToDateTime(txtRETIRE_DATE.Value);
            }

            if (cmb_PER_STATUS.SelectedIndex != -1)
            {
                DR["PER_STATUS"] = cmb_PER_STATUS.Value;
            }

            //---------------------------------------

            if (rdSEX.SelectedIndex != -1)
            {
                DR["SEX"] = rdSEX.SelectedIndex + 1;
            }

            if (txtBORN_DATE.DateValue.ToString("yyyy-MM-dd", ct_en) != "0001-01-01")
            {
                DR["BORN_DATE"] = Convert.ToDateTime(txtBORN_DATE.Value);
            }

            DR["ADDRESS"] = txtAddress.Text;

            DR["LOC_SERIAL"] = DBNull.Value;
            if (cmb_DIST.SelectedIndex != -1)
            {
                DR["LOC_SERIAL"] = cmb_DIST.Value;
            }
            else if (cmb_AMP.SelectedIndex != -1)
            {
                DR["LOC_SERIAL"] = cmb_AMP.Value;
            }
            else if (cmb_PROV.SelectedIndex != -1)
            {
                DR["LOC_SERIAL"] = cmb_PROV.Value;
            }

            DR["POST_CODE"] = txtPOST_CODE.Text;
            DR["TEL"] = txtTEL.Text;
            DR["FAX"] = txtFAX.Text;
            DR["MOBILE"] = txtMOBILE.Text;
            DR["EMAIL"] = txtEMAIL.Text;
            DR["TEL_ORG"] = txtTEL_ORG.Text;
            DR["TEL_ORG_EXT"] = txtTEL_ORG_EXT.Text;
            //DR["USER_ID"] = Session["USER_PSNL_NO"];
            DR["LAST_DATE"] = DateTime.Now;

            if (DT.Rows.Count == 0)
                DT.Rows.Add(DR);
            SqlCommandBuilder cmd = new SqlCommandBuilder(DA);
            try
            {
                DA.Update(DT);

                HRMWebService.HRMWebService ws = new HRMWebService.HRMWebService();
                ws.Timeout = 10000;
                ws.Url = OPM_BL.GetSysconfig("OPMWebServiceURL");

                string ret = ws.HRMSaveOPMPerson(Convert.ToInt64(PSN_ID));
                ws.Dispose();

            }
            catch (Exception ex)
            {
            }

            //----------Save File--------
            //if (Avatar.ImageUrl != "~/images/NoImage.png")
            //{
            //string fileName = Path.GetFileName(avatarUpload.PostedFile.FileName);
            //avatarUpload.PostedFile.SaveAs(Server.MapPath("~/ImagesPSN/") + PSN_ID);
            //Response.Redirect(Request.Url.AbsoluteUri);

            string path = Server.MapPath("~/TempImageHRM");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string pathfile = Server.MapPath("~/TempImageHRM/");
            string extension = Path.GetExtension(avatarUpload.PostedFile.FileName);
            int fileSize = avatarUpload.PostedFile.ContentLength;

            string PER_ID_DPIS = OPM_BL.GetPSN_ID_DPIS(PSN_ID);
            string PER_PICSEQ_ORA = OPM_BL.getPIC_DPIS_SEQ(PER_ID_DPIS);

        try
            {
            SQL = "";
            //SQL = " SELECT * FROM HRM_File WHERE File_ID='" + PER_ID_DPIS + "'";
            SQL = " SELECT TOP 1 * FROM HRM_File WHERE ID_CARD='" + txtID_CARD.Text + "'  ORDER BY PER_PICSEQ DESC";
            DA = new SqlDataAdapter(SQL,OPM_BL.DefaultConnectionString);
            DT = new DataTable();
            DA.Fill(DT);
            DR = null;
            string PER_PICSEQ= string.Empty;
            //DT.Rows[0]["PER_PICSEQ"].ToString();

            if (DT.Rows.Count > 0)
            {
                PER_PICSEQ = chk_SEQ(DT.Rows[0]["PER_PICSEQ"].ToString(), PER_PICSEQ_ORA);
            }
            else
            {
                PER_PICSEQ = chk_SEQ("000", PER_PICSEQ_ORA);
            }

            if (DT.Rows.Count == 0)
            {
                DR = DT.NewRow();
                DR["File_ID"] = OPM_BL.GetNewID("HRM_File", "File_ID");
                DR["ID_CARD"] = txtID_CARD.Text;
            }
            else {
                DR = DT.Rows[0];
            }
            if (extension == "")
            {
                DR["Content_Type"] = "";
            }
            else {
                DR["Content_Type"] = avatarUpload.PostedFile.ContentType;
            }
            DR["File_Size"] = fileSize;
            DR["PER_PICSEQ"] = PER_PICSEQ;
            DR["PSN_ID"] = PSN_ID ;
            if (DT.Rows.Count == 0)
                DT.Rows.Add(DR);
            cmd = new SqlCommandBuilder(DA);

                DA.Update(DT);
                if (avatarUpload.HasFile)
                {
                    avatarUpload.SaveAs(pathfile + txtID_CARD.Text + extension);
                }
            }
            catch (Exception ex)
            {
            }

        if (cmb_POS.Value != null)
        {

            //----------Clear ตำแหน่งเดิมกรรมีการเปลี่ยรร ตำแหน่ง PSST_POSITION--------
            //lblOld_POS_ID.Text = (drv["POS_ID"].ToString()); //เก็บ รหัสตำแหน่ง กรณีแก้ไขเปลี่ยนตำแหน่ง จะได้เคลีย พนักงานออกจากตำแหน่งเดิม

            if ((cmb_POS.Value.ToString() != lblOld_POS_ID.Text) && lblOld_POS_ID.Text !="" ){

                string SQL_Clear_POS = "";
                SQL_Clear_POS = "  UPDATE PSST_POSITION  \n";
                SQL_Clear_POS += " SET ID = NULL    \n";
                SQL_Clear_POS += " WHERE POS_ID='" + lblOld_POS_ID.Text + "' AND PER_TYPE='" + cmb_PER_STATUS.Value + "'  \n";
                SqlDataAdapter DA_Clear_POS = new SqlDataAdapter(SQL_Clear_POS, OPM_BL.DefaultConnectionString);
                DataTable DT_Clear_POS = new DataTable();
                DA_Clear_POS.Fill(DT_Clear_POS);

                string SQL_Clear_COMMAND = "";
                SQL_Clear_COMMAND = "  UPDATE CTLT_COMMAND_LINE  \n";
                SQL_Clear_COMMAND += " SET ID = NULL ,   \n";
                SQL_Clear_COMMAND += " ACT_ORG_SERIAL = NULL ,   \n";
                SQL_Clear_COMMAND += " LAST_DATE = getdate()     \n";
                SQL_Clear_COMMAND += " WHERE POS_ID='" + lblOld_POS_ID.Text + "' AND PER_TYPE='" + cmb_PER_STATUS.Value + "'  \n";
                SqlDataAdapter DA_Clear_COMMAND = new SqlDataAdapter(SQL_Clear_COMMAND, OPM_BL.DefaultConnectionString);
                DataTable DT_Clear_COMMAND = new DataTable();
                DA_Clear_COMMAND.Fill(DT_Clear_COMMAND);
            }

            //----------Save PSST_POSITION--------
            string SQL_POSITION = "";
            SQL_POSITION = " SELECT * \n";
            SQL_POSITION += "  FROM PSST_POSITION WHERE POS_ID='" + cmb_POS.Value + "'  \n";
            SqlDataAdapter DA_POSITION = new SqlDataAdapter(SQL_POSITION,OPM_BL.DefaultConnectionString);
            DataTable DT_POSITION = new DataTable();
            DA_POSITION.Fill(DT_POSITION);
            DataRow DR_POSITION = null;
            if (DT_POSITION.Rows.Count == 1)
            {
                // เพิ่มพนักงานให้กับตำแหน่งว่าง
                DR_POSITION = DT_POSITION.Rows[0];
                DR_POSITION["ID"] = PSN_ID;
            }
            SqlCommandBuilder cmd_POSITION = new SqlCommandBuilder(DA_POSITION);
            DA_POSITION.Update(DT_POSITION);

            //----------Save CTLT_COMMAND_LINE--------
            string SQL_CTLT_COMMAND_LINE = "";
            SQL_CTLT_COMMAND_LINE = " SELECT * \n";
            SQL_CTLT_COMMAND_LINE += "  FROM CTLT_COMMAND_LINE WHERE POS_ID='" + cmb_POS.Value + "' AND PER_TYPE ='"+ cmbPER_TYPE.Value +"'  \n";
            SqlDataAdapter DA_CTLT_COMMAND_LINE = new SqlDataAdapter(SQL_CTLT_COMMAND_LINE, OPM_BL.DefaultConnectionString);
            DataTable DT_CTLT_COMMAND_LINE = new DataTable();
            DA_CTLT_COMMAND_LINE.Fill(DT_CTLT_COMMAND_LINE);
            DataRow DR_CTLT_COMMAND_LINE = null;
            if (DT_CTLT_COMMAND_LINE.Rows.Count == 1)
            {
                // เพิ่มพนักงานให้กับตำแหน่งว่าง
                DR_CTLT_COMMAND_LINE = DT_CTLT_COMMAND_LINE.Rows[0];
                DR_CTLT_COMMAND_LINE["ID"] = PSN_ID;
                DR_CTLT_COMMAND_LINE["ACT_ORG_SERIAL"] = cmb_ORG.Value.ToString();
                DR_CTLT_COMMAND_LINE["LAST_DATE"] =  DateTime.Now;
            }
            SqlCommandBuilder cmd_CTLT_COMMAND_LINE = new SqlCommandBuilder(DA_CTLT_COMMAND_LINE);
            DA_CTLT_COMMAND_LINE.Update(DT_CTLT_COMMAND_LINE);
        }

            // ตรวจสอบการอัพเดท CTLT_EMP
        string SQL_Emp = "";
        SQL_Emp = " SELECT * \n";
        SQL_Emp += "  FROM CTLT_EMP WHERE EMP_ID='" + PSN_ID + "' \n";
        SqlDataAdapter DA_Emp = OPM_BL.GetNewSqlDataAdapter(SQL_Emp);
        DataTable DT_Emp = new DataTable();
        DA_Emp.Fill(DT_Emp);
        if (DT_Emp.Rows.Count== 0){

                    //---------------เพิ่ม User ลง CTT_EMP
                    long EMP_ID = GL.CINT(PSN_ID);
                    string GenUserName = AutoGenUserName(txtNAME_ENG.Text, txtSURNAME_ENG.Text, EMP_ID);

                    if (GenUserName != "")
                    {
                        string UserPwd = encryptPwd(GenUserName);

                        //DataRow dr = dt.Rows[0];
                        string sql = " insert into ctlt_emp (user_code,user_login,emp_id,user_pwd, user_efft_date, user_exp_date)";
                        sql += " values (@_USER_CODE,@_USER_LOGIN,@_EMP_ID,@_USER_PWD,getdate(),@_USER_EXP_DATE)";

                        SqlParameter[] p = new SqlParameter[5];
                        p[0] = OPM_BL.setParameter("@_USER_CODE", SqlDbType.VarChar, GenUserName);
                        p[1] = OPM_BL.setParameter("@_USER_LOGIN", SqlDbType.VarChar, GenUserName);
                        p[2] = OPM_BL.setParameter("@_EMP_ID", SqlDbType.BigInt, EMP_ID);
                        p[3] = OPM_BL.setParameter("@_USER_PWD", SqlDbType.VarChar, UserPwd);

                        if (txtRETIRE_DATE.DateValue.ToString("yyyy-MM-dd", ct_en) != "0001-01-01")
                        {
                            p[4] = OPM_BL.setParameter("@_USER_EXP_DATE", SqlDbType.DateTime, Convert.ToDateTime(txtRETIRE_DATE.Value));
                        }
                        else
                        {
                            p[4] = OPM_BL.setParameter("@_USER_EXP_DATE", SqlDbType.DateTime, DBNull.Value);

                        }
                        OPM_BL.ExecuteNoneQuery(sql, p);
                    }
        }

            LogFileEng.SaveActionTransLog("HRM_UT0301", "UPDATE", "บันทึกข้อมูลพนักงาน ID='" + PSN_ID + "'", "PSST_PERSON", "ID='" + PSN_ID + " ", "", Request);
            LogFileEng.SaveActionTransLog("HRM_UT0301", "UPDATE", "บันทึกข้อมูลตำแหน่งของพนักงาน ID='" + PSN_ID + "'", "PSST_POSITION", "POS_ID='" + cmb_POS.Value+ " ", "", Request);

            OPM_BL.SetAlertComboBox(this.Page, "บันทึกเรียบร้อย",cmb_PER_STATUS);
                }
                catch (Exception ex)
                {
                    OPM_BL.SetAlertComboBox(this.Page, "ไม่สามารถบันทึกได้", cmb_PER_STATUS);

                }
            Response.Redirect("PSST_PERSON_ListView.aspx");
    }
Пример #8
0
    public static bool ApproveLeaveData(Control page, TextBox txtSendDate, DateTime SendDateValue, long vLeaveID, HttpRequest req, string Leave_Status)
    {
        bool result = false;
        try
        {
            string sql = " update hrm_leave_his_approver";
            sql += " set approve_status=@_LEAVE_STATUS";
            sql += " ,approve_date=@_APPROVE_DATE";
            sql += " where leave_his_id=@_LEAVE_HIS_ID";
            sql += " and person_id_approve=@_PERSON_ID";
            SqlParameter[] param = new SqlParameter[4];
            //param[0] = OPM_BL.setParameter("@_LEAVE_STATUS", SqlDbType.VarChar, "1");
            param[0] = OPM_BL.setParameter("@_LEAVE_STATUS", SqlDbType.VarChar, Leave_Status.ToString());

            param[1] = OPM_BL.setParameter("@_APPROVE_DATE", SqlDbType.Date, SendDateValue);
            param[2] = OPM_BL.setParameter("@_LEAVE_HIS_ID", SqlDbType.BigInt, vLeaveID);
            param[3] = OPM_BL.setParameter("@_PERSON_ID", SqlDbType.BigInt, Convert.ToInt64(LoginUserData.getLoginUserID(req)));

            string ret = OPM_BL.ExecuteNoneQuery(sql, param);
            if (ret != "true")
            {
                OPM_BL.SetAlertTextDate(page, ret, txtSendDate);
                result = false;
            }
            else
            {
                //ตรวจว่า ผู้อนุญาตทำการ อนุญาตครบแล้วทุกคน
                sql = "select id, approve_status ";
                sql += " from hrm_leave_his_approver";
                sql += " where leave_his_id=@_LEAVE_HIS_ID";
                param = new SqlParameter[1];
                param[0] = OPM_BL.setParameter("@_LEAVE_HIS_ID", SqlDbType.BigInt, vLeaveID);

                DataTable dt = OPM_BL.GetDatatable(sql, param);
                if (dt.Rows.Count > 0)
                {
                    int totAppQty = dt.Rows.Count;   //จำนวนผู้อนุญาตทั้งหมด

                    dt.DefaultView.RowFilter = "approve_status='1'";   //จำนวนผู้คลิกอนุญาตแล้ว
                    if (totAppQty == dt.DefaultView.Count)
                    {
                        sql = "update hrm_leave_his";
                        sql += " set leave_status=@_LEAVE_STATUS";
                        sql += " ,comm_date = @_APPROVE_DATE";
                        sql += " ,comm_date_active = @_APPROVE_DATE";
                        sql += " output inserted.leave_day, inserted.leave_id,inserted.person_id,inserted.budget_year, inserted.start_date, inserted.end_date";
                        sql += " where id=@_ID";

                        param = new SqlParameter[3];
                        param[0] = OPM_BL.setParameter("@_LEAVE_STATUS", SqlDbType.VarChar, "3");  //อนุญาตแล้ว
                        //param[0] = OPM_BL.setParameter("@_LEAVE_STATUS", SqlDbType.VarChar, Leave_Status.ToString());  //อนุญาตแล้ว

                        param[1] = OPM_BL.setParameter("@_APPROVE_DATE", SqlDbType.Date, SendDateValue);
                        param[2] = OPM_BL.setParameter("@_ID", SqlDbType.BigInt, vLeaveID);

                        DataTable lDt = OPM_BL.GetDatatable(sql, param);
                        if (lDt.Rows.Count == 0)
                        {
                            OPM_BL.SetAlertTextDate(page, ret, txtSendDate);
                            result = false;
                        }
                        else
                        {
                            //กรณีเป็นการลาพักผ่อน และได้ทำการคลิกอนุญาติครบทุกคนแล้ว
                            //ให้ไป Update ข้อมูลการลาพักผ่อนสะสมด้วย
                            if (lDt.Rows[0]["leave_id"].ToString() == "4")
                            {
                                //Update HRM_SUM_VACATION
                                sql = "update HRM_SUM_VACATION";
                                sql += " set leave_rest = leave_rest+@_LEAVE_QTY";
                                sql += " where person_id=@_PERSON_ID";
                                sql += " and budget_year=@_BUDGET_YEAR";

                                param = new SqlParameter[3];
                                param[0] = OPM_BL.setParameter("@_LEAVE_QTY", SqlDbType.Float, Convert.ToDouble(lDt.Rows[0]["leave_day"]));
                                param[1] = OPM_BL.setParameter("@_PERSON_ID", SqlDbType.BigInt, Convert.ToInt64(lDt.Rows[0]["person_id"]));
                                param[2] = OPM_BL.setParameter("@_BUDGET_YEAR", SqlDbType.Int, Convert.ToInt16(lDt.Rows[0]["budget_year"]));

                                ret = OPM_BL.ExecuteNoneQuery(sql, param);
                                if (ret == "true")
                                {
                                    result = true;
                                }
                                else
                                {
                                    OPM_BL.SetAlertTextDate(page, ret, txtSendDate);
                                    result = false;
                                }
                            }
                            else
                            {
                                result = true;
                            }

                            if (result == true)
                            {
                                // กรณี--1 ลาป่วย, 3 ลากิจ, 4 ลาพักผ่อน  ให้อัพเดทข้อมูลไปยัง DPIS ด้วย
                                switch (lDt.Rows[0]["leave_id"].ToString())
                                {
                                    case "1": //ลาป่วย
                                    case "3": //ลากิจ
                                    case "4": //ลาพักผ่อน
                                        //Update ข้อมูลไปยัง DPIS ผ่าน Web service
                                        HRMWebService.HRMWebService ws = new HRMWebService.HRMWebService();
                                        ws.Url = OPM_BL.GetSysconfig("OPMWebServiceURL");
                                        ws.Timeout = 10000;

                                        if (ws.SendLeaveDataToDPIS(vLeaveID) == "true")
                                        {
                                            result = true;
                                        }
                                        else
                                        {
                                            result = false;
                                        }
                                        ws.Dispose();

                                        break;
                                }

                                //Insert Job เพื่อให้ทำการ Process ตอนเที่ยงคืน
                                DateTime lStartDate = Convert.ToDateTime(lDt.Rows[0]["start_date"]).Date;
                                DateTime lEndDate = Convert.ToDateTime(lDt.Rows[0]["end_date"]).Date;
                                DateTime lCurrDate = lStartDate;
                                do
                                {
                                    if (lCurrDate.Date < DateTime.Now.Date)
                                    {
                                        PSSTTimeProcessENG.SetJobTimeProcess(LoginUserData.getLoginUserID(req), "ApproveLeaveData", vLeaveID.ToString(), Convert.ToInt64(lDt.Rows[0]["person_id"]), lCurrDate);
                                    }
                                }
                                while (lCurrDate <= lEndDate);
                            }
                        }
                    }
                    else
                    {
                        result = true;
                    }
                }
                dt.Dispose();
            }
        }
        catch (Exception ex)
        {
            result = false;
        }

        return result;
    }
    private string Save()
    {
        string ret = "";

        SqlConnection conn = new SqlConnection(OPM_BL.StaticDefaultConnectionString);
        conn.Open();

        SqlTransaction trans;
        trans = conn.BeginTransaction();

        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandTimeout = 240;
        cmd.Transaction = trans;
        string sql = "";

        try
        {

            string pos_id = "0";

            #region "PSST_POSITION"
            pos_id = OPM_BL.GetNewID("PSST_POSITION", "POS_ID", cmd);

            sql = "INSERT INTO PSST_POSITION(POS_ID,LINE_INORG,ORG_SERIAL,PER_TYPE,ID,POS_STATUS,CUR_LEV,USER_ID,LAST_DATE,REC_CODE,POS_DATE) " + Environment.NewLine;
            sql += " VALUES(@_POS_ID,@_LINE_INORG,@_ORG_SERIAL,@_PER_TYPE,@_ID,@_POS_STATUS,1,@_USER_ID,'" + DateTime.Now.ToString("yyyy/MM/dd") + "',@_REC_CODE,'" + DateTime.Now.ToString("yyyy/MM/dd") + "') ";

            SqlParameter[] param = new SqlParameter[8];
            param[0] = OPM_BL.setParameter("@_POS_ID", SqlDbType.VarChar, pos_id);  // running number
            param[1] = OPM_BL.setParameter("@_LINE_INORG", SqlDbType.VarChar, cmbPosName.Text);
            param[2] = OPM_BL.setParameter("@_ORG_SERIAL", SqlDbType.VarChar, cmb_ORG.Value.ToString());
            param[3] = OPM_BL.setParameter("@_PER_TYPE", SqlDbType.VarChar, cmd_PERTYPE.Value.ToString());
            if (cb_PER.Value != null)
            {
                param[4] = OPM_BL.setParameter("@_ID", SqlDbType.VarChar, cb_PER.Value.ToString());
            }
            else
            {
                param[4] = OPM_BL.setParameter("@_ID", SqlDbType.VarChar, DBNull.Value);
            }

            //
            string pos_status = "1";
            //if (chkActive.Checked == false) // เปลี่ยนมาใช้ Radio
            //{
            //    pos_status = "2";
            //}

            string _DEC_FLAG = (rdb_DEC_FLAG_USE.Checked == true) ? "Y" : "N";
            if (_DEC_FLAG == "Y")
            {
                rdb_DEC_FLAG_USE.Checked = true;
                pos_status = "1";
            }
            else
            {
                rdb_DEC_FLAG_None.Checked = true;
                pos_status = "2";
            }

            param[5] = OPM_BL.setParameter("@_POS_STATUS", SqlDbType.VarChar, pos_status);

            param[6] = OPM_BL.setParameter("@_USER_ID", SqlDbType.VarChar, user_Code);
            param[7] = OPM_BL.setParameter("@_REC_CODE", SqlDbType.VarChar, OPM_BL.GetNewID("PSST_POSITION","REC_CODE"));

            cmd.CommandText = sql;
            cmd.Parameters.Clear();
            foreach (SqlParameter p in param)
            {
                if (p != null)
                {
                    cmd.Parameters.Add(p);
                }
            }
            cmd.ExecuteNonQuery();

            #endregion

            string com_code = OPM_BL.GetNewID("CTLT_COMMAND_LINE", "COM_CODE", cmd);
            string parent_comcode = GetParentComCode(cmb_ORG.Value.ToString(),cmd);
            string user_id = LoginUserData.getLoginUserID(Request);
            sql ="INSERT INTO CTLT_COMMAND_LINE " + Environment.NewLine;
            sql += " ([COM_CODE] " + Environment.NewLine;
            sql += " ,[POS_ID] " + Environment.NewLine;
            sql += " ,[PER_TYPE] " + Environment.NewLine;
            sql += " ,[PARENT_COM_CODE] " + Environment.NewLine;
            sql += " ,[USER_ID] " + Environment.NewLine;
            sql += " ,[LAST_DATE]) " + Environment.NewLine;
            sql += " VALUES " + Environment.NewLine;
            sql += " (@_COM_CODE" + Environment.NewLine;
            sql += " ,@_POS_ID" + Environment.NewLine;
            sql += " ,@_PER_TYPE" + Environment.NewLine;
            sql += " ,@_PARENT_COM_CODE" + Environment.NewLine;
            sql += " ,@_USER_ID" + Environment.NewLine;
            sql += " ,@_LAST_DATE)";

            param = new SqlParameter[6];
            param[0] = OPM_BL.setParameter("@_COM_CODE", SqlDbType.VarChar, com_code);
            param[1] = OPM_BL.setParameter("@_POS_ID", SqlDbType.VarChar, pos_id);
            param[2] = OPM_BL.setParameter("@_PER_TYPE", SqlDbType.VarChar, cmd_PERTYPE.Value.ToString());
            param[3] = OPM_BL.setParameter("@_PARENT_COM_CODE", SqlDbType.VarChar, parent_comcode);
            param[4] = OPM_BL.setParameter("@_USER_ID", SqlDbType.VarChar, user_id);
            param[5] = OPM_BL.setParameter("@_LAST_DATE", SqlDbType.DateTime, DateTime.Now);
            cmd.CommandText = sql;
            cmd.Parameters.Clear();
            foreach (SqlParameter p in param)
            {
                if (p != null)
                {
                    cmd.Parameters.Add(p);
                }
            }
            cmd.ExecuteNonQuery();

            sql = "UPDATE  PSST_POSITION Set  COM_CODE= @_COM_CODE " + Environment.NewLine;
            sql += " WHERE  POS_ID= @_POS_ID AND PER_TYPE = @_PER_TYPE AND ORG_SERIAL=@_ORG_SERIAL" + Environment.NewLine;

            param = new SqlParameter[4];
            param[0] = OPM_BL.setParameter("@_COM_CODE", SqlDbType.VarChar, com_code);
            param[1] = OPM_BL.setParameter("@_POS_ID", SqlDbType.VarChar, pos_id);  // running number
            param[2] = OPM_BL.setParameter("@_ORG_SERIAL", SqlDbType.VarChar, cmb_ORG.Value.ToString());
            param[3] = OPM_BL.setParameter("@_PER_TYPE", SqlDbType.VarChar, cmd_PERTYPE.Value.ToString());

            cmd.CommandText = sql;
            cmd.Parameters.Clear();
            foreach (SqlParameter p in param)
            {
                if (p != null)
                {
                    cmd.Parameters.Add(p);
                }
            }
            cmd.ExecuteNonQuery();

            trans.Commit();
            ret = "true";

            LogFileEng.SaveActionTransLog("SMM_UT0302", "SAVE", "เพิ่มตำแหน่ง " + cmd_PERTYPE.Text + " POS_ID:" + pos_id, "PSST_POSITION", pos_id, "", Request);

            HRMWebService.HRMWebService ws = new HRMWebService.HRMWebService();
            ws.Timeout = 10000;
            ws.Url = OPM_BL.GetSysconfig("OPMWebServiceURL");
            string re = ws.SMMSavePosition(Convert.ToInt64(pos_id), cmd_PERTYPE.Value.ToString(), Convert.ToInt64(cmb_ORG.Value), Convert.ToInt64(com_code));
            ws.Dispose();

        }
        catch (Exception ex)
        {
            ret = "false|Exception " + ex.Message + "\n" + ex.StackTrace.ToString();
            trans.Rollback();

            string err = ex.ToString();
            if (ex.ToString().Length > 500)
            {
                err = ex.ToString().Substring(0, 499);
            }
            LogFileEng.SaveActionTransLog("SMM_UT0302", "SAVE", err, "PSST_POSITION", "", "", Request);
        }

        return ret;
    }