private void ClearBudgetPlan()
        {
            txtbudget_plan_code.Text = string.Empty;
            txtdirector_name.Text    = string.Empty;
            txtunit_name.Text        = string.Empty;
            txtbudget_name.Text      = string.Empty;
            txtproduce_name.Text     = string.Empty;
            txtactivity_name.Text    = string.Empty;
            txtplan_name.Text        = string.Empty;
            txtwork_name.Text        = string.Empty;
            txtfund_name.Text        = string.Empty;

            if (ViewState["mode"].ToString() == "edit")
            {
                cBudget_open obudget_open = new cBudget_open();
                try
                {
                    obudget_open.SP_BUDGET_OPEN_DETAIL_DEL_BY_DOC(txtbudget_open_doc.Text);
                    BindGridDetail();
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                    throw ex;
                }
                finally
                {
                    obudget_open.Dispose();
                }
            }
        }
        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        lblbudget_open_doc = (Label)GridView1.Rows[e.RowIndex].FindControl("lblbudget_open_doc");
            cBudget_open oBudget_open       = new cBudget_open();

            try
            {
                oBudget_open.SP_BUDGET_OPEN_HEAD_DEL(lblbudget_open_doc.Text);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("REFERENCE constraint"))
                {
                    MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oBudget_open.Dispose();
            }
            BindGridView(0);
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string       strMessage = string.Empty;
            string       strScript  = string.Empty;
            HiddenField  hddbudget_open_detail_id = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hddbudget_open_detail_id");
            cBudget_open oBudget_open             = new cBudget_open();

            try
            {
                oBudget_open.SP_BUDGET_OPEN_DETAIL_DEL(hddbudget_open_detail_id.Value);
                oBudget_open.SP_BUDGET_OPEN_TOTAL_UPD(txtbudget_open_doc.Text);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("REFERENCE constraint"))
                {
                    MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oBudget_open.Dispose();
            }
            BindGridDetail();
        }
        private bool saveDataDetail()
        {
            bool               blnResult                = false;
            string             strScript                = string.Empty;
            cBudget_open       oBudget_open             = new cBudget_open();
            HiddenField        hddbudget_open_detail_id = null;
            TextBox            txtmaterial_detail       = null;
            AwNumeric          txtopen_detail_amount    = null;
            Budget_open_detail budget_open_detail       = null;

            try
            {
                for (var index = 0; index < GridView1.Rows.Count; index++)
                {
                    hddbudget_open_detail_id = (HiddenField)GridView1.Rows[index].FindControl("hddbudget_open_detail_id");
                    txtmaterial_detail       = (TextBox)GridView1.Rows[index].FindControl("txtmaterial_detail");
                    txtopen_detail_amount    = (AwNumeric)GridView1.Rows[index].FindControl("txtopen_detail_amount");
                    if (!string.IsNullOrEmpty(hddbudget_open_detail_id.Value))
                    {
                        budget_open_detail = new Budget_open_detail
                        {
                            budget_open_doc           = ViewState["budget_open_doc"].ToString(),
                            budget_open_detail_id     = long.Parse(hddbudget_open_detail_id.Value),
                            budget_open_detail_amount = decimal.Parse(txtopen_detail_amount.Value.ToString()),
                            material_detail           = txtmaterial_detail.Text,
                            c_updated_by = Session["username"].ToString()
                        };
                        oBudget_open.SP_BUDGET_OPEN_DETAIL_UPD(budget_open_detail);
                    }
                }
                blnResult = true;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate key"))
                {
                    MsgBox("ข้อมูลซ้ำโปรดตรวจสอบ");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oBudget_open.Dispose();
            }
            return(blnResult);
        }
示例#5
0
        private bool saveData()
        {
            bool   blnResult    = false;
            string strUpdatedBy = string.Empty;

            strUpdatedBy = Session["username"].ToString();
            CheckBox           chkSelect;
            HiddenField        hddbudget_money_major_id;
            var                oBudget_open       = new cBudget_open();
            Budget_open_detail budget_open_detail = null;

            try
            {
                foreach (GridViewRow gvRow in GridView1.Rows)
                {
                    chkSelect = (CheckBox)gvRow.FindControl("chkSelect");
                    var select = Request.Form[chkSelect.UniqueID];
                    if (select != null && select == "on")
                    {
                        hddbudget_money_major_id = (HiddenField)gvRow.FindControl("hddbudget_money_major_id");
                        budget_open_detail       = new Budget_open_detail()
                        {
                            budget_open_doc           = ViewState["budget_open_doc"].ToString(),
                            budget_money_major_id     = long.Parse(hddbudget_money_major_id.Value),
                            budget_open_detail_amount = 0,
                            budget_open_detail_remark = string.Empty,
                            c_created_by = strUpdatedBy
                        };
                        oBudget_open.SP_BUDGET_OPEN_DETAIL_INS(budget_open_detail);
                    }
                    blnResult = true;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
            finally
            {
                oBudget_open.Dispose();
            }
            return(blnResult);
        }
        private void BindGridView(int nPageNo)
        {
            var     oBudget_open     = new cBudget_open();
            DataSet ds               = new DataSet();
            string  strMessage       = string.Empty;
            string  strCriteria      = string.Empty;
            var     budget_open_head = new view_Budget_open_head();
            string  strScript        = string.Empty;

            #region Criteria
            budget_open_head.budget_open_year    = cboYear.SelectedValue;
            budget_open_head.degree_code         = cboDegree.SelectedValue;
            budget_open_head.budget_open_doc     = txtbudget_plan_code.Text.Replace("'", "''").Trim();
            budget_open_head.open_code           = string.IsNullOrEmpty(txtopen_code.Text) ? 0 : int.Parse(txtopen_code.Text);
            budget_open_head.open_title          = txtopen_title.Text;
            budget_open_head.budget_plan_code    = txtbudget_plan_code.Text;
            budget_open_head.unit_code           = cboUnit.SelectedValue;
            budget_open_head.budget_code         = cboBudget.SelectedValue;
            budget_open_head.produce_code        = cboProduce.SelectedValue;
            budget_open_head.activity_code       = cboActivity.SelectedValue;
            budget_open_head.major_code          = cboMajor.SelectedValue;
            budget_open_head.approve_head_status = cboApproveStatus.SelectedValue;

            budget_open_head.budget_open_no        = txtbudget_open_no.Text.Trim();
            budget_open_head.budget_open_ap        = txtbudget_open_ap.Text.Trim();
            budget_open_head.budget_open_pr        = txtbudget_open_pr.Text.Trim();
            budget_open_head.budget_open_budget_no = txtbudget_open_budget_no.Text.Trim();


            if (!string.IsNullOrEmpty(txtdate_begin.Text))
            {
                strCriteria = strCriteria + "  And  (budget_open_date >= '" + cCommon.SeekDate(txtdate_begin.Text) + "') ";
            }

            if (!string.IsNullOrEmpty(txtdate_end.Text))
            {
                strCriteria = strCriteria + "  And  (budget_open_date <= '" + cCommon.SeekDate(txtdate_end.Text) + "') ";
            }

            if (!string.IsNullOrEmpty(txtdate_actual_begin.Text))
            {
                strCriteria = strCriteria + "  And  (budget_open_date_actual >= '" + cCommon.SeekDate(txtdate_actual_begin.Text) + "') ";
            }

            if (!string.IsNullOrEmpty(txtdate_actual_end.Text))
            {
                strCriteria = strCriteria + "  And  (budget_open_date_actual <= '" + cCommon.SeekDate(txtdate_actual_end.Text) + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.budget_open_year))
            {
                strCriteria = strCriteria + "  And  (budget_open_year = '" + budget_open_head.budget_open_year + "') ";
            }
            if (!string.IsNullOrEmpty(budget_open_head.degree_code))
            {
                strCriteria = strCriteria + "  And  (degree_code ='" + budget_open_head.degree_code + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.budget_open_doc))
            {
                strCriteria = strCriteria + "  And  (budget_open_doc LIKE '%" + budget_open_head.budget_open_doc + "%') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.budget_open_no))
            {
                strCriteria = strCriteria + "  And  (budget_open_no LIKE '%" + budget_open_head.budget_open_no + "%') ";
            }


            if (!string.IsNullOrEmpty(budget_open_head.budget_open_ap))
            {
                strCriteria = strCriteria + "  And  (budget_open_ap LIKE '%" + budget_open_head.budget_open_ap + "%') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.budget_open_pr))
            {
                strCriteria = strCriteria + "  And  (budget_open_pr LIKE '%" + budget_open_head.budget_open_pr + "%') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.budget_open_budget_no))
            {
                strCriteria = strCriteria + "  And  (budget_open_budget_no LIKE '%" + budget_open_head.budget_open_budget_no + "%') ";
            }


            if (budget_open_head.open_code > 0)
            {
                strCriteria = strCriteria + "  And  (open_code ='" + budget_open_head.open_code + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.open_title))
            {
                strCriteria = strCriteria + "  And  (open_title ='" + budget_open_head.open_title + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.budget_plan_code))
            {
                strCriteria = strCriteria + "  And  (budget_plan_code ='" + budget_open_head.budget_plan_code + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.unit_code))
            {
                strCriteria = strCriteria + "  And  (unit_code ='" + budget_open_head.unit_code + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.budget_code))
            {
                strCriteria = strCriteria + "  And  (budget_code ='" + budget_open_head.budget_code + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.produce_code))
            {
                strCriteria = strCriteria + "  And  (produce_code ='" + budget_open_head.produce_code + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.activity_code))
            {
                strCriteria = strCriteria + "  And  (activity_code = '" + budget_open_head.activity_code + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.major_code))
            {
                strCriteria = strCriteria + "  And  (major_code = '" + budget_open_head.major_code + "') ";
            }

            if (!string.IsNullOrEmpty(budget_open_head.approve_head_status))
            {
                strCriteria = strCriteria + "  And  (approve_head_status = '" + budget_open_head.approve_head_status + "') ";
            }

            if (!string.IsNullOrEmpty(txtdescription.Text))
            {
                strCriteria = strCriteria + "  And  (budget_open_doc IN (SELECT budget_open_doc from view_Budget_open_detail where item_detail_name like '%" + txtdescription.Text.Trim() + "%') ) ";
            }

            if (DirectorLock == "Y")
            {
                strCriteria += " and substring(director_code,4,2) = substring('" + DirectorCode + "',4,2) ";
            }

            if (MajorLock == "Y")
            {
                strCriteria += " and major_code = '" + PersonMajorCode + "' ";
            }

            #endregion

            strCriteria = strCriteria + " and budget_type ='" + this.BudgetType + "' ";

            try
            {
                if (!oBudget_open.SP_BUDGET_OPEN_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
            {
                oBudget_open.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
        private bool saveData()
        {
            bool             blnResult        = false;
            Budget_open_head budget_open_head = new Budget_open_head();
            cBudget_open     obudget_open     = new cBudget_open();

            try
            {
                #region set Data
                budget_open_head.budget_open_doc  = txtbudget_open_doc.Text;
                budget_open_head.degree_code      = cboDegree.SelectedValue;
                budget_open_head.budget_open_date = cCommon.GetDate(Request.Form[txtbudget_open_date.UniqueID]);
                if (!string.IsNullOrEmpty(Request.Form[txtbudget_open_date_actual.UniqueID]))
                {
                    budget_open_head.budget_open_date_actual = cCommon.GetDate(Request.Form[txtbudget_open_date_actual.UniqueID]);
                }
                budget_open_head.budget_type      = cboBudget_type.SelectedValue;
                budget_open_head.budget_open_year = cboYear.SelectedValue;
                budget_open_head.major_code       = cboMajor.SelectedValue;
                budget_open_head.budget_plan_code = txtbudget_plan_code.Text;

                budget_open_head.budget_open_no = txtbudget_open_no.Text.Trim();
                budget_open_head.budget_open_ap = txtbudget_open_ap.Text.Trim();
                budget_open_head.budget_open_pr = txtbudget_open_pr.Text.Trim();

                budget_open_head.budget_open_budget_no = txtbudget_open_budget_no.Text.Trim();
                budget_open_head.ef_open_doc           = txtef_open_doc.Text;
                if (!string.IsNullOrEmpty(txtopen_code.Text))
                {
                    budget_open_head.open_code = int.Parse(txtopen_code.Text);
                }
                budget_open_head.open_title        = txtopen_title.Text.Trim();
                budget_open_head.open_command_desc = txtopen_command_desc.Text.Trim();
                budget_open_head.open_desc         = txtopen_desc.Text.Trim();

                budget_open_head.open_remark         = txtopen_remark.Text.Trim();
                budget_open_head.approve_head_status = cboApproveStatus.SelectedValue;
                budget_open_head.person_open         = txtperson_code.Text;

                budget_open_head.c_created_by = Session["username"].ToString();
                budget_open_head.c_updated_by = Session["username"].ToString();
                #endregion
                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    if (obudget_open.SP_BUDGET_OPEN_HEAD_UPD(budget_open_head))
                    {
                        saveDataDetail();
                        obudget_open.SP_BUDGET_OPEN_TOTAL_UPD(txtbudget_open_doc.Text);
                    }
                }
                else
                {
                    obudget_open.SP_BUDGET_OPEN_HEAD_INS(budget_open_head);
                    ViewState["budget_open_doc"] = budget_open_head.budget_open_doc;
                }
                blnResult = true;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate key"))
                {
                    MsgBox("ข้อมูลซ้ำโปรดตรวจสอบ");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                obudget_open.Dispose();
            }
            return(blnResult);
        }