public ProductAdjustmentHistoryCollection GetAllProductAdjustmentHistoryDynamicCollection(string whereExpression, string orderBy)
        {
            IDBManager dbm = new DBManager();
            ProductAdjustmentHistoryCollection cols = new ProductAdjustmentHistoryCollection();

            try
            {
                dbm.CreateParameters(2);
                dbm.AddParameters(0, "@WhereCondition", whereExpression);
                dbm.AddParameters(1, "@OrderByExpression", orderBy);
                IDataReader reader = dbm.ExecuteReader(CommandType.StoredProcedure, "SelectUsersDynamic");
                while (reader.Read())
                {
                    ProductAdjustmentHistory PAH = new ProductAdjustmentHistory();

                    PAH.ProductID        = Int32.Parse(reader["ProductID"].ToString());
                    PAH.AdjustedQuantity = Int32.Parse(reader["ProductID"].ToString());
                    PAH.Reason           = reader["Reason"].ToString();
                    PAH.ModifiedDate     = DateTime.Parse(reader["ModifiedDate"].ToString());
                    cols.Add(PAH);
                }
            }

            catch (Exception ex)
            {
                log.Write(ex.Message, "GetAllProductAdjustmentHistoryDynamicCollection");
                throw (ex);
            }
            finally
            {
                dbm.Dispose();
            }
            return(cols);
        }
        public ProductAdjustmentHistoryCollection GetAllProductAdjustmentHistoryCollection(int purchaseAdjustedQuantity)
        {
            IDBManager dbm = new DBManager();
            ProductAdjustmentHistoryCollection cols = new ProductAdjustmentHistoryCollection();

            try
            {
                dbm.CreateParameters(1);
                dbm.AddParameters(0, "@ProductID", purchaseAdjustedQuantity);
                IDataReader reader = dbm.ExecuteReader(CommandType.StoredProcedure, "SelectProductAdjustmentHistoryByAdjustedQuantity");
                while (reader.Read())
                {
                    ProductAdjustmentHistory PAH = new ProductAdjustmentHistory();
                    PAH.ProductID        = Int32.Parse(reader["ProductID"].ToString());
                    PAH.AdjustedQuantity = Int32.Parse(reader["AdjustedQuantity"].ToString());
                    PAH.Reason           = reader["Reason"].ToString();
                    PAH.ModifiedDate     = DateTime.Parse(reader["ModifiedDate"].ToString());

                    cols.Add(PAH);
                }
            }

            catch (Exception ex)
            {
                log.Write(ex.Message, "ProductAdjustmentHistoryCollection");
                throw (ex);
            }
            finally
            {
                dbm.Dispose();
            }
            return(cols);
        }
        public int AddProductAdjustmentHistory(ProductAdjustmentHistory PAH)
        {
            IDBManager dbm = new DBManager();

            try
            {
                dbm.CreateParameters(5);
                dbm.AddParameters(0, "@ProductID", PAH.ProductID);
                dbm.AddParameters(1, "@AdjustedQuantity", PAH.AdjustedQuantity);
                dbm.AddParameters(2, "@Reason", PAH.Reason);
                dbm.AddParameters(3, "@ModifiedDate", PAH.ModifiedDate);
                dbm.AddParameters(4, "@ID", PAH.ID);
                dbm.Parameters[4].Direction = ParameterDirection.Output;
                dbm.ExecuteNonQuery(CommandType.StoredProcedure, "InsertProductAdjustmentHistory");
                PAH.ID = Int32.Parse(dbm.Parameters[4].Value.ToString());
            }
            catch (Exception ex)
            {
                log.Write(ex.Message, "AddProductAdjustmentHistory");
                throw (ex);
            }
            finally
            {
                dbm.Dispose();
            }
            return(PAH.ID);
        }
