예제 #1
0
        public bool SP_BUDGET_MONEY_HEAD_INS(Budget_money_head budget_money_head)
        {
            bool           blnResult = false;
            SqlConnection  oConn     = new SqlConnection();
            SqlCommand     oCommand  = new SqlCommand();
            SqlDataAdapter oAdapter  = new SqlDataAdapter();

            try
            {
                oConn.ConnectionString = _strConn;
                oConn.Open();
                oCommand.Connection  = oConn;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.CommandText = "sp_BUDGET_MONEY_HEAD_INS";

                SqlParameter oParambudget_money_doc = new SqlParameter("budget_money_doc", SqlDbType.VarChar, 10)
                {
                    Direction = ParameterDirection.Output,
                    Value     = budget_money_head.budget_money_doc
                };
                oCommand.Parameters.Add(oParambudget_money_doc);
                //oCommand.Parameters.Add("budget_money_doc", SqlDbType.VarChar).Value = budget_money_head.budget_money_doc;

                oCommand.Parameters.Add("budget_money_year", SqlDbType.VarChar).Value       = budget_money_head.budget_money_year;
                oCommand.Parameters.Add("budget_type", SqlDbType.VarChar).Value             = budget_money_head.budget_type;
                oCommand.Parameters.Add("budget_plan_code", SqlDbType.VarChar).Value        = budget_money_head.budget_plan_code;
                oCommand.Parameters.Add("degree_code", SqlDbType.VarChar).Value             = budget_money_head.degree_code;
                oCommand.Parameters.Add("budget_money_plan", SqlDbType.Money).Value         = budget_money_head.budget_money_plan;
                oCommand.Parameters.Add("budget_money_contribute", SqlDbType.VarChar).Value = budget_money_head.budget_money_contribute;
                oCommand.Parameters.Add("budget_money_use", SqlDbType.VarChar).Value        = budget_money_head.budget_money_use;
                oCommand.Parameters.Add("c_active", SqlDbType.VarChar).Value     = budget_money_head.c_active;
                oCommand.Parameters.Add("c_created_by", SqlDbType.VarChar).Value = budget_money_head.c_created_by;
                oCommand.ExecuteNonQuery();
                budget_money_head.budget_money_doc = oParambudget_money_doc.Value.ToString();

                blnResult = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oConn.Close();
                oCommand.Dispose();
                oConn.Dispose();
            }
            return(blnResult);
        }
        private bool saveData()
        {
            bool blnResult = false;
            Budget_money_head budget_money_head = new Budget_money_head();
            cBudget_money     oBudget_money     = new cBudget_money();

            try
            {
                #region set Data
                budget_money_head.budget_money_doc  = txtbudget_money_doc.Text;
                budget_money_head.budget_money_year = cboYear.SelectedValue;
                budget_money_head.budget_type       = cboBudget_type.SelectedValue;
                budget_money_head.budget_plan_code  = txtbudget_plan_code.Text;
                budget_money_head.degree_code       = cboDegree.SelectedValue;
                budget_money_head.comments          = txtcomment.Text.Trim();
                budget_money_head.c_active          = chkStatus.Checked == true ? "Y" : "N";
                budget_money_head.c_created_by      = Session["username"].ToString();
                budget_money_head.c_updated_by      = Session["username"].ToString();
                #endregion
                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    oBudget_money.SP_BUDGET_MONEY_HEAD_UPD(budget_money_head);
                }
                else
                {
                    oBudget_money.SP_BUDGET_MONEY_HEAD_INS(budget_money_head);
                    ViewState["budget_money_doc"] = budget_money_head.budget_money_doc;
                }
                blnResult = true;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate key"))
                {
                    MsgBox("ข้อมูลซ้ำโปรดตรวจสอบ");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oBudget_money.Dispose();
            }
            return(blnResult);
        }