Ejemplo n.º 1
0
        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  lbltitle_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lbltitle_code");
            cTitle oTitle        = new cTitle();

            try
            {
                if (!oTitle.SP_DEL_TITLE(lbltitle_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oTitle.Dispose();
            }
            BindGridView(0);
        }
Ejemplo 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;
                }
            }
        }
Ejemplo 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);
        }