示例#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       lbluser_group_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lbluser_group_code");
            cUser_group oUser_group        = new cUser_group();

            try
            {
                if (!oUser_group.SP_USER_GROUP_DEL(lbluser_group_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    if (strMessage.Contains("REFERENCE constraint"))
                    {
                        MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                    }
                    else
                    {
                        lblError.Text = strMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("REFERENCE constraint"))
                {
                    MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oUser_group.Dispose();
            }
            BindGridView(0);
        }
        protected void imgSaveOnly_Click(object sender, ImageClickEventArgs e)
        {
            string      strMessage  = string.Empty;
            string      strScript   = string.Empty;
            cUser_group oUser_group = new cUser_group();
            DataSet     ds          = new DataSet();

            try
            {
                string strCheck = string.Empty;
                strCheck = " and [user_group_code] = '" + cboUserGroup.SelectedValue + "' ";
                if (!oUser_group.SP_USER_GROUP_SEL(strCheck, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        strScript =
                            "alert('ไม่สามารถบันข้อมูลได้ เนื่องจาก" +
                            "\\nไม่พบข้อมูล User Group : " + cboUserGroup.SelectedItem.Text + "');";
                        MsgBox(strScript);
                        return;
                    }
                }
                string struser_group_code = ds.Tables[0].Rows[0]["user_group_code"].ToString();
                saveData(struser_group_code);
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oUser_group.Dispose();
                ds.Dispose();
            }
        }
示例#3
0
        private void BindGridView(int nPageNo)
        {
            cUser_group oUser_group        = new cUser_group();
            DataSet     ds                 = new DataSet();
            string      strMessage         = string.Empty;
            string      strCriteria        = string.Empty;
            string      struser_group_code = string.Empty;
            string      struser_group_name = string.Empty;
            string      strActive          = string.Empty;

            struser_group_code = txtuser_group_code.Text.Replace("'", "''").Trim();
            struser_group_name = txtuser_group_name.Text.Replace("'", "''").Trim();
            if (!struser_group_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (user_group_code like '%" + struser_group_code + "%') ";
            }
            if (!struser_group_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (user_group_name like '%" + struser_group_name + "%')";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }
            try
            {
                if (!oUser_group.SP_USER_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
            {
                oUser_group.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
示例#4
0
        private bool saveData()
        {
            bool   blnResult          = false;
            bool   blnDup             = false;
            string strMessage         = string.Empty;
            string struser_group_code = string.Empty,
                   struser_group_name = string.Empty,
                   strActive          = string.Empty,
                   strCreatedBy       = string.Empty,
                   strUpdatedBy       = string.Empty;
            string      strScript     = string.Empty;
            cUser_group oUser_group   = new cUser_group();
            DataSet     ds            = new DataSet();

            try
            {
                #region set Data
                struser_group_code = txtuser_group_code.Text.Trim();
                struser_group_name = txtuser_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 (oUser_group.SP_USER_GROUP_UPD(struser_group_code, struser_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 user_group_code = '" + struser_group_code.Trim() + "' ";
                    if (!oUser_group.SP_USER_GROUP_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + struser_group_code.Trim() + " : " + struser_group_name.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oUser_group.SP_USER_GROUP_INS(struser_group_code, struser_group_name, strActive, strCreatedBy, ref strMessage))
                        {
                            ViewState["user_group_code"] = struser_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
            {
                oUser_group.Dispose();
            }
            return(blnResult);
        }