Esempio n. 1
0
        private void setData()
        {
            cPosition oPosition = new cPosition();
            DataSet   ds = new DataSet();
            string    strMessage = string.Empty, strCriteria = string.Empty;
            string    strposition_code = string.Empty,
                      strposition_name = string.Empty,
                      strC_active      = string.Empty,
                      strCreatedBy     = string.Empty,
                      strUpdatedBy     = string.Empty,
                      strCreatedDate   = string.Empty,
                      strUpdatedDate   = string.Empty;

            try
            {
                strCriteria = " and position_code = '" + ViewState["position_code"].ToString() + "' ";
                if (!oPosition.SP_POSITION_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strposition_code = ds.Tables[0].Rows[0]["position_code"].ToString();
                        strposition_name = ds.Tables[0].Rows[0]["position_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
                        txtposition_code.Text = strposition_code;
                        txtposition_name.Text = strposition_name;
                        if (strC_active.Equals("Y"))
                        {
                            txtposition_name.ReadOnly = false;
                            txtposition_name.CssClass = "textbox";
                            chkStatus.Checked         = true;
                        }
                        else
                        {
                            txtposition_name.ReadOnly = true;
                            txtposition_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
        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     lblposition_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblposition_code");
            cPosition oPosition        = new cPosition();

            try
            {
                if (!oPosition.SP_POSITION_DEL(lblposition_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oPosition.Dispose();
            }
            BindGridView(0);
        }
Esempio n. 3
0
        private void BindGridView()
        {
            cPosition oPosition              = new cPosition();
            DataSet   ds                     = new DataSet();
            string    strMessage             = string.Empty;
            string    strCriteria            = string.Empty;
            string    strlevel_position_code = string.Empty;
            string    strlevel_position_name = string.Empty;
            string    strScript              = string.Empty;

            strlevel_position_code = txtlevel_position_code.Text.Replace("'", "''").Trim();
            strlevel_position_name = txtlevel_position_name.Text.Replace("'", "''").Trim();
            if (!strlevel_position_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (level_position_code like '%" + strlevel_position_code + "%') ";
            }
            if (!strlevel_position_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (level_position_name like '%" + strlevel_position_name + "%')";
            }
            strCriteria = strCriteria + "  And  (c_active ='Y') ";
            try
            {
                if (oPosition.SP_LEVEL_POSITION_SEL(strCriteria, ref ds, ref strMessage))
                {
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        strlevel_position_code = ds.Tables[0].Rows[0]["level_position_code"].ToString();
                        strlevel_position_name = ds.Tables[0].Rows[0]["level_position_name"].ToString();
                        if (!ViewState["show"].ToString().Equals("1"))
                        {
                            if (!string.IsNullOrEmpty(ViewState["ctrl1"].ToString()))
                            {
                                strScript = "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strlevel_position_code + "';\n ";
                            }
                            if (!string.IsNullOrEmpty(ViewState["ctrl2"].ToString()))
                            {
                                strScript += "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strlevel_position_name + "';\n";
                            }
                            strScript += "ClosePopUp('" + ViewState["show"].ToString() + "');";
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(ViewState["ctrl1"].ToString()))
                            {
                                strScript = "window.parent.document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strlevel_position_code + "';\n ";
                            }
                            if (!string.IsNullOrEmpty(ViewState["ctrl2"].ToString()))
                            {
                                strScript += "window.parent.document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strlevel_position_name + "';\n";
                            }
                            strScript += "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
            {
                oPosition.Dispose();
                ds.Dispose();
            }
        }
Esempio n. 4
0
        private void BindGridView(int nPageNo)
        {
            cPosition oPosition        = new cPosition();
            DataSet   ds               = new DataSet();
            string    strMessage       = string.Empty;
            string    strCriteria      = string.Empty;
            string    strposition_code = string.Empty;
            string    strposition_name = string.Empty;
            string    strActive        = string.Empty;

            strposition_code = txtposition_code.Text.Replace("'", "''").Trim();
            strposition_name = txtposition_name.Text.Replace("'", "''").Trim();
            if (!strposition_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (position_code like '%" + strposition_code + "%') ";
            }
            if (!strposition_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (position_name like '%" + strposition_name + "%')";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }
            try
            {
                if (!oPosition.SP_POSITION_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
            {
                oPosition.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
Esempio n. 5
0
        private bool saveData()
        {
            bool   blnResult        = false;
            bool   blnDup           = false;
            string strMessage       = string.Empty;
            string strposition_code = string.Empty,
                   strposition_name = string.Empty,
                   strActive        = string.Empty,
                   strCreatedBy     = string.Empty,
                   strUpdatedBy     = string.Empty;
            string    strScript     = string.Empty;
            cPosition oPosition     = new cPosition();
            DataSet   ds            = new DataSet();

            try
            {
                #region set Data
                strposition_code = txtposition_code.Text.Trim();
                strposition_name = txtposition_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 (oPosition.SP_POSITION_UPD(strposition_code, strposition_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 position_code = '" + strposition_code.Trim() + "' ";
                    if (!oPosition.SP_POSITION_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strposition_code.Trim() + " : " + strposition_name.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oPosition.SP_POSITION_INS(strposition_code, strposition_name, strActive, strCreatedBy, ref strMessage))
                        {
                            ViewState["position_code"] = strposition_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
            {
                oPosition.Dispose();
            }
            return(blnResult);
        }