private void setData()
        {
            cPerson_manage oPerson_manage = new cPerson_manage();
            DataSet        ds = new DataSet();
            string         strMessage = string.Empty, strCriteria = string.Empty;
            string         strperson_manage_code = string.Empty,
                           strperson_manage_name = string.Empty,
                           strC_active           = string.Empty,
                           strCreatedBy          = string.Empty,
                           strUpdatedBy          = string.Empty,
                           strCreatedDate        = string.Empty,
                           strUpdatedDate        = string.Empty;

            try
            {
                strCriteria = " and person_manage_code = '" + ViewState["person_manage_code"].ToString() + "' ";
                if (!oPerson_manage.SP_PERSON_MANAGE_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strperson_manage_code = ds.Tables[0].Rows[0]["person_manage_code"].ToString();
                        strperson_manage_name = ds.Tables[0].Rows[0]["person_manage_name"].ToString();
                        strC_active           = ds.Tables[0].Rows[0]["c_active"].ToString();
                        strCreatedBy          = ds.Tables[0].Rows[0]["c_created_by"].ToString();
                        strUpdatedBy          = ds.Tables[0].Rows[0]["c_updated_by"].ToString();
                        strCreatedDate        = ds.Tables[0].Rows[0]["d_created_date"].ToString();
                        strUpdatedDate        = ds.Tables[0].Rows[0]["d_updated_date"].ToString();
                        #endregion

                        #region set Control
                        txtperson_manage_code.Text = strperson_manage_code;
                        txtperson_manage_name.Text = strperson_manage_name;
                        if (strC_active.Equals("Y"))
                        {
                            txtperson_manage_name.ReadOnly = false;
                            txtperson_manage_name.CssClass = "textbox";
                            chkStatus.Checked = true;
                        }
                        else
                        {
                            txtperson_manage_name.ReadOnly = true;
                            txtperson_manage_name.CssClass = "textboxdis";
                            chkStatus.Checked = false;
                        }
                        txtUpdatedBy.Text   = strUpdatedBy;
                        txtUpdatedDate.Text = strUpdatedDate;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
        private void BindGridView()
        {
            cPerson_manage oPerson_manage        = new cPerson_manage();
            DataSet        ds                    = new DataSet();
            string         strMessage            = string.Empty;
            string         strCriteria           = string.Empty;
            string         strperson_manage_code = string.Empty;
            string         strperson_manage_name = string.Empty;
            string         strScript             = string.Empty;

            strperson_manage_code = txtperson_manage_code.Text.Replace("'", "''").Trim();
            strperson_manage_name = txtperson_manage_name.Text.Replace("'", "''").Trim();
            if (!strperson_manage_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (person_manage_code like '%" + strperson_manage_code + "%') ";
            }
            if (!strperson_manage_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (person_manage_name like '%" + strperson_manage_name + "%')";
            }
            strCriteria = strCriteria + "  And  (c_active ='Y') ";
            try
            {
                if (oPerson_manage.SP_PERSON_MANAGE_SEL(strCriteria, ref ds, ref strMessage))
                {
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        strperson_manage_code = ds.Tables[0].Rows[0]["person_manage_code"].ToString();
                        strperson_manage_name = ds.Tables[0].Rows[0]["person_manage_name"].ToString();
                        if (!ViewState["show"].ToString().Equals("1"))
                        {
                            strScript = "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strperson_manage_code + "';\n " +
                                        "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strperson_manage_name + "';\n" +
                                        "ClosePopUp('" + ViewState["show"].ToString() + "');";
                        }
                        else
                        {
                            strScript = "window.parent.document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strperson_manage_code + "';\n " +
                                        "window.parent.document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strperson_manage_name + "';\n" +
                                        "ClosePopUp('" + ViewState["show"].ToString() + "');";
                        }
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close", strScript, true);
                    }
                    else
                    {
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                }
                else
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oPerson_manage.Dispose();
                ds.Dispose();
            }
        }
Beispiel #3
0
        private void BindGridView(int nPageNo)
        {
            cPerson_manage operson_manage        = new cPerson_manage();
            DataSet        ds                    = new DataSet();
            string         strMessage            = string.Empty;
            string         strCriteria           = string.Empty;
            string         strperson_manage_code = string.Empty;
            string         strperson_manage_name = string.Empty;
            string         strActive             = string.Empty;

            strperson_manage_code = txtperson_manage_code.Text.Replace("'", "''").Trim();
            strperson_manage_name = txtperson_manage_name.Text.Replace("'", "''").Trim();
            if (!strperson_manage_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (person_manage_code like '%" + strperson_manage_code + "%') ";
            }
            if (!strperson_manage_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (person_manage_name like '%" + strperson_manage_name + "%')";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }
            try
            {
                if (!operson_manage.SP_PERSON_MANAGE_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_manage.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
        private bool saveData()
        {
            bool   blnResult              = false;
            bool   blnDup                 = false;
            string strMessage             = string.Empty;
            string strperson_manage_code  = string.Empty,
                   strperson_manage_name  = string.Empty,
                   strActive              = string.Empty,
                   strCreatedBy           = string.Empty,
                   strUpdatedBy           = string.Empty;
            string         strScript      = string.Empty;
            cPerson_manage oPerson_manage = new cPerson_manage();
            DataSet        ds             = new DataSet();

            try
            {
                #region set Data
                strperson_manage_code = txtperson_manage_code.Text.Trim();
                strperson_manage_name = txtperson_manage_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_manage.SP_PERSON_MANAGE_UPD(strperson_manage_code, strperson_manage_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_manage_code = '" + strperson_manage_code.Trim() + "' ";
                    if (!oPerson_manage.SP_PERSON_MANAGE_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strperson_manage_code.Trim() + " : " + strperson_manage_name.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oPerson_manage.SP_PERSON_MANAGE_INS(strperson_manage_code, strperson_manage_name, strActive, strCreatedBy, ref strMessage))
                        {
                            ViewState["person_manage_code"] = strperson_manage_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_manage.Dispose();
            }
            return(blnResult);
        }