void inventoryCheckingView_FillProductMasterToComboEvent(object sender, InventoryCheckingEventArgs e)
        {
            IList stockList = StockLogic.FindByProductMasterName();
            IList stockViewList = new ArrayList();
            if(stockList!=null)
            {
                foreach (IList list in stockList)
                {
                    StockView stockView = new StockView();
                    stockView.ProductMaster = (ProductMaster) list[0];
                    stockView.StockQuantity = (long) list[1];
                    stockViewList.Add(stockView);
                }

            }
            e.ReturnStockViewList = stockViewList;
        }
 void inventoryCheckingView_LoadGoodsByProductIdEvent(object sender, InventoryCheckingEventArgs e)
 {
     ObjectCriteria objectCriteria  = new ObjectCriteria();
     objectCriteria.AddEqCriteria("Product.ProductId", e.InputBarcode);
     objectCriteria.AddEqCriteria("DelFlg", (long)0);
     IList stockList = StockLogic.FindAll(objectCriteria);
     if(stockList != null && stockList.Count > 0)
     {
         e.ScannedStock = (Stock)stockList[0];
     }
     else
     {
         e.ScannedStock = null;
     }
     IList stockDefectList = StockLogic.FindAll(objectCriteria);
     if(stockDefectList!=null && stockDefectList.Count > 0)
     {
         e.ScannedStock = (Stock)stockDefectList[0];
     }
     else
     {
         e.ScannedStock = null;
     }
 }
 private void LoadGoodsToCombo()
 {
     InventoryCheckingEventArgs checkingEventArgs = new InventoryCheckingEventArgs();
     EventUtility.fireEvent(FillProductMasterToComboEvent,this,checkingEventArgs);
     stockViewList.Clear();
     foreach(var obj in checkingEventArgs.ReturnStockViewList)
     {
         stockViewList.Add((StockView)obj);
     }
     bdsProductMasters.EndEdit();
 }
        void inventoryCheckingView_SaveInventoryCheckingEvent(object sender, InventoryCheckingEventArgs e)
        {
            if(e.SaveStockList!=null && e.SaveStockList.Count > 0)
               {

               foreach (Stock stock in e.SaveStockList)
               {
                   stock.CreateDate = DateTime.Now;
                   stock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                   stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                   stock.UpdateDate = DateTime.Now;
                   stock.DelFlg = 0;

                   // calculate business
                   StockLogic.Update(stock);

                   e.HasErrors = false;

               }
               }
        }
        private void LoadGoodsByProductId(string id)
        {
            InventoryCheckingEventArgs checkingEventArgs = new InventoryCheckingEventArgs();
            /*if (!DepartmentChecking)
            {*/
                /* ----------------- STOCK CHECKING --------------*/
                checkingEventArgs.InputBarcode = id;
                EventUtility.fireEvent(LoadGoodsByProductIdEvent, this, checkingEventArgs);
                Stock stock = checkingEventArgs.ScannedStock;
                if (stock == null)
                {
                    MessageBox.Show("Không tìm thấy mã vạch trong kho", "Lỗi");
                    return;
                }

                if (stock.ProductMaster.ProductType != null)
                    txtProductType.Text = stock.ProductMaster.ProductType.TypeName;

                txtProductName.Text = stock.ProductMaster.ProductName;

                txtDescription.Text = stock.ProductMaster.Description;
                pictureBox1.ImageLocation = stock.ProductMaster.ImagePath;
                if (!string.IsNullOrEmpty(pictureBox1.ImageLocation))
                {
                    if(File.Exists(pictureBox1.ImageLocation)) pictureBox1.Load();
                }

                int stockDefIndex = -1;
                Stock foundStock = GetFromStockList(stock, stockList);

                if(foundStock != null)
                {
                    foundStock.GoodQuantity += 1;
                }
                else
                {
                    stock.GoodQuantity = 1;
                   stockList.Add(stock);
                }
                /*if (HasInStockList(stock, stockList, out stockDefIndex))
                {
                    if (stockDefIndex > -1 && stockDefIndex < stockList.Count)
                    {
                        stockList[stockDefIndex].GoodQuantity += 1;
                        dgvStock.CurrentCell = dgvStock[5, stockDefIndex];
                    }

                }
                else // create new stock defect row
                {
                        Stock newStockDefect = stockList.AddNew();

                        // assign total quantity
                        Stock defect = checkingEventArgs.ScannedStock;
                        stockList[stockList.Count - 1] = defect;

                        txtStockQuantity.Text = stockList[stockList.Count - 1].Quantity.ToString("##,##0");

                        stockList[stockList.Count - 1].OldGoodQuantity = stockList[stockList.Count - 1].GoodQuantity = 1;

                        stockList[stockList.Count - 1].OldDamageQuantity = stockList[stockList.Count - 1].DamageQuantity = 0;

                        stockList[stockList.Count - 1].OldErrorQuantity =stockList[stockList.Count - 1].ErrorQuantity = 0;

                        stockList[stockList.Count - 1].OldUnconfirmQuantity = stockList[stockList.Count - 1].UnconfirmQuantity = 0;

                        stockList[stockList.Count - 1].OldLostQuantity = stockList[stockList.Count - 1].LostQuantity = 0;

                    dgvStock.CurrentCell = dgvStock[5, stockList.Count - 1];
                }*/

                    /* ----------------- DEPARTMENT STOCK CHECKING --------------*/

                bdsStockDefect.EndEdit();
                bdsStockDefect.ResetBindings(false);
                dgvStock.Refresh();
                dgvStock.Invalidate();
                int stockIndex = GetIndexFromList(stock, stockList);
                dgvStock.CurrentCell = dgvStock[5, stockIndex];
                txtBarcode.Text = "";
                txtBarcode.Focus();
        }
        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = false;
            fileDialog.CheckFileExists = true;
            fileDialog.CheckPathExists = true;
            fileDialog.Filter = "Text Files|*.txt";
            DialogResult result = fileDialog.ShowDialog();
            if (result == DialogResult.OK)
            {

                Dictionary<string, int> list = new Dictionary<string, int>();
                string path = fileDialog.FileName;
                StreamReader fileReader = new StreamReader(File.OpenRead(path));

                while (!fileReader.EndOfStream)
                {
                    string line = fileReader.ReadLine();
                    string[] parseLines = line.Split(',');

                    try
                    {
                        if (parseLines.Length == 2)
                        {
                            if (list.ContainsKey(parseLines[0].Trim()))
                            {
                                list[parseLines[0].Trim()] += Int32.Parse(parseLines[1].Trim());
                            }
                            else
                            {
                                list.Add(parseLines[0].Trim(), Int32.Parse(parseLines[1].Trim()));
                            }

                        }
                        else
                        {
                            if (list.ContainsKey(parseLines[0].Trim()))
                            {
                                list[parseLines[0].Trim()] += 1;
                            }
                            else
                            {
                                list.Add(parseLines[0].Trim(), 1);
                            }

                        }
                    }
                    catch (Exception)
                    {
                        if (_errorForm == null)
                        {
                            _errorForm = new ErrorForm();
                            _errorForm.Caption = "Lỗi";
                            _errorForm.ErrorString = "Các mã vạch bị lỗi khi nhập mã vạch từ file text";
                        }
                        _errorForm.ErrorDetails.Add(line);
                        continue;
                    }
                }

                foreach (KeyValuePair<string, int> barCodeLine in list)
                {
                    if (!string.IsNullOrEmpty(barCodeLine.Key) && barCodeLine.Key.Length == 12)
                    {
                        InventoryCheckingEventArgs checkingEventArgs = new InventoryCheckingEventArgs();
                        /*if (!DepartmentChecking)
                        {*/
                        /* ----------------- STOCK CHECKING --------------*/
                        checkingEventArgs.InputBarcode = barCodeLine.Key;
                        EventUtility.fireEvent(LoadGoodsByProductIdEvent, this, checkingEventArgs);
                        Stock stock = checkingEventArgs.ScannedStock;
                        if (stock == null)
                        {
                            MessageBox.Show("Không tìm thấy mã vạch trong kho", "Lỗi");
                            return;
                        }

                        if (stock.ProductMaster.ProductType != null)
                            txtProductType.Text = stock.ProductMaster.ProductType.TypeName;

                        txtProductName.Text = stock.ProductMaster.ProductName;

                        txtDescription.Text = stock.ProductMaster.Description;
                        pictureBox1.ImageLocation = stock.ProductMaster.ImagePath;
                        if (!string.IsNullOrEmpty(pictureBox1.ImageLocation))
                        {
                            if (File.Exists(pictureBox1.ImageLocation)) pictureBox1.Load();
                        }

                        int stockDefIndex = -1;
                        Stock foundStock = GetFromStockList(stock, stockList);

                        if (foundStock != null)
                        {
                            foundStock.GoodQuantity += barCodeLine.Value;
                        }
                        else
                        {
                            stock.GoodQuantity = barCodeLine.Value;
                            stockList.Add(stock);
                        }

                        /* ----------------- DEPARTMENT STOCK CHECKING --------------*/

                        bdsStockDefect.EndEdit();
                        bdsStockDefect.ResetBindings(false);
                        dgvStock.Refresh();
                        dgvStock.Invalidate();
                        int stockIndex = GetIndexFromList(stock, stockList);
                        dgvStock.CurrentCell = dgvStock[5, stockIndex];

                    }

                }

                txtBarcode.Text = "";
                txtBarcode.Focus();
                CalculateTotal();

                if (_errorForm != null)
                {
                    _errorForm.ShowDialog();
                    _errorForm = null;
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if(stockList.Count < 1)
            {
                MessageBox.Show("Không có gì để lưu");
                return;
            }
                /* ----------------- STOCK CHECKING --------------*/
                InventoryCheckingEventArgs checkingEventArgs = new InventoryCheckingEventArgs();
                checkingEventArgs.SaveStockList = ObjectConverter.ConvertToNonGenericList(stockList);
                if (!CheckDataIntegrity())
                {
                    DialogResult result = MessageBox.Show("Số lượng không khớp, bạn vẫn muốn lưu ?", "Cảnh báo",
                                                          MessageBoxButtons.YesNo);
                    if (result == DialogResult.No) return;
                }

                EventUtility.fireEvent(SaveInventoryCheckingEvent, this, checkingEventArgs);
                if (!checkingEventArgs.HasErrors)
                {
                    MessageBox.Show("Lưu kết quả thành công");
                    ClearForm();
                }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if(stockList.Count < 1)
     {
         MessageBox.Show("Không có gì để lưu");
         return;
     }
         /* ----------------- STOCK CHECKING --------------*/
         InventoryCheckingEventArgs checkingEventArgs = new InventoryCheckingEventArgs();
         checkingEventArgs.SaveStockList = ObjectConverter.ConvertToNonGenericList(stockList);
         if (!CheckDataIntegrity())
             return;
         EventUtility.fireEvent(SaveInventoryCheckingEvent, this, checkingEventArgs);
         if (!checkingEventArgs.HasErrors)
         {
             MessageBox.Show("Lưu kết quả thành công");
             ClearForm();
         }
 }
        void inventoryCheckingView_SaveInventoryCheckingEvent(object sender, InventoryCheckingEventArgs e)
        {
            if(e.SaveStockList!=null && e.SaveStockList.Count > 0)
               {
               /*foreach (Stock stock in e.SaveStockList)
               {
                   stock.CreateDate = DateTime.Now;
                   stock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                   stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                   stock.UpdateDate = DateTime.Now;
                   stock.DelFlg = 0;

                   // calculate business
                   StockLogic.Update(stock);

                   e.HasErrors = false;

               }*/
               // ++ AMEND FOR SHOES STOCK CHECKING 19/10/2009
               StockIn stockIn = new StockIn();
               stockIn.NotUpdateMainStock = false;
               stockIn.CreateDate = DateTime.Now;
               stockIn.UpdateDate = DateTime.Now;
               stockIn.StockInDate = DateTime.Now;
               stockIn.CreateId = ClientInfo.getInstance().LoggedUser.Name;
               stockIn.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
               stockIn.DelFlg = 0;
               stockIn.Description = " NHẬP TỪ SỐ LƯỢNG KIỂM KÊ";

               IList stockInDetailList = new ArrayList();
               foreach (Stock stock in e.SaveStockList)
               {
                   StockInDetail inDetail = new StockInDetail();
                   inDetail.CreateDate = DateTime.Now;
                   inDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                   inDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                   inDetail.UpdateDate = DateTime.Now;
                   inDetail.DelFlg = 0;
                   inDetail.Product = stock.Product;
                   inDetail.Quantity = stock.GoodQuantity;
                   inDetail.DelFlg = 0;
                   inDetail.StockIn = stockIn;
                   // calculate business
                   inDetail.StockInDetailPK = new StockInDetailPK
                                                  {
                                                      ProductId = stock.Product.ProductId
                                                  };
                   stockInDetailList.Add(inDetail);
               }
               stockIn.StockInDetails = stockInDetailList;
               StockInLogic.AddForStockOutToProducer(stockIn);
               e.HasErrors = false;
               // ++ AMEND FOR SHOES STOCK CHECKING 19/10/2009
               }
        }