Beispiel #1
0
        private void InitcboPerson_group()
        {
            cPerson_group oPerson_group        = new cPerson_group();
            string        strMessage           = string.Empty,
                          strCriteria          = string.Empty,
                          strperson_group_code = string.Empty;

            strperson_group_code = ViewState["person_group_code"].ToString();
            int       i;
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            strCriteria  = " and c_active='Y' ";
            strCriteria += " and person_group_code IN (" + PersonGroupList + ") ";
            if (oPerson_group.SP_PERSON_GROUP_SEL(strCriteria, ref ds, ref strMessage))
            {
                dt = ds.Tables[0];
                cboPerson_group.Items.Clear();
                cboPerson_group.Items.Add(new ListItem("---- เลือกข้อมูลทั้งหมด ----", ""));
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    cboPerson_group.Items.Add(new ListItem(dt.Rows[i]["person_group_name"].ToString(), dt.Rows[i]["person_group_code"].ToString()));
                }
                if (cboPerson_group.Items.FindByValue(strperson_group_code) != null)
                {
                    cboPerson_group.SelectedIndex = -1;
                    cboPerson_group.Items.FindByValue(strperson_group_code).Selected = true;
                }
            }
        }
        private void setData()
        {
            cPerson_group oPerson_group = new cPerson_group();
            DataSet       ds = new DataSet();
            string        strMessage = string.Empty, strCriteria = string.Empty;
            string        strperson_group_code = string.Empty,
                          strperson_group_name = string.Empty,
                          strC_active          = string.Empty,
                          strCreatedBy         = string.Empty,
                          strUpdatedBy         = string.Empty,
                          strCreatedDate       = string.Empty,
                          strUpdatedDate       = string.Empty;

            try
            {
                strCriteria = " and person_group_code = '" + ViewState["person_group_code"].ToString() + "' ";
                if (!oPerson_group.SP_PERSON_GROUP_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strperson_group_code = ds.Tables[0].Rows[0]["person_group_code"].ToString();
                        strperson_group_name = ds.Tables[0].Rows[0]["person_group_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_group_code.Text = strperson_group_code;
                        txtperson_group_name.Text = strperson_group_name;
                        if (strC_active.Equals("Y"))
                        {
                            txtperson_group_name.ReadOnly = false;
                            txtperson_group_name.CssClass = "textbox";
                            chkStatus.Checked             = true;
                        }
                        else
                        {
                            txtperson_group_name.ReadOnly = true;
                            txtperson_group_name.CssClass = "textboxdis";
                            chkStatus.Checked             = false;
                        }
                        txtUpdatedBy.Text   = strUpdatedBy;
                        txtUpdatedDate.Text = strUpdatedDate;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
        private void BindGridView2()
        {
            cPerson_group oPerson_group = new cPerson_group();
            DataSet       ds            = new DataSet();
            string        strMessage    = string.Empty;
            string        strCriteria   = string.Empty;
            string        strActive     = string.Empty;

            strCriteria = strCriteria + "  And  (c_active ='Y') ";
            try
            {
                if (!oPerson_group.SP_PERSON_GROUP_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    GridView2.DataSource = ds.Tables[0];
                    GridView2.DataBind();
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oPerson_group.Dispose();
                ds.Dispose();
            }
        }
Beispiel #4
0
        private void BindGridView()
        {
            cPerson_group oPerson_group        = new cPerson_group();
            DataSet       ds                   = new DataSet();
            string        strMessage           = string.Empty;
            string        strCriteria          = string.Empty;
            string        strperson_group_code = string.Empty;
            string        strperson_group_name = string.Empty;
            string        strScript            = string.Empty;

            strperson_group_code = txtperson_group_code.Text.Replace("'", "''").Trim();
            strperson_group_name = txtperson_group_name.Text.Replace("'", "''").Trim();
            if (!strperson_group_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (person_group_code like '%" + strperson_group_code + "%') ";
            }
            if (!strperson_group_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (person_group_name like '%" + strperson_group_name + "%')";
            }
            strCriteria = strCriteria + "  And  (c_active ='Y') ";
            try
            {
                if (oPerson_group.SP_PERSON_GROUP_SEL(strCriteria, ref ds, ref strMessage))
                {
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        strperson_group_code = ds.Tables[0].Rows[0]["person_group_code"].ToString();
                        strperson_group_name = ds.Tables[0].Rows[0]["person_group_name"].ToString();
                        strScript            = "self.opener.document.forms[0].elements('" + ViewState["ctrl1"].ToString() + "').value='" + strperson_group_code + "';\n " +
                                               "self.opener.document.forms[0].elements('" + ViewState["ctrl2"].ToString() + "').value='" + strperson_group_name + "';\n" +
                                               "self.close(); \n";
                        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_group.Dispose();
                ds.Dispose();
            }
        }
        private void BindGridView(int nPageNo)
        {
            cPerson_group oPerson_group        = new cPerson_group();
            DataSet       ds                   = new DataSet();
            string        strMessage           = string.Empty;
            string        strCriteria          = string.Empty;
            string        strperson_group_code = string.Empty;
            string        strperson_group_name = string.Empty;
            string        strActive            = string.Empty;

            strperson_group_code = txtperson_group_code.Text.Replace("'", "''").Trim();
            strperson_group_name = txtperson_group_name.Text.Replace("'", "''").Trim();
            if (!strperson_group_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (person_group_code like '%" + strperson_group_code + "%') ";
            }
            if (!strperson_group_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (person_group_name like '%" + strperson_group_name + "%')";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }
            try
            {
                if (!oPerson_group.SP_PERSON_GROUP_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_group.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_group_code = string.Empty,
                   strperson_group_name = string.Empty,
                   strActive            = string.Empty,
                   strCreatedBy         = string.Empty,
                   strUpdatedBy         = string.Empty;
            string        strScript     = string.Empty;
            cPerson_group oPerson_group = new cPerson_group();
            DataSet       ds            = new DataSet();

            try
            {
                #region set Data
                strperson_group_code = txtperson_group_code.Text.Trim();
                strperson_group_name = txtperson_group_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_group.SP_PERSON_GROUP_UPD(strperson_group_code, strperson_group_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_group_code = '" + strperson_group_code.Trim() + "' ";
                    if (!oPerson_group.SP_PERSON_GROUP_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strperson_group_code.Trim() + " : " + strperson_group_name.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oPerson_group.SP_PERSON_GROUP_INS(strperson_group_code, strperson_group_name, strActive, strCreatedBy, ref strMessage))
                        {
                            ViewState["person_group_code"] = strperson_group_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_group.Dispose();
            }
            return(blnResult);
        }