protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string strMessage   = string.Empty;
            string strCheck     = string.Empty;
            string strScript    = string.Empty;
            string strUpdatedBy = Session["username"].ToString();
            Label  lblperson_work_status_code       = (Label)GridView1.Rows[e.RowIndex].FindControl("lblperson_work_status_code");
            cPerson_work_status oPerson_work_status = new cPerson_work_status();

            try
            {
                if (!oPerson_work_status.SP_PERSON_WORK_STATUS_DEL(lblperson_work_status_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oPerson_work_status.Dispose();
            }
            BindGridView(0);
        }
        private void BindGridView(int nPageNo)
        {
            cPerson_work_status oPerson_work_status = new cPerson_work_status();
            DataSet             ds            = new DataSet();
            string strMessage                 = string.Empty;
            string strCriteria                = string.Empty;
            string strperson_work_status_code = string.Empty;
            string strperson_work_status_name = string.Empty;
            string strActive = string.Empty;

            strperson_work_status_code = txtperson_work_status_code.Text.Replace("'", "''").Trim();
            strperson_work_status_name = txtperson_work_status_name.Text.Replace("'", "''").Trim();
            if (!strperson_work_status_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (person_work_status_code like '%" + strperson_work_status_code + "%') ";
            }
            if (!strperson_work_status_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (person_work_status_name like '%" + strperson_work_status_name + "%')";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }
            try
            {
                if (!oPerson_work_status.SP_PERSON_WORK_STATUS_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    try
                    {
                        GridView1.PageIndex           = nPageNo;
                        txthTotalRecord.Value         = ds.Tables[0].Rows.Count.ToString();
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                    catch
                    {
                        GridView1.PageIndex           = 0;
                        txthTotalRecord.Value         = ds.Tables[0].Rows.Count.ToString();
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oPerson_work_status.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
Beispiel #3
0
        private bool saveData()
        {
            bool   blnResult  = false;
            bool   blnDup     = false;
            string strMessage = string.Empty;
            string strperson_work_status_code = string.Empty,
                   strperson_work_status_name = string.Empty,
                   strActive    = string.Empty,
                   strCreatedBy = string.Empty,
                   strUpdatedBy = string.Empty;
            string strScript    = string.Empty;
            cPerson_work_status oPerson_work_status = new cPerson_work_status();
            DataSet             ds = new DataSet();

            try
            {
                #region set Data
                strperson_work_status_code = txtperson_work_status_code.Text.Trim();
                strperson_work_status_name = txtperson_work_status_name.Text;
                if (chkStatus.Checked == true)
                {
                    strActive = "Y";
                }
                else
                {
                    strActive = "N";
                }
                strCreatedBy = Session["username"].ToString();
                strUpdatedBy = Session["username"].ToString();
                #endregion
                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    #region edit
                    if (!blnDup)
                    {
                        if (oPerson_work_status.SP_PERSON_WORK_STATUS_UPD(strperson_work_status_code, strperson_work_status_name, strActive, strUpdatedBy, ref strMessage))
                        {
                            blnResult = true;
                        }
                        else
                        {
                            lblError.Text = strMessage.ToString();
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true);
                    }
                    #endregion
                }
                else
                {
                    #region check dup
                    string strCheckDup = string.Empty;
                    strCheckDup = " and person_work_status_code = '" + strperson_work_status_code.Trim() + "' ";
                    if (!oPerson_work_status.SP_PERSON_WORK_STATUS_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strperson_work_status_code.Trim() + " : " + strperson_work_status_name.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oPerson_work_status.SP_PERSON_WORK_STATUS_INS(strperson_work_status_code, strperson_work_status_name, strActive, strCreatedBy, ref strMessage))
                        {
                            ViewState["person_work_status_code"] = strperson_work_status_code;
                            blnResult = true;
                        }
                        else
                        {
                            lblError.Text = strMessage.ToString();
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true);
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oPerson_work_status.Dispose();
            }
            return(blnResult);
        }