Esempio 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       lblmaterial_id = (Label)GridView1.Rows[e.RowIndex].FindControl("lblmaterial_id");
            c3dMaterial obj3dMaterial  = new c3dMaterial();

            try
            {
                if (!obj3dMaterial.SP_MATERIAL_DEL(Helper.CInt(lblmaterial_id.Text)))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                obj3dMaterial.Dispose();
            }
            BindGridView(0);
        }
Esempio n. 2
0
        private bool saveData()
        {
            bool   blnResult        = false;
            string strmaterial_code = string.Empty,
                   strmaterial_name = string.Empty,
                   strUserName      = string.Empty;

            double      pstandard_price, plast_price;
            string      strScript      = string.Empty;
            int         intmaterial_id = Helper.CInt(ViewState["material_id"]);
            int         intcount_id;
            c3dMaterial obj3dMaterial = new c3dMaterial();
            DataSet     ds            = new DataSet();

            try
            {
                #region set Data
                strmaterial_code = txtmaterial_code.Text;
                strmaterial_name = txtmaterial_name.Text;
                intcount_id      = Helper.CInt(txtcount_id.Text);
                pstandard_price  = Helper.CDbl(txtstandard_price.Value);
                plast_price      = Helper.CDbl(txtlast_price.Value);
                strUserName      = Session["username"].ToString();

                #endregion

                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    blnResult = obj3dMaterial.SP_MATERIAL_UPD(intmaterial_id, strmaterial_code, strmaterial_name, intcount_id, pstandard_price, plast_price, "E", strUserName);
                }
                else
                {
                    #region insert
                    if (obj3dMaterial.SP_MATERIAL_INS(ref intmaterial_id, ref strmaterial_code, strmaterial_name, intcount_id, pstandard_price, plast_price, "E", strUserName))
                    {
                        ViewState["material_id"] = intmaterial_id;
                        blnResult = true;
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate") && ex.Message.Contains("IX_material_name"))
                {
                    strScript = "alert(\"ไม่สามารถแก้ไขข้อมูล เนื่องจากข้อมูล " + strmaterial_name.Trim() + "  ซ้ำ\");\n";
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true);
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                obj3dMaterial.Dispose();
            }
            return(blnResult);
        }
Esempio n. 3
0
        private void BindGridView(int nPageNo)
        {
            c3dMaterial obj3dMaterial    = new c3dMaterial();
            string      strMessage       = string.Empty;
            string      strCriteria      = string.Empty;
            string      strmaterial_code = string.Empty;
            string      strmaterial_name = string.Empty;
            DataTable   dt;

            strmaterial_code = txtmaterial_code.Text.Replace("'", "''").Trim();
            strmaterial_name = txtmaterial_name.Text.Replace("'", "''").Trim();
            if (!strmaterial_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (material_code like '%" + strmaterial_code + "%') ";
            }
            if (!strmaterial_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (material_name like '%" + strmaterial_name + "%') ";
            }
            strCriteria = strCriteria + "  And  (material_type = 'E') ";
            try
            {
                dt = obj3dMaterial.SP_MATERIAL_SEL(strCriteria);

                try
                {
                    GridView1.PageIndex   = nPageNo;
                    txthTotalRecord.Value = dt.Rows.Count.ToString();
                    dt.DefaultView.Sort   = ViewState["sort"] + " " + ViewState["direction"];
                    GridView1.DataSource  = dt;
                    GridView1.DataBind();
                }
                catch
                {
                    GridView1.PageIndex   = 0;
                    txthTotalRecord.Value = dt.Rows.Count.ToString();
                    dt.DefaultView.Sort   = ViewState["sort"] + " " + ViewState["direction"];
                    GridView1.DataSource  = dt;
                    GridView1.DataBind();
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                obj3dMaterial.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
Esempio n. 4
0
        private void setData()
        {
            c3dMaterial obj3dMaterial = new c3dMaterial();
            string      strCriteria = string.Empty;
            string      strmaterial_code = string.Empty,
                        strmaterial_name = string.Empty,
                        strUpdatedBy = string.Empty,
                        strUpdatedDate = string.Empty,
                        strcount_id = string.Empty,
                        strcount_name = string.Empty;
            double pstandard_price, plast_price;

            try
            {
                strCriteria = " and material_id = '" + ViewState["material_id"].ToString() + "' ";
                var dt = obj3dMaterial.SP_MATERIAL_SEL(strCriteria);
                if (dt.Rows.Count > 0)
                {
                    #region get Data
                    strmaterial_code = dt.Rows[0]["material_code"].ToString();
                    strmaterial_name = dt.Rows[0]["material_name"].ToString();
                    strcount_id      = dt.Rows[0]["count_id"].ToString();
                    strcount_name    = dt.Rows[0]["count_name"].ToString();
                    pstandard_price  = Helper.CDbl(dt.Rows[0]["standard_price"]);
                    plast_price      = Helper.CDbl(dt.Rows[0]["last_price"]);
                    strUpdatedBy     = dt.Rows[0]["c_updated_by"].ToString();
                    strUpdatedDate   = dt.Rows[0]["d_updated_date"].ToString();
                    #endregion

                    #region set Control
                    txtmaterial_code.Text   = strmaterial_code;
                    txtmaterial_name.Text   = strmaterial_name;
                    txtcount_id.Text        = strcount_id;
                    txtcount_name.Text      = strcount_name;
                    txtstandard_price.Value = pstandard_price;
                    txtlast_price.Value     = plast_price;
                    txtUpdatedBy.Text       = strUpdatedBy;
                    txtUpdatedDate.Text     = strUpdatedDate;
                    #endregion
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
Esempio n. 5
0
        private void BindGridView()
        {
            c3dMaterial oMaterial        = new c3dMaterial();
            DataSet     ds               = new DataSet();
            string      strMessage       = string.Empty;
            string      strCriteria      = string.Empty;
            string      strmaterial_id   = string.Empty;
            string      strmaterial_code = string.Empty;
            string      strmaterial_name = string.Empty;
            string      strScript        = string.Empty;

            strmaterial_code = txtmaterial_code.Text.Replace("'", "''").Trim();
            strmaterial_name = txtmaterial_name.Text.Replace("'", "''").Trim();
            if (!strmaterial_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (material_code like '%" + strmaterial_code + "%') ";
            }
            if (!strmaterial_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (material_name like '%" + strmaterial_name + "%') ";
            }
            strCriteria += "  And material_type = 'E' ";
            try
            {
                var dt = oMaterial.SP_MATERIAL_SEL(strCriteria);
                if (dt.Rows.Count == 1)
                {
                    strmaterial_code = dt.Rows[0]["material_code"].ToString();
                    strmaterial_name = dt.Rows[0]["material_name"].ToString();
                    strmaterial_id   = dt.Rows[0]["material_id"].ToString();
                    if (!ViewState["show"].ToString().Equals("1"))
                    {
                        strScript = "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strmaterial_code + "';\n " +
                                    "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strmaterial_name + "';\n" +
                                    "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl3"].ToString() + "').value='" + strmaterial_id + "';\n" +
                                    "ClosePopUp('" + ViewState["show"].ToString() + "');";
                    }
                    else
                    {
                        strScript = "window.parent.document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strmaterial_code + "';\n " +
                                    "window.parent.document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strmaterial_name + "';\n" +
                                    "window.parent.document.getElementById('" + ViewState["ctrl3"].ToString() + "').value='" + strmaterial_id + "';\n" +
                                    "ClosePopUp('" + ViewState["show"].ToString() + "');";
                    }
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close", strScript, true);
                }
                else
                {
                    dt.DefaultView.Sort  = ViewState["sort"] + " " + ViewState["direction"];
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oMaterial.Dispose();
                ds.Dispose();
            }
        }