Esempio n. 1
0
        private void setData()
        {
            cTitle  oTitle = new cTitle();
            DataSet ds = new DataSet();
            string  strMessage = string.Empty, strCriteria = string.Empty;
            string  strTitle_code  = string.Empty,
                    strTitle_name  = string.Empty,
                    strC_active    = string.Empty,
                    strCreatedBy   = string.Empty,
                    strUpdatedBy   = string.Empty,
                    strCreatedDate = string.Empty,
                    strUpdatedDate = string.Empty;

            try
            {
                strCriteria = " and title_code = '" + ViewState["title_code"].ToString() + "' ";
                if (!oTitle.SP_SEL_TITLE(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strTitle_code  = ds.Tables[0].Rows[0]["title_code"].ToString();
                        strTitle_name  = ds.Tables[0].Rows[0]["title_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
                        txttitle_code.Text = strTitle_code;
                        txttitle_name.Text = strTitle_name;
                        if (strC_active.Equals("Y"))
                        {
                            txttitle_name.ReadOnly = false;
                            txttitle_name.CssClass = "textbox";
                            chkStatus.Checked      = true;
                        }
                        else
                        {
                            txttitle_name.ReadOnly = true;
                            txttitle_name.CssClass = "textboxdis";
                            chkStatus.Checked      = false;
                        }
                        txtUpdatedBy.Text   = strUpdatedBy;
                        txtUpdatedDate.Text = strUpdatedDate;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
Esempio n. 2
0
        private void BindGridView(int nPageNo)
        {
            cTitle  oTitle        = new cTitle();
            DataSet ds            = new DataSet();
            string  strMessage    = string.Empty;
            string  strCriteria   = string.Empty;
            string  strTitle_code = string.Empty;
            string  strTitle_name = string.Empty;
            string  strActive     = string.Empty;

            strTitle_code = txttitle_code.Text.Replace("'", "''").Trim();
            strTitle_name = txttitle_name.Text.Replace("'", "''").Trim();
            if (!strTitle_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (title_code like '%" + strTitle_code + "%') ";
            }
            if (!strTitle_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (title_name like '%" + strTitle_name + "%')";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }
            try
            {
                if (!oTitle.SP_SEL_TITLE(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
            {
                oTitle.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
Esempio n. 3
0
        private bool saveData()
        {
            bool   blnResult     = false;
            bool   blnDup        = false;
            string strMessage    = string.Empty;
            string strtitle_code = string.Empty,
                   strtitle_name = string.Empty,
                   strActive     = string.Empty,
                   strCreatedBy  = string.Empty,
                   strUpdatedBy  = string.Empty;
            string  strScript    = string.Empty;
            cTitle  oTitle       = new cTitle();
            DataSet ds           = new DataSet();

            try
            {
                #region set Data
                strtitle_code = txttitle_code.Text.Trim();
                strtitle_name = txttitle_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 (oTitle.SP_UPD_TITLE(strtitle_code, strtitle_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 title_code = '" + strtitle_code.Trim() + "' ";
                    if (!oTitle.SP_SEL_TITLE(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strtitle_code.Trim() + " : " + strtitle_name.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oTitle.SP_INS_TITLE(strtitle_code, strtitle_name, strActive, strCreatedBy, ref strMessage))
                        {
                            ViewState["title_code"] = strtitle_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
            {
                oTitle.Dispose();
            }
            return(blnResult);
        }