Ejemplo n.º 1
0
        public void InsertIntoBranch(ProductsInBranches pib)
        {
            rowsAffected = 0;

            // Create SQL statement to submit
            string sql = "INSERT INTO [Categories](Parent_Category,Category_Name )";

            sql += $" VALUES( '{pib.Product_code}','{pib.Branch_name}', '{pib.Quantity}')";

            try
            {
                using (SqlConnection cnn = new SqlConnection(AppSettings.ConnectionString))
                {
                    // Create command object in using block for automatic disposal
                    using (SqlCommand cmd = new SqlCommand(sql, cnn))
                    {
                        // Set CommandType
                        cmd.CommandType = CommandType.Text;
                        // Open the connection
                        cnn.Open();
                        // Execute the INSERT statement
                        rowsAffected = cmd.ExecuteNonQuery();

                        ResultText = "Rows Affected: " + rowsAffected.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                ResultText = ex.ToString();
            }
        }
Ejemplo n.º 2
0
 public ActionResult DeleteProductInBranches([FromBody] ProductsInBranches products_In_Branches, string product_code)
 {
     try
     {
         DataAccessPIB da = new DataAccessPIB();
         da.DeleteProductInBranches(product_code);
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
     return(Ok());
 }
Ejemplo n.º 3
0
 public ActionResult PostProductInBranch(ProductsInBranches pib)
 {
     try
     {
         DataAccessPIB da = new DataAccessPIB();
         da.InsertIntoBranch(pib);
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
     return(Ok());
 }
        /// <summary>
        /// Add or Update Product in Branch
        /// </summary>
        /// <param name="productInBranch"></param>
        /// <returns></returns>
        public Int32 AddUpdateProductInBranch(ProductsInBranches productInBranch)
        {
            #region Parameters

            IParameter[] parameters = new Parameter[] {
                new Parameter("@ProductID", productInBranch.ProductID),
                new Parameter("@BranchID", productInBranch.BranchID),
                new Parameter("@Enable", productInBranch.Enable),
                new Parameter("@Price", productInBranch.Price)
            };

            #endregion
            object result = DBHandler.ExecuteScalar(System.Data.CommandType.StoredProcedure, "[BranchProduct_AddUpdateProductInBranch]", parameters);
            return(Convert.ToInt32(result));
        }
Ejemplo n.º 5
0
    protected void SaveBtn_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(txtBranch.SelectedValue) && !string.IsNullOrEmpty(txtProduct.SelectedValue) && txtPrice.Value != null)
            {
                ProductsInBranches productInBranch = new ProductsInBranches();
                int result = 0;
                productInBranch.BranchID  = Int32.Parse(txtBranch.SelectedValue);
                productInBranch.ProductID = Int32.Parse(txtProduct.SelectedValue);
                productInBranch.Price     = txtPrice.Value.Value;
                productInBranch.Enable    = txtActive.Checked;

                result = _prodictInBranchManager.AddUpdateProductInBranch(productInBranch);
                if (result > 0)
                {
                    if (ViewStateID != null)
                    {
                        ShowMessage(txtProduct.SelectedItem.Text + " has been updated with default price of $" + txtPrice.Value, MessageType.Success);
                    }
                    else
                    {
                        ShowMessage(txtProduct.SelectedItem.Text + " added into branch(" + txtBranch.SelectedItem.Text + ") with default price of $" + txtPrice.Value, MessageType.Success);

                        BindProducts();
                    }
                    txtError.ForeColor     = System.Drawing.Color.Green;
                    txtError.ViewStateMode = System.Web.UI.ViewStateMode.Disabled;
                }
            }
            else
            {
                ShowMessage("There should be all values to make new entry.", MessageType.Error);
            }
        }
        catch (Exception ex)
        {
            txtError.Text = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
        }
    }
Ejemplo n.º 6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         Int32 branchProductId = 0;
         if (Int32.TryParse(QueryStringParamID, out branchProductId))
         {
             ProductInBranchObj = _prodictInBranchManager.GetProductInBranchById(branchProductId);
             if (ProductInBranchObj != null)
             {
                 BindBranches();
                 BindProducts();
                 txtPrice.Value    = ProductInBranchObj.Price;
                 txtActive.Enabled = ProductInBranchObj.Enable;
                 ViewStateID       = QueryStringParamID.ToString();
             }
         }
         else
         {
             BindBranches();
             BindProducts();
         }
     }
 }