示例#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       lblitem_acc_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblitem_acc_code");
            HiddenField hdditem_acc_id   = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdditem_acc_id");
            cItem_acc   oItem_acc        = new cItem_acc();

            try
            {
                if (!oItem_acc.SP_ITEM_ACC_DEL(hdditem_acc_id.Value.ToString(), "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oItem_acc.Dispose();
            }
            BindGridView(0);
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string    strMessage      = string.Empty;
            string    strCheck        = string.Empty;
            string    strScript       = string.Empty;
            Label     lblitem_acc_doc = (Label)GridView1.Rows[e.RowIndex].FindControl("lblitem_acc_doc");
            cItem_acc oitem_acc       = new cItem_acc();

            try
            {
                if (!oitem_acc.SP_ITEM_ACC_HEAD_DEL(lblitem_acc_doc.Text, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oitem_acc.Dispose();
            }
            BindGridView(0);
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string      strMessage            = string.Empty;
            string      strScript             = string.Empty;
            HiddenField hdditem_acc_detail_id = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdditem_acc_detail_id");

            cItem_acc oItem_acc = new cItem_acc();

            try
            {
                if (!oItem_acc.SP_ITEM_ACC_DETAIL_DEL(hdditem_acc_detail_id.Value.ToString(), ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oItem_acc.Dispose();
            }
            BindGridView();
        }
示例#4
0
        private void InitcboItem_acc()
        {
            cItem_acc oItem_acc        = new cItem_acc();
            string    strMessage       = string.Empty,
                      strCriteria      = string.Empty,
                      strItem_acc_code = string.Empty;

            strItem_acc_code = cboItem_acc.SelectedValue;
            string    strYear = ((DataSet)Application["xmlconfig"]).Tables["default"].Rows[0]["yearnow"].ToString();
            int       i;
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            strCriteria = "and item_acc_year='" + strYear + "' and c_active='Y' ";
            if (oItem_acc.SP_ITEM_ACC_SEL(strCriteria, ref ds, ref strMessage))
            {
                dt = ds.Tables[0];
                cboItem_acc.Items.Clear();
                cboItem_acc.Items.Add(new ListItem("---- กรุณาเลือกข้อมูล ----", ""));
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    cboItem_acc.Items.Add(new ListItem(dt.Rows[i]["Item_acc_name"].ToString(), dt.Rows[i]["item_acc_id"].ToString()));
                }
                if (cboItem_acc.Items.FindByValue(strItem_acc_code) != null)
                {
                    cboItem_acc.SelectedIndex = -1;
                    cboItem_acc.Items.FindByValue(strItem_acc_code).Selected = true;
                }
            }
        }
示例#5
0
        private void setData()
        {
            cItem_acc oItem_acc = new cItem_acc();
            DataSet   ds = new DataSet();
            string    strMessage = string.Empty, strCriteria = string.Empty;
            string    stritem_acc_code = string.Empty,
                      stritem_acc_name = string.Empty,
                      strYear          = string.Empty,
                      strC_active      = string.Empty,
                      strCreatedBy     = string.Empty,
                      strUpdatedBy     = string.Empty,
                      strCreatedDate   = string.Empty,
                      strUpdatedDate   = string.Empty;

            try
            {
                strCriteria = " and item_acc_code = '" + ViewState["item_acc_code"].ToString() + "' ";
                if (!oItem_acc.SP_ITEM_ACC_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        stritem_acc_code = ds.Tables[0].Rows[0]["item_acc_code"].ToString();
                        stritem_acc_name = ds.Tables[0].Rows[0]["item_acc_name"].ToString();
                        strYear          = ds.Tables[0].Rows[0]["item_acc_year"].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
                        txtitem_acc_code.Text = stritem_acc_code;
                        txtitem_acc_name.Text = stritem_acc_name;
                        txtyear.Text          = strYear;
                        if (strC_active.Equals("Y"))
                        {
                            chkStatus.Checked = true;
                        }
                        else
                        {
                            chkStatus.Checked = false;
                        }
                        txtUpdatedBy.Text   = strUpdatedBy;
                        txtUpdatedDate.Text = strUpdatedDate;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
        private void BindGridView()
        {
            string    strMessage   = string.Empty;
            string    strCriteria  = string.Empty;
            string    strunit_code = string.Empty;
            cItem_acc oItem_acc    = new cItem_acc();
            DataSet   ds           = new DataSet();

            try
            {
                strCriteria = "  And  item_acc_doc  ='" + ViewState["item_acc_doc"].ToString() + "' ";

                if (!oItem_acc.SP_ITEM_ACC_DETAIL_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        strCriteria  = "   And  pay_month  ='" + cboPay_Month.SelectedValue + "' ";
                        strCriteria += "  And  pay_year  ='" + cboPay_Year.SelectedValue + "' ";

                        if (base.myBudgetType == "B")
                        {
                            strCriteria += "  And  payment_detail_person_group_code in (" + PersonGroupList + ",'') ";
                        }

                        if (base.myBudgetType != "M")
                        {
                            strCriteria += "  And  payment_detail_budget_type ='" + base.myBudgetType + "' ";
                        }


                        if (!oItem_acc.SP_ITEM_ACC_TMP_SEL(strCriteria, ref ds, ref strMessage))
                        {
                            lblError.Text = strMessage;
                        }
                    }
                    ds.Tables[0].DefaultView.Sort = ViewState["sort"].ToString() + " " + ViewState["direction"].ToString();
                    GridView1.DataSource          = ds.Tables[0];
                    GridView1.DataBind();
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                if (GridView1.Rows.Count == 0)
                {
                    EmptyGridFix(GridView1);
                }
                oItem_acc.Dispose();
                ds.Dispose();
            }
        }
        private void BindGridView(int nPageNo)
        {
            cItem_acc oItem_acc   = new cItem_acc();
            DataSet   ds          = new DataSet();
            string    strMessage  = string.Empty;
            string    strCriteria = string.Empty;
            string    strActive   = string.Empty;
            string    strYear     = string.Empty;

            strYear = cboYear.SelectedValue;
            if (!strYear.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_acc_year = '" + strYear + "') ";
            }
            strCriteria += "  And budget_type ='" + this.BudgetType + "' ";
            strCriteria += "  And c_created_by = '" + UserLoginName + "' ";

            try
            {
                if (!oItem_acc.SP_ITEM_ACC_HEAD_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
            {
                oItem_acc.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
示例#8
0
        private void BindGridView(int nPageNo)
        {
            cItem_acc oItem_acc        = new cItem_acc();
            DataSet   ds               = new DataSet();
            string    strMessage       = string.Empty;
            string    strCriteria      = string.Empty;
            string    stritem_acc_code = string.Empty;
            string    stritem_acc_name = string.Empty;
            string    strActive        = string.Empty;
            string    stritem_acc_year = string.Empty;

            stritem_acc_code = txtitem_acc_code.Text.Replace("'", "''").Trim();
            stritem_acc_name = txtitem_acc_name.Text.Replace("'", "''").Trim();
            stritem_acc_year = cboYear.SelectedValue;
            if (!stritem_acc_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (item_acc_code like '%" + stritem_acc_code + "%') ";
            }
            if (!stritem_acc_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (item_acc_name like '%" + stritem_acc_name + "%')";
            }
            if (!stritem_acc_year.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (item_acc_year = '" + stritem_acc_year + "') ";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }


            try
            {
                if (!oItem_acc.SP_ITEM_ACC_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
            {
                oItem_acc.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
        private void setData()
        {
            imgClear.Visible = false;
            cItem_acc oItem_acc = new cItem_acc();
            DataSet   ds = new DataSet();
            string    strMessage = string.Empty, strCriteria = string.Empty;
            string    stritem_acc_doc     = string.Empty;
            string    stritem_acc_year    = string.Empty;
            string    strpay_month        = string.Empty;
            string    strpay_year         = string.Empty;
            string    stritem_acc_comment = string.Empty;
            string    strCreatedBy        = string.Empty,
                      strUpdatedBy        = string.Empty,
                      strCreatedDate      = string.Empty,
                      strUpdatedDate      = string.Empty;

            try
            {
                strCriteria = " and item_acc_doc = '" + ViewState["item_acc_doc"].ToString() + "' ";
                if (!oItem_acc.SP_ITEM_ACC_HEAD_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data

                        stritem_acc_doc     = ds.Tables[0].Rows[0]["item_acc_doc"].ToString();
                        stritem_acc_year    = ds.Tables[0].Rows[0]["item_acc_year"].ToString();
                        strpay_month        = ds.Tables[0].Rows[0]["pay_month"].ToString();
                        strpay_year         = ds.Tables[0].Rows[0]["pay_year"].ToString();
                        stritem_acc_comment = ds.Tables[0].Rows[0]["item_acc_comment"].ToString();
                        strUpdatedBy        = ds.Tables[0].Rows[0]["c_updated_by"].ToString();
                        strUpdatedDate      = ds.Tables[0].Rows[0]["d_updated_date"].ToString();
                        #endregion

                        #region set Control

                        txtitem_acc_doc.Text = ds.Tables[0].Rows[0]["item_acc_doc"].ToString();
                        InitcboYear();
                        if (cboYear.Items.FindByValue(stritem_acc_year) != null)
                        {
                            cboYear.SelectedIndex = -1;
                            cboYear.Items.FindByValue(stritem_acc_year).Selected = true;
                        }

                        InitcboPay_Year();
                        if (cboPay_Year.Items.FindByValue(strpay_year) != null)
                        {
                            cboPay_Year.SelectedIndex = -1;
                            cboPay_Year.Items.FindByValue(strpay_year).Selected = true;
                        }

                        InitcboPay_Month();
                        if (cboPay_Month.Items.FindByValue(strpay_month) != null)
                        {
                            cboPay_Month.SelectedIndex = -1;
                            cboPay_Month.Items.FindByValue(strpay_month).Selected = true;
                        }

                        txtcomments.Text         = stritem_acc_comment;
                        txtitem_acc_doc.CssClass = "textboxdis";
                        cboYear.Enabled          = false;
                        cboYear.CssClass         = "textboxdis";
                        txtUpdatedBy.Text        = strUpdatedBy;
                        txtUpdatedDate.Text      = strUpdatedDate;

                        if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                        {
                            BindGridView();
                        }

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
        private bool saveData()
        {
            bool   blnResult  = false;
            string strMessage = string.Empty;
            //Head
            string stritem_acc_doc     = string.Empty;
            string stritem_acc_year    = string.Empty;
            string strpay_month        = string.Empty;
            string strpay_year         = string.Empty;
            string stritem_acc_comment = string.Empty;
            //Detail
            string stritem_acc_detail_id = "0";
            string stritem_acc_deka;
            string stritem_acc_group;
            string stritem_acc_amount;
            string stritem_acc_tax;
            string stritem_acc_total;
            string stritem_acc_code;
            string stritem_project_code;
            string stritem_code;
            string strproduce_code;

            string strc_user = Session["username"].ToString();

            string    strScript = string.Empty;
            bool      blnDup    = false;
            cItem_acc oItem_acc = new cItem_acc();
            DataSet   ds        = new DataSet();

            try
            {
                #region set Data
                stritem_acc_doc     = txtitem_acc_doc.Text;
                stritem_acc_year    = cboYear.SelectedValue;
                strpay_month        = cboPay_Month.SelectedValue;
                strpay_year         = cboPay_Year.SelectedValue;
                stritem_acc_comment = txtcomments.Text;
                #endregion

                if (ViewState["mode"].ToString().ToLower().Equals("add"))
                {
                    #region insert
                    string strCheckDup = string.Empty;
                    strCheckDup = " and pay_year = '" + strpay_year + "' " +
                                  " and pay_month = '" + strpay_month + "'" +
                                  " and budget_type = '" + this.BudgetType + "'" +
                                  " and c_created_by = '" + UserLoginName + "' ";
                    if (!oItem_acc.SP_ITEM_ACC_HEAD_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            blnDup    = true;
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูลได้ เนื่องจาก" +
                                "\\n รอบเดือน : " + cboPay_Month.SelectedItem.Text + "   ปี : " + strpay_year +
                                "\\nซ้ำ\");\n";
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPage", strScript, true);
                        }
                        else
                        {
                            if (!oItem_acc.SP_ITEM_ACC_HEAD_INS(stritem_acc_year, strpay_month,
                                                                strpay_year, stritem_acc_comment, strc_user, "B", ref strMessage))
                            {
                                lblError.Text = strMessage;
                            }
                            else
                            {
                                DataSet dsCHK = new DataSet();
                                strCheckDup = " and pay_year = '" + strpay_year + "' " +
                                              " and pay_month = '" + strpay_month + "' " +
                                              " and budget_type = '" + this.BudgetType + "'" +
                                              " and c_created_by = '" + UserLoginName + "' ";
                                if (!oItem_acc.SP_ITEM_ACC_HEAD_SEL(strCheckDup, ref dsCHK, ref strMessage))
                                {
                                    lblError.Text = strMessage;
                                }
                                else
                                {
                                    stritem_acc_doc           = dsCHK.Tables[0].Rows[0]["item_acc_doc"].ToString();
                                    ViewState["item_acc_doc"] = stritem_acc_doc;
                                    blnResult = true;
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region update
                    if (!oItem_acc.SP_ITEM_ACC_HEAD_UPD(stritem_acc_doc, stritem_acc_year, strpay_month, strpay_year,
                                                        stritem_acc_comment, strc_user, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        #region insert detail
                        GridViewRow gviewRow;
                        int         i;
                        for (i = 0; i <= GridView1.Rows.Count - 1; i++)
                        {
                            gviewRow = GridView1.Rows[i];
                            Label lblitem_acc_code = (Label)gviewRow.FindControl("lblitem_acc_code");
                            //if (lblitem_acc_code.Text != "")
                            //{
                            HiddenField hdditem_acc_detail_id = (HiddenField)gviewRow.FindControl("hdditem_acc_detail_id");
                            TextBox     txtitem_acc_deka      = (TextBox)gviewRow.FindControl("txtitem_acc_deka");
                            TextBox     txtitem_acc_group     = (TextBox)gviewRow.FindControl("txtitem_acc_group");
                            TextBox     txtitem_project_code  = (TextBox)gviewRow.FindControl("txtitem_project_code");
                            AwNumeric   txtitem_acc_amount    = (AwNumeric)gviewRow.FindControl("txtitem_acc_amount");
                            AwNumeric   txtitem_acc_tax       = (AwNumeric)gviewRow.FindControl("txtitem_acc_tax");
                            AwNumeric   txtitem_acc_total     = (AwNumeric)gviewRow.FindControl("txtitem_acc_total");
                            //Label lblitem_acc_code = (Label)gviewRow.FindControl("txtitem_code");
                            Label lblitem_code             = (Label)gviewRow.FindControl("lblitem_code");
                            Label lblproduce_code          = (Label)gviewRow.FindControl("lblproduce_code");
                            Label lblperson_group_code_acc = (Label)gviewRow.FindControl("lblperson_group_code_acc");
                            Label lblpayment_back_type     = (Label)gviewRow.FindControl("lblpayment_back_type");

                            stritem_acc_detail_id = hdditem_acc_detail_id.Value.ToString();
                            stritem_acc_deka      = txtitem_acc_deka.Text.Trim();
                            stritem_acc_group     = txtitem_acc_group.Text.Trim();
                            stritem_acc_amount    = txtitem_acc_amount.Value.ToString();
                            stritem_acc_tax       = txtitem_acc_tax.Value.ToString();
                            stritem_acc_total     = txtitem_acc_total.Value.ToString();
                            stritem_acc_code      = lblitem_acc_code.Text;
                            stritem_project_code  = txtitem_project_code.Text.Trim();
                            strproduce_code       = lblproduce_code.Text;
                            stritem_code          = lblitem_code.Text;

                            if (stritem_acc_detail_id != "0")
                            {
                                if (!oItem_acc.SP_ITEM_ACC_DETAIL_UPD(stritem_acc_detail_id, txtitem_acc_doc.Text.Trim(),
                                                                      stritem_acc_deka, stritem_acc_group, stritem_acc_amount,
                                                                      stritem_acc_tax, stritem_acc_total, stritem_acc_code,
                                                                      stritem_project_code, stritem_code, strproduce_code,
                                                                      ref strMessage))
                                {
                                    lblError.Text = strMessage;
                                }
                            }
                            else
                            {
                                if (!oItem_acc.SP_ITEM_ACC_DETAIL_INS(txtitem_acc_doc.Text.Trim(), stritem_acc_deka, stritem_acc_group,
                                                                      stritem_acc_amount, stritem_acc_tax, stritem_acc_total, stritem_acc_code,
                                                                      stritem_project_code, stritem_code, strproduce_code, lblperson_group_code_acc.Text.Trim(),
                                                                      lblpayment_back_type.Text, ref strMessage))
                                {
                                    lblError.Text = strMessage;
                                }
                            }
                            //}
                        }
                        #endregion
                        blnResult = true;
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oItem_acc.Dispose();
            }
            return(blnResult);
        }
示例#11
0
        private void setData()
        {
            cItem_acc oItem_acc = new cItem_acc();
            DataSet   ds = new DataSet();
            string    strMessage = string.Empty, strCriteria = string.Empty;
            string    stritem_acc_code = string.Empty,
                      stritem_acc_name = string.Empty,
                      strYear          = string.Empty,
                      strC_active      = string.Empty,
                      strCreatedBy     = string.Empty,
                      strUpdatedBy     = string.Empty,
                      strCreatedDate   = string.Empty,
                      strUpdatedDate   = string.Empty;

            try
            {
                strCriteria = " and item_acc_id = '" + ViewState["item_acc_id"].ToString() + "' ";
                if (!oItem_acc.SP_ITEM_ACC_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        stritem_acc_code = ds.Tables[0].Rows[0]["item_acc_code"].ToString();
                        stritem_acc_name = ds.Tables[0].Rows[0]["item_acc_name"].ToString();
                        strYear          = ds.Tables[0].Rows[0]["item_acc_year"].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
                        hdditem_acc_id.Value  = ds.Tables[0].Rows[0]["item_acc_id"].ToString();
                        txtitem_acc_code.Text = stritem_acc_code;
                        txtitem_acc_name.Text = stritem_acc_name;
                        InitcboYear();
                        if (cboYear.Items.FindByValue(strYear) != null)
                        {
                            cboYear.SelectedIndex = -1;
                            cboYear.Items.FindByValue(strYear).Selected = true;
                        }
                        if (strC_active.Equals("Y"))
                        {
                            txtitem_acc_name.ReadOnly = false;
                            txtitem_acc_name.CssClass = "textbox";
                            chkStatus.Checked         = true;
                        }
                        else
                        {
                            txtitem_acc_name.ReadOnly = true;
                            txtitem_acc_name.CssClass = "textboxdis";
                            chkStatus.Checked         = false;
                        }
                        cboYear.Enabled     = false;
                        cboYear.CssClass    = "textboxdis";
                        txtUpdatedBy.Text   = strUpdatedBy;
                        txtUpdatedDate.Text = strUpdatedDate;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
示例#12
0
        private bool saveData()
        {
            bool   blnResult        = false;
            bool   blnDup           = false;
            string strMessage       = string.Empty;
            string stritem_acc_code = string.Empty,
                   stritem_acc_year = string.Empty,
                   stritem_acc_name = string.Empty,
                   strActive        = string.Empty,
                   strCreatedBy     = string.Empty,
                   strUpdatedBy     = string.Empty;
            string    strScript     = string.Empty;
            cItem_acc oItem_acc     = new cItem_acc();
            DataSet   ds            = new DataSet();

            try
            {
                #region set Data
                stritem_acc_code = txtitem_acc_code.Text.Trim();
                stritem_acc_name = txtitem_acc_name.Text;
                stritem_acc_year = cboYear.SelectedItem.Value;
                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 (oItem_acc.SP_ITEM_ACC_UPD(hdditem_acc_id.Value.ToString(), stritem_acc_code,
                                                      stritem_acc_year, stritem_acc_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 item_acc_name = '" + stritem_acc_name.Trim() + "' and item_acc_year = '" + stritem_acc_year + "' ";
                    if (!oItem_acc.SP_ITEM_ACC_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + stritem_acc_name.Trim() + " ปี " + stritem_acc_year.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oItem_acc.SP_ITEM_ACC_INS(stritem_acc_year, stritem_acc_code, stritem_acc_name, strActive, strCreatedBy, ref strMessage))
                        {
                            string strGetcode = " and item_acc_name = '" + stritem_acc_name.Trim() + "' and item_acc_year = '" + stritem_acc_year + "' ";
                            if (!oItem_acc.SP_ITEM_ACC_SEL(strGetcode, ref ds, ref strMessage))
                            {
                                lblError.Text = strMessage;
                            }
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                stritem_acc_code = ds.Tables[0].Rows[0]["item_acc_id"].ToString();
                            }
                            ViewState["item_acc_id"] = stritem_acc_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
            {
                oItem_acc.Dispose();
            }
            return(blnResult);
        }