Esempio n. 4
0
        private void AddProduct()
        {
            Product                  p       = new Product();
            Product                  product = new Product();
            ProductInventory         pi      = new ProductInventory();
            ProductAdjustmentHistory pah     = new ProductAdjustmentHistory();

            try
            {
                p = SetProduct();

                //pi.ProductID = p.ProductID;
                string qty = txtQuantity.Text.Trim() == string.Empty?"0" : txtQuantity.Text.Trim();
                pi.Quantity        = Int32.Parse(qty);
                pi.ModifiedDate    = DateTime.Now;
                pi.Shelf           = "2";
                pi.LocationID      = 1;
                pi.Bin             = 1;
                p.ProductInventory = pi;
                int productid = p.Exists(p.Name, p.Description);
                if (productid > 0)
                {
                    DialogResult result = MessageBox.Show("The product " + p.Name + " already exists\nWould you like to update it?", "MICS", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        p.ProductID = productid;
                        p.UpdateProduct(p);
                        PopulateGrid(String.Empty, String.Empty, p.ProductID);
                        MessageBox.Show("Record updated successfully", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Record is not saved", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    return;
                }
                p.ProductID = product.AddProduct(p);
                if (p.ProductID > 0)
                {
                    MessageBox.Show("Product Added");
                    PopulateGrid(String.Empty, String.Empty, p.ProductID);
                }
                else
                {
                    MessageBox.Show("Unable to add product");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                p = null;
            }

            // PopulateGrid(String.Empty, String.Empty,p.ProductID);
        }
Esempio n. 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (ValidateFields() == false)
            {
                return;
            }
            if (dgInventory.Rows.Count < 1 || InventoryAdjustmentCount == 0)
            {
                return;
            }
            // int selectedRows = dgInventory.SelectedRows.Count;

            int          selectedCount = 0;
            DialogResult result        = MessageBox.Show("You are about to adjust the inventory for " + InventoryAdjustmentCount.ToString() + " item(s). Are you sure you want proceed.?", "MICS", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.No)
            {
                return;
            }
            int  curIndex = 0;
            bool success  = true;

            for (int row = 0; row < dgInventory.Rows.Count; row++)
            {
                if (dsProductInventory.Tables[0].Rows[row]["AdjustedQuantity"] == DBNull.Value)
                {
                    continue;
                }
                if (selectedCount > InventoryAdjustmentCount)
                {
                    break;
                }
                selectedCount++;
                //DataGridViewRow row = dgInventory.CurrentRow;
                //int curIndex = dgInventory.CurrentRow.Index;
                curIndex = row;
                //if (row == null) return;


                Cursor.Current = Cursors.WaitCursor;
                ProductInventory         pi  = new ProductInventory();
                ProductAdjustmentHistory pah = new ProductAdjustmentHistory();
                // int adjustedQuantity = Int32.Parse(txtAdjustedQuanity.Text.Trim());
                //   string reason = txtReason.Text.Trim();


                try
                {
                    int productid   = Int32.Parse(dsProductInventory.Tables[0].Rows[row]["productid"].ToString()); //Int32.Parse(dgInventory.CurrentRow.Cells["productid"].Value.ToString());
                    int CurQuantity = 0;
                    int NewQuantity = 0;
                    if (dsProductInventory.Tables[0].Rows[row]["AdjustedQuantity"] != DBNull.Value)
                    {
                        NewQuantity = Int32.Parse(dsProductInventory.Tables[0].Rows[row]["AdjustedQuantity"].ToString());
                    }
                    if (dsProductInventory.Tables[0].Rows[row]["Quantity"] != DBNull.Value)
                    {
                        CurQuantity = Int32.Parse(dsProductInventory.Tables[0].Rows[row]["Quantity"].ToString());
                    }


                    pah.ProductID        = productid;
                    pah.AdjustedQuantity = NewQuantity - CurQuantity;
                    if (dsProductInventory.Tables[0].Rows[row]["Reason"] != DBNull.Value)
                    {
                        pah.Reason = dsProductInventory.Tables[0].Rows[row]["Reason"].ToString();
                    }
                    else
                    {
                        pah.Reason = "";
                    }
                    // pah.AdjustedQuantity = adjustedQuantity;
                    pah.ModifiedDate = DateTime.Now;
                    pah.AddProductAdjustmentHistory(pah);


                    pi.ProductID    = productid;
                    pi.Quantity     = NewQuantity;
                    pi.LocationID   = 0;
                    pi.ModifiedDate = DateTime.Now;
                    pi.Shelf        = "";
                    pi.Bin          = 0;
                    ProductInventory inv = new ProductInventory();
                    inv = inv.GetProductInventorys(productid);
                    //  pi.Quantity = (long) adjustedQuantity;
                    //pi.ModifiedDate = DateTime.Now;
                    if (inv.ProductID > 0)
                    {
                        pi.UpdateProductInventory(pi);
                    }
                    else
                    {
                        pi.AddProductInventory(pi);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Product Inventory", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Cursor.Current = Cursors.Default;
                    success        = false;
                    break;
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
            if (success)
            {
                MessageBox.Show("Inventory Adjusted successfully.", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Inventory Adjustment failed.", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            Search(curIndex);
        }