Example #1
0
        public bool SP_ITEM_GROUP_DETAIL_INS(Item_group_detail Item_group_detail)
        {
            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_ITEM_GROUP_DETAIL_INS";
                oCommand.Parameters.Add("item_group_detail_code", SqlDbType.VarChar).Value = Item_group_detail.item_group_detail_code;
                oCommand.Parameters.Add("item_group_detail_name", SqlDbType.VarChar).Value = Item_group_detail.item_group_detail_name;
                oCommand.Parameters.Add("item_group_code", SqlDbType.VarChar).Value        = Item_group_detail.item_group_code;
                oCommand.Parameters.Add("c_active", SqlDbType.VarChar).Value     = Item_group_detail.c_active;
                oCommand.Parameters.Add("c_created_by", SqlDbType.VarChar).Value = Item_group_detail.c_created_by;
                oCommand.ExecuteNonQuery();
                blnResult = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oConn.Close();
                oCommand.Dispose();
                oConn.Dispose();
            }
            return(blnResult);
        }
Example #2
0
        private bool saveData()
        {
            bool               blnResult          = false;
            string             strMessage         = string.Empty;
            string             strScript          = string.Empty;
            Item_group_detail  item_group_detail  = new Item_group_detail();
            cItem_group_detail oItem_group_detail = new cItem_group_detail();
            DataSet            ds = new DataSet();

            try
            {
                #region set Data
                item_group_detail.item_group_detail_id   = string.IsNullOrEmpty(hdditem_group_detail_id.Value) ? 0 : int.Parse(hdditem_group_detail_id.Value);
                item_group_detail.item_group_detail_code = txtitem_group_detail_code.Text.Trim();
                item_group_detail.item_group_detail_name = txtitem_group_detail_name.Text.Trim();
                item_group_detail.item_group_code        = cboItemGroup.SelectedValue;
                item_group_detail.c_active     = chkStatus.Checked == true ? "Y" : "N";
                item_group_detail.c_created_by = Session["username"].ToString();
                item_group_detail.c_updated_by = Session["username"].ToString();
                #endregion

                string strCheckAdd = " and item_group_detail_id = '" + item_group_detail.item_group_detail_id + "' ";
                var    item        = oItem_group_detail.GET(strCheckAdd);
                if (item != null)
                {
                    blnResult = oItem_group_detail.SP_ITEM_GROUP_DETAIL_UPD(item_group_detail);
                }
                else
                {
                    blnResult = oItem_group_detail.SP_ITEM_GROUP_DETAIL_INS(item_group_detail);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate key"))
                {
                    strScript = @"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก";
                    if (ex.Message.Contains("IX_item_group_detail_code"))
                    {
                        strScript += "ข้อมูลรหัสรายละเอียดหมวดค่าใช้จ่าย : " + txtitem_group_detail_code.Text + " ซ้ำ";
                    }
                    else if (ex.Message.Contains("IX_item_group_detail_name"))
                    {
                        strScript += "ข้อมูลรายละเอียดหมวดค่าใช้จ่าย : " + txtitem_group_detail_name.Text + " ซ้ำ";
                    }
                    MsgBox(strScript);
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oItem_group_detail.Dispose();
            }
            return(blnResult);
        }