public void _departmentStockInView_UpdateDepartemntStockInForExportEvent(object sender, DepartmentStockInEventArgs e)
 {
     e.DepartmentStockIn.ExportStatus = CommonConstants.DEL_FLG_YES;
     e.DepartmentStockIn.UpdateDate = DateTime.Now;
     e.DepartmentStockIn.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
     DepartmentStockInLogic.UpdateExportStatus(e.DepartmentStockIn);
 }
 private void LoadProductMasterToComboBox()
 {
     var deptStockInEventArgs = new DepartmentStockInEventArgs();
     /*if (dgvDeptStockIn == null || dgvDeptStockIn.CurrentRow == null)
     {
         return;
     }*/
     // selectectIndex is the firstrow
     //int selectedIndex = 0;
     //mainStockInEventArgs.SelectedIndex = selectedIndex;
     //mainStockInEventArgs.SelectedStockInDetail = deptSIDetailList[selectedIndex];
     deptStockInEventArgs.SelectedDepartmentStockInDetail = new DepartmentStockInDetail { Product = new Product { ProductMaster = new ProductMaster { ProductName = "" } } };
     deptStockInEventArgs.IsFillToComboBox = true;
     deptStockInEventArgs.ComboBoxDisplayMember = "ProductName";
     EventUtility.fireEvent<DepartmentStockInEventArgs>(FillProductToComboEvent, cboProductMasters, deptStockInEventArgs);
 }
        private void dgvDeptStockIn_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            string columnName = dgvDeptStockIn.CurrentCell.OwningColumn.Name;
            if (columnName.Equals("columnProductId")
                || columnName.Equals("columnProductName"))
            {

                ComboBox comboBox = ((ComboBox)e.Control);

                // firstly, remove event regard to cell
                comboBox.DropDown -= new EventHandler(comboBox_DropDown);
                comboBox.KeyUp -= new KeyEventHandler(Control_KeyUp);

                comboBox.DroppedDown = false;

                comboBox.DataSource = null;
                comboBox.Text = (string)dgvDeptStockIn.CurrentCell.Value;
                comboBox.DropDown += new EventHandler(comboBox_DropDown);
                comboBox.KeyUp += new KeyEventHandler(Control_KeyUp);
            }

            DepartmentStockInEventArgs mainStockInEventArgs = new DepartmentStockInEventArgs();
            int selectedIndex = dgvDeptStockIn.CurrentRow.Index;
            mainStockInEventArgs.SelectedIndex = selectedIndex;
            mainStockInEventArgs.SelectedDepartmentStockInDetail = deptSIDetailList[selectedIndex];

            if(columnName.Equals("columnColor") )
            {
                // put colors to list
                EventUtility.fireEvent(LoadProductColorEvent, this, mainStockInEventArgs);
                if (mainStockInEventArgs.ProductColorList != null)
                {
                    ComboBox comboBox = ((ComboBox)e.Control);
                    comboBox.DataSource = mainStockInEventArgs.ProductColorList;
                    comboBox.DisplayMember = "ColorName";
                    comboBox.ValueMember = "ColorName";
                }
                mainStockInEventArgs.ProductColorList = null;
            }

            if( columnName.Equals("columnSize"))
            {
                // put size to list
                EventUtility.fireEvent(LoadProductSizeEvent, this, mainStockInEventArgs);
                if (mainStockInEventArgs.ProductSizeList != null)
                {
                    ComboBox comboBox = ((ComboBox)e.Control);
                    comboBox.DataSource = mainStockInEventArgs.ProductSizeList;
                    comboBox.DisplayMember = "SizeName";
                    comboBox.ValueMember = "SizeName";
                }
                mainStockInEventArgs.ProductSizeList = null;
            }
        }
        private void cboProductMasters_SelectedIndexChanged(object sender, EventArgs e)
        {
            ProductMaster proMaster = cboProductMasters.SelectedItem as ProductMaster;
            if (proMaster == null)
            {
                return;
            }
            string productName = proMaster.ProductName;
            BindingSource bindingSource = (BindingSource)cboProductMasters.DataSource;

            if (string.IsNullOrEmpty(productName))
            {
                return;
            }

            var mainStockInEventArgs = new DepartmentStockInEventArgs();
            mainStockInEventArgs.SelectedDepartmentStockInDetail = new DepartmentStockInDetail();
            mainStockInEventArgs.SelectedDepartmentStockInDetail.Product = new Product { ProductMaster = new ProductMaster() };
            mainStockInEventArgs.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductName = productName;
            EventUtility.fireEvent(LoadGoodsByNameEvent, this, mainStockInEventArgs);

            // clear the binding list
            colorBindingSource.Clear();
            sizeBindingSource.Clear();

            IList colorList = new ArrayList();
            IList sizeList = new ArrayList();
            foreach (ProductMaster productMaster in mainStockInEventArgs.FoundProductMasterList)
            {
                if (productMaster.ProductColor != null)
                {
                    bool found = false;
                    foreach (ProductColor color in colorList)
                    {
                        if (color.ColorId == productMaster.ProductColor.ColorId)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        colorList.Add(productMaster.ProductColor);
                    }
                }
                if (productMaster.ProductSize != null)
                {
                    bool found = false;
                    foreach (ProductSize size in sizeList)
                    {
                        if (size.SizeId == productMaster.ProductSize.SizeId)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        sizeList.Add(productMaster.ProductSize);
                    }
                }
            }
            colorBindingSource.DataSource = colorList;
            sizeBindingSource.DataSource = sizeList;
            productMasterList = mainStockInEventArgs.FoundProductMasterList;
        }
        private void DepartmentStockInExtra_Load(object sender, EventArgs e)
        {
            var eventArgs = new DepartmentStockInEventArgs();
            EventUtility.fireEvent(FillDepartmentEvent, this, eventArgs);

            IList departmentList = new ArrayList();
            departmentList.Add(new Department { DepartmentId = 0, DepartmentName = "--- Hãy chọn cửa hàng xuất ---" });
            foreach (Department department in eventArgs.DepartmentList)
            {
                departmentList.Add(department);
            }

            bdsDept.DataSource = departmentList;

            deptSIDetailList = new DepartmentStockInDetailCollection(bdsStockIn);
            bdsStockIn.DataSource = deptSIDetailList;
            dgvDeptStockIn.DataError += new DataGridViewDataErrorEventHandler(dgvDeptStockIn_DataError);

            deptSIDetailList = new DepartmentStockInDetailCollection(bdsStockIn);
            bdsStockIn.DataSource = deptSIDetailList;
            dgvDeptStockIn.DataError += new DataGridViewDataErrorEventHandler(dgvDeptStockIn_DataError);

            // create DepartmentStockIn
            if (deptSI == null)
            {
                deptSI = new DepartmentStockIn();
                deptSI.CreateDate = DateTime.Now;
                deptSI.UpdateDate = DateTime.Now;
                deptSI.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                deptSI.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                deptSI.ExclusiveKey = 0;
                CreateNewStockInDetail();
                // load products to extra combo box
                LoadProductMasterToComboBox();
                deptSIDetailList.RemoveAt(0);
                bdsStockIn.EndEdit();

            }
            else
            {
            //                btnBarcode.Visible = true;
            //                numericUpDownBarcode.Visible = true;
            //                btnPreview.Visible = true;
                IList deptStockInDetails = deptSI.DepartmentStockInDetails;
                foreach (DepartmentStockInDetail detail in deptStockInDetails)
                {
                    if (detail.DelFlg == CommonConstants.DEL_FLG_NO)
                    {
                        deptSIDetailList.Add(detail);
                        detail.OldQuantity = detail.Quantity;
                    }
                }

                for (int i = 0; i < dgvDeptStockIn.Columns.Count; i++)
                {
                    dgvDeptStockIn.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                    if (i != QUANTITY_POS
                            && i != PRICE_POS
                            && i != SELL_PRICE_POS)
                    {
                        dgvDeptStockIn.Columns[i].ReadOnly = true;
                    }
                }
                txtDexcription.Text = deptSI.Description;
            }
            deptSI.DepartmentStockInDetails =
                    ObjectConverter.ConvertToNonGenericList<DepartmentStockInDetail>(deptSIDetailList);
        }
        private void PopulateGridByProductMaster(IList colorList, IList sizeList)
        {
            var eventArgs = new DepartmentStockInEventArgs();
            eventArgs.DepartmentStockInDetailList = new ArrayList();
            IList selectedProductMasterList = new ArrayList();
            foreach (ProductColor color in colorList)
            {
                foreach (ProductSize size in sizeList)
                {
                    foreach (ProductMaster productMaster in productMasterList)
                    {

                        // do not allow duplicate
                        bool goOut = false;
                        foreach (DepartmentStockInDetail detail in deptSIDetailList)
                        {
                            if (detail.Product != null
                                && detail.Product.ProductMaster != null
                                && productMaster.ProductMasterId.Equals(detail.Product.ProductMaster.ProductMasterId))
                            {
                                goOut = true;
                            }
                        }
                        if (goOut)
                        {
                            continue;
                        }

                        if (productMaster.ProductColor != null
                            && productMaster.ProductColor.ColorId == color.ColorId
                            && productMaster.ProductSize != null
                            && productMaster.ProductSize.SizeId == size.SizeId)
                        {
                            selectedProductMasterList.Add(productMaster);
                            #region unused code
                            /*DepartmentStockInDetail stockInDetail = deptSIDetailList.AddNew();
                            stockInDetail.Quantity = NumberUtility.ParseLong(txtQuantity.Text);
                            //stockInDetail.SellPrice = NumberUtility.ParseLong(txtPriceOut.Text);
                            stockInDetail.DepartmentStockInDetailPK = new DepartmentStockInDetailPK();
                            if (stockInDetail.Product == null)
                            {
                                stockInDetail.Product = new Product();
                            }
                            stockInDetail.Product.ProductMaster = productMaster;
                            eventArgs.DepartmentStockInDetailList.Add(stockInDetail);
                            deptSIDetailList.EndNew(deptSIDetailList.Count - 1);*/
                            #endregion
                        }
                    }
                }
            }

            eventArgs.ProductMasterList = selectedProductMasterList;
            EventUtility.fireEvent(LoadStockInByProductMaster, this, eventArgs);

            /*if (eventArgs.DepartmentStockInDetailList.Count > 0)
            {
                EventUtility.fireEvent(LoadPriceAndStockEvent, this, eventArgs);
            }*/

            // remove 0 quanity
            int count = 0;
            int length = deptSIDetailList.Count;
            bool isMessage = false;
            for (int i = 0; i < length; i++)
            {
                if (deptSIDetailList[i - count].StockQuantity == 0)
                {
                    //isMessage = true;
                    deptSIDetailList.RemoveAt(i - count);
                    count++;
                }
            }
            if(eventArgs.SelectedStockOutDetails!=null && eventArgs.SelectedStockOutDetails.Count > 0 )
            {
                foreach (DepartmentStockInDetail inDetail in eventArgs.SelectedStockOutDetails)
                {
                    deptSIDetailList.Add(inDetail);
                }

            }

            RemoveDuplicateRows();
            bdsStockIn.ResetBindings(false);
            dgvStockIn.Refresh();
            dgvStockIn.Invalidate();
            /*if (isMessage)
            {
                MessageBox.Show("Sản phẩm có tồn kho 0 sẽ không đựoc xuất");
            }*/
        }
        private void txtBarcode_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtBarcode.Text) && txtBarcode.Text.Length == 12)
            {
                var eventArgs = new DepartmentStockInEventArgs();
                eventArgs.ProductId = txtBarcode.Text;
                EventUtility.fireEvent(FindBarcodeInMainStockEvent, this, eventArgs);
                if (eventArgs.EventResult == null)
                {
                    MessageBox.Show("Không tìm thấy mã vạch này");
                    return;
                }

                // remove 0 quanity
                //RemoveZeroStockQuantities();

                if (eventArgs.SelectedStockOutDetails != null && eventArgs.SelectedStockOutDetails.Count > 0)
                {
                    foreach (DepartmentStockInDetail inDetail in eventArgs.SelectedStockOutDetails)
                    {
                        bool found = false;
                        DepartmentStockInDetail foundStockOutDetail = null;
                        foreach (DepartmentStockInDetail detail in deptSIDetailList)
                        {
                            if (inDetail.Product.ProductId.Equals(detail.Product.ProductId))
                            {
                                found = true;
                                foundStockOutDetail = detail;
                                break;
                            }
                        }
                        if (found)
                        {
                            //MessageBox.Show("Mã vạch đã được nhập");
                            foundStockOutDetail.OldQuantity = foundStockOutDetail.Quantity;
                            foundStockOutDetail.Quantity += 1;
                        }
                        else
                        {
                            deptSIDetailList.Add(inDetail);
                        }
                    }

                }
                RemoveDuplicateRows();
                bdsStockIn.ResetBindings(false);
                dgvStockIn.Refresh();
                dgvStockIn.Invalidate();
                txtBarcode.Text = "";
            }

            CalculateTotalStorePrice();
        }
 void _departmentStockInView_LoadGoodsByNameEvent(object sender, DepartmentStockInEventArgs e)
 {
     DepartmentStockInDetail detail = e.SelectedDepartmentStockInDetail;
             ObjectCriteria objectCriteria = new ObjectCriteria();
             objectCriteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
             objectCriteria.AddEqCriteria("ProductName", detail.Product.ProductMaster.ProductName);
             IList list  = ProductMasterLogic.FindAll(objectCriteria);
             e.FoundProductMasterList = list;
             if (list == null || list.Count == 0)
             {
                 return;
             }
             ProductMaster prodMaster = list[0] as ProductMaster;
             detail.Product.ProductMaster = prodMaster;
             e.SelectedDepartmentStockInDetail = detail;
             IList detailList = new ArrayList();
             detailList.Add(detail);
             GetRemainStockNumber(detailList);
 }
 void _departmentStockInView_LoadPriceAndStockEvent(object sender, DepartmentStockInEventArgs e)
 {
     GetRemainStockNumber(e.DepartmentStockInDetailList);
 }
        void _departmentStockInView_LoadGoodsByIdEvent(object sender, DepartmentStockInEventArgs e)
        {
            DepartmentStockInDetail detail = e.SelectedDepartmentStockInDetail;
                    ProductMaster prodMaster = ProductMasterLogic.FindById(detail.Product.ProductMaster.ProductMasterId);
                    if (prodMaster == null)
                    {
                        return;
                    }
                    detail.Product.ProductMaster = prodMaster;

                    e.SelectedDepartmentStockInDetail = detail;
                    IList detailList = new ArrayList();
                    detailList.Add(detail);
                    GetRemainStockNumber(detailList);
        }
 void _departmentStockInView_LoadGoodsByNameColorSizeEvent(object sender, DepartmentStockInEventArgs e)
 {
     DepartmentStockInDetail detail = e.SelectedDepartmentStockInDetail;
             ObjectCriteria objectCriteria = new ObjectCriteria();
             objectCriteria.AddEqCriteria("ProductName", detail.Product.ProductMaster.ProductName);
             objectCriteria.AddEqCriteria("ProductType", e.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductType);
             objectCriteria.AddEqCriteria("Country", e.SelectedDepartmentStockInDetail.Product.ProductMaster.Country);
             objectCriteria.AddEqCriteria("Manufacturer", e.SelectedDepartmentStockInDetail.Product.ProductMaster.Manufacturer);
             objectCriteria.AddEqCriteria("Distributor", e.SelectedDepartmentStockInDetail.Product.ProductMaster.Distributor);
             objectCriteria.AddEqCriteria("Packager", e.SelectedDepartmentStockInDetail.Product.ProductMaster.Packager);
             objectCriteria.AddEqCriteria("ProductColor", e.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductColor);
             objectCriteria.AddEqCriteria("ProductSize", e.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductSize);
             IList list = ProductMasterLogic.FindAll(objectCriteria);
             if (list == null || list.Count == 0)
             {
                 return;
             }
             ProductMaster prodMaster = list[0] as ProductMaster;
             detail.Product.ProductMaster = prodMaster;
             e.SelectedDepartmentStockInDetail = detail;
             IList detailList = new ArrayList();
             detailList.Add(detail);
             GetRemainStockNumber(detailList);
 }
        void _departmentStockInView_FillProductToComboEvent(object sender, DepartmentStockInEventArgs e)
        {
            ComboBox comboBox = (ComboBox) sender;
                    string originalText = comboBox.Text;
                    if (e.IsFillToComboBox)
                    {
                        ProductMaster searchPM = e.SelectedDepartmentStockInDetail.Product.ProductMaster;
                        var criteria = new ObjectCriteria(true);
                        criteria.AddEqCriteria("pm.DelFlg", CommonConstants.DEL_FLG_NO);
                        criteria.AddEqCriteria("stock.DelFlg", CommonConstants.DEL_FLG_NO);
                        criteria.AddLikeCriteria("pm.ProductName", "%" + searchPM.ProductName + "%");
                        criteria.MaxResult = 50;
                        IList list = StockLogic.FindByQueryForStockIn(criteria);
            //                        if (e.ComboBoxDisplayMember.Equals("ProductMasterId"))
            //                        {
            //                            result = ProductMasterLogic.FindProductMasterById(searchPM.ProductMasterId, 50,true);
            //                        }
            //                        else
            //                        {
            //                            result = ProductMasterLogic.FindProductMasterByName(searchPM.ProductName, 50,true);
            //                        }

                        if(list ==null || list.Count == 0)
                        {
                            return;
                        }
                        IList result = new ArrayList();
                        foreach (Stock stock in list)
                        {
                            result.Add(stock.ProductMaster);
                        }
                        IList retlist = RemoveDuplicateName(result);

                        result = new ArrayList();
                        int count = 0;
                        foreach (var p in retlist)
                        {
                            result.Add(p);
                            count++;
                        }

                        BindingList<ProductMaster> productMasters = new BindingList<ProductMaster>();
                        if (result != null)
                        {
                            foreach (ProductMaster master in result)
                            {
                                productMasters.Add(master);
                            }
                        }
                        BindingSource bindingSource = new BindingSource();
                        bindingSource.DataSource = productMasters;
                        comboBox.DataSource = bindingSource;
                        comboBox.DisplayMember = "TypeAndName";
                        comboBox.ValueMember = e.ComboBoxDisplayMember;
                        comboBox.DropDownWidth = 300;
                        comboBox.DropDownHeight = 200;
                        // keep the original text
                        comboBox.Text = originalText;
                        //comboBox.SelectedIndex = -1;
                        //comboBox.SelectionStart = comboBox.Text.Length;
                        //comboBox.DroppedDown = true;
                        comboBox.MaxDropDownItems = 10;
                    }
        }
 void _departmentStockInView_FillDepartmentEvent(object sender, DepartmentStockInEventArgs e)
 {
     var criteria = new ObjectCriteria();
             criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
             e.DepartmentList = DepartmentLogic.FindAll(criteria);
 }
 void departmentStockInExtraView_LoadProductSizeEvent(object sender, DepartmentStockInEventArgs e)
 {
     if (e.SelectedDepartmentStockInDetail != null && e.SelectedDepartmentStockInDetail.Product != null && !string.IsNullOrEmpty(e.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductName))
             {
                 var subCriteria = new SubObjectCriteria("ProductMasters");
                 subCriteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                 subCriteria.AddEqCriteria("ProductType", e.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductType);
                 subCriteria.AddEqCriteria("ProductName", e.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductName);
                 subCriteria.AddEqCriteria("ProductColor", e.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductColor);
                 subCriteria.AddEqCriteria("Country", e.SelectedDepartmentStockInDetail.Product.ProductMaster.Country);
                 subCriteria.AddEqCriteria("Manufacturer", e.SelectedDepartmentStockInDetail.Product.ProductMaster.Manufacturer);
                 subCriteria.AddEqCriteria("Distributor", e.SelectedDepartmentStockInDetail.Product.ProductMaster.Distributor);
                 subCriteria.AddEqCriteria("Packager", e.SelectedDepartmentStockInDetail.Product.ProductMaster.Packager);
                 var criteria = new ObjectCriteria();
                 criteria.AddSubCriteria("ProductMasters", subCriteria);
                 IList productSizes = ProductSizeLogic.FindAll(criteria);
                 e.ProductSizeList = productSizes;
             }
 }
Esempio n. 15
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            long cost = 0;
            if (!NumberUtility.CheckLongNullIsZero(txtCost.Text, out cost) || cost < 0)
            {
                MessageBox.Show("Chi phí phải là số dương");
                return;
            }
            if (deptSIDetailList.Count == 0)
            {
                MessageBox.Show("Không có sản phẩm nào để nhập kho!!!!");
                return;
            }

            // validate quantity
            StringBuilder errMsg = new StringBuilder();
            int line = 1;
            foreach (DepartmentStockInDetail detail in deptSIDetailList)
            {
                if (detail.Quantity <= 0)
                {
                    MessageBox.Show("Lỗi ở dòng " + line + " : Số lượng phải lớn hơn 0");
                    return;
                }
                long remainReStock = detail.StockOutQuantity - detail.ReStockQuantity;
                if (detail.Quantity > remainReStock)
                {
                    MessageBox.Show("Lỗi ở dòng " + errMsg.ToString() + " : Số lượng còn tái nhập được là " + remainReStock.ToString());
                    return;
                }
                line++;
            }

            if (deptSI == null)
            {
                deptSI = new DepartmentStockIn();
                deptSI.DepartmentStockInPK = new DepartmentStockInPK();
            }
            bool isNeedClearData = string.IsNullOrEmpty(deptSI.DepartmentStockInPK.StockInId);
            deptSI.DepartmentId = CurrentDepartment.Get().DepartmentId;
            deptSI.StockInDate = dtpImportDate.Value;
            deptSI.DepartmentStockInDetails = deptSIDetailList;
            deptSI.Description = txtDexcription.Text;
            deptSI.StockInCost = cost;
            var eventArgs = new DepartmentStockInEventArgs();
            eventArgs.DepartmentStockIn = deptSI;
            EventUtility.fireEvent(SaveReDepartmentStockInEvent, this, eventArgs);
            if (eventArgs.EventResult != null)
            {
                MessageBox.Show("Lưu thành công");
                if (isNeedClearData)
                {
                    deptSI = new DepartmentStockIn();
                    deptSIDetailList.Clear();
                    txtBarcode.Text = "";
                    txtQty.Text = "";
                    txtDexcription.Text = "";
                    txtSumProduct.Text = "";
                    txtSumValue.Text = "";
                    //CreateNewStockInDetail();
                }
            }
            else
            {
                //MessageBox.Show("Có lỗi khi lưu");
            }
        }
        private void txtBarcode_TextChanged(object sender, EventArgs e)
        {
            lblMessage.Text = " Đang chờ nhập ...";
            lblMessage.ForeColor = Color.Blue;
            if (!string.IsNullOrEmpty(txtBarcode.Text) && txtBarcode.Text.Length == 12)
            {
                var eventArgs = new DepartmentStockInEventArgs();
                eventArgs.ProductId = txtBarcode.Text;
                EventUtility.fireEvent(FindBarcodeEvent, this, eventArgs);
                if (eventArgs.EventResult == null)
                {
                    MessageBox.Show("Không tìm thấy mã vạch này");
                    txtBarcode.Text = "";
                    return;
                }
                txtGoodsDescription.Text = eventArgs.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductFullName;
                bool found = false;
                DepartmentStockInDetail foundStockInDetail = null;
                foreach (DepartmentStockInDetail detail in deptSODetailList)
                {
                    if (eventArgs.SelectedDepartmentStockInDetail.Product.ProductId.Equals(detail.Product.ProductId))
                    {
                        found = true;
                        foundStockInDetail = detail;
                        break;
                    }
                }
                if (found)
                {
                    txtBarcode.Text = "";
                    foundStockInDetail.Quantity += 1;
                    bdsStockIn.ResetBindings(false);
                    txtBarcode.Text = "";
                    txtBarcode.Focus();
                    dgvDeptStockIn.Refresh();
                    dgvDeptStockIn.Invalidate();
                    CalculateTotalStorePrice();
                    //MessageBox.Show("Mã vạch đã được nhập");
                    return;
                }
                if (eventArgs.DepartmentStock != null)
                {
                    found = false;
                    foreach (DepartmentStock detail in departmentStockList)
                    {
                        if (eventArgs.DepartmentStock.Product.ProductId.Equals(detail.Product.ProductId))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        departmentStockList.Add(eventArgs.DepartmentStock);
                    }
                }
                eventArgs.SelectedDepartmentStockInDetail.Quantity = 1;

                deptSODetailList.Add(eventArgs.SelectedDepartmentStockInDetail);
                deptSODetailList.EndNew(deptSODetailList.Count - 1);
                //cbbStockOutType.Enabled = false;
                bdsStockIn.ResetBindings(false);
                txtBarcode.Text = "";
                txtBarcode.Focus();
                dgvDeptStockIn.Refresh();
                dgvDeptStockIn.Invalidate();
                CalculateTotalStorePrice();

                if (rdoFastStockIn.Checked)
                {
                    #region unused code
                    /*// do fast stock out in here
                    // first remove all blank row
                    int count = 0;
                    int length = deptSODetailList.Count;
                    for (int i = 0; i < length - count; i++)
                    {
                        DepartmentStockInDetail detail = deptSODetailList[i];
                        if (string.IsNullOrEmpty(detail.Product.ProductMaster.ProductMasterId)
                            && string.IsNullOrEmpty(detail.Product.ProductMaster.ProductName))
                        {
                            deptSODetailList.RemoveAt(i - count);
                            count++;
                        }
                    }

                    if (deptSODetailList.Count == 0)
                    {
                        MessageBox.Show("Không có sản phẩm nào để nhập kho!!!!");
                        return;
                    }

                    // validate quantity
                    int line = 1;
                    foreach (DepartmentStockInDetail detail in deptSODetailList)
                    {
                        detail.CreateDate = DateTime.Now;
                        detail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        detail.UpdateDate = DateTime.Now;
                        detail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        detail.ExclusiveKey = 1;
                        foreach (DepartmentStock stock in departmentStockList)
                        {
                            if (detail.Product.ProductId.Equals(stock.Product.ProductId))
                            {
                                if (detail.Quantity <= 0 )
                                {
                                    MessageBox.Show("Lỗi ở dòng " + line +
                                                    " : Số lượng phải là số dương !");
                                    return;
                                }
                            }
                        }

                        line++;
                    }

                    if (deptSO == null)
                    {
                        deptSO = new DepartmentStockIn();
                    }

                    deptSO.StockInDate = DateTime.Now;
                    deptSO.DepartmentStockInPK = new DepartmentStockInPK
                                                     {
                                                       DepartmentId = CurrentDepartment.Get().DepartmentId
                                                     };
                    deptSO.DepartmentStockInDetails = deptSODetailList;
                    deptSO.ExclusiveKey = 1;
                    //            deptSO.Description = txtDexcription.Text;
                    var ea = new DepartmentStockInEventArgs();
                    ea.DepartmentStockIn = deptSO;
                    ea.Department = (Department)cboDepartment.SelectedItem;
                    ea.DepartmentStockList = departmentStockList;
                    try
                    {
                        //EventUtility.fireAsyncEvent(DispatchDepartmentStockIn, this, ea,new AsyncCallback(EndEvent));
                        EventUtility.fireEvent(DispatchDepartmentStockIn, this, ea);
                    }
                    catch (Exception)
                    {
                        lblMessage.ForeColor = Color.Red;
                        lblMessage.Text = " Không kết nối được với máy cửa hàng! ";
                        deptSO = new DepartmentStockIn();
                        deptSODetailList.Clear();
                        //                    txtDexcription.Text = "";
                        //                    txtPriceIn.Text = "";
                        //                    txtPriceOut.Text = "";
                        txtSumProduct.Text = "";
                        txtSumValue.Text = "";
                        return;
                    }
                    EventUtility.fireEvent(SaveStockInBackEvent, this, ea);
                    if (ea.EventResult != null)
                    {
                         lblMessage.ForeColor = Color.Blue;
                         lblMessage.Text = "Lưu thành công !";

                            deptSO = new DepartmentStockIn();
                            deptSODetailList.Clear();
                            //                    txtDexcription.Text = "";
                            //                    txtPriceIn.Text = "";
                            //                    txtPriceOut.Text = "";
                            txtSumProduct.Text = "";
                            txtSumValue.Text = "";
                            //CreateNewStockInDetail();
                    }
                    else
                    {
                        lblMessage.ForeColor = Color.Red;
                        lblMessage.Text = "Có lỗi khi lưu ! ";
                    }*/
                    #endregion
                }
            }
        }
Esempio n. 17
0
 private ProductMaster GetProductMaster(string productMasterId)
 {
     var eventArgs = new DepartmentStockInEventArgs { ProductMasterId = productMasterId };
     EventUtility.fireEvent(FindProductMasterEvent, this, eventArgs);
     return eventArgs.SelectedProductMaster;
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(
                "Bạn hãy kiểm tra kỹ trước khi lưu số liệu bởi vì sau khi lưu sẽ không thay đổi được nữa. Bạn có chắc chắn muốn lưu ?","Xác nhận",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if(result == System.Windows.Forms.DialogResult.No)
            {
                return;
            }
            // first remove all blank row
            int count = 0;
            int length = deptSODetailList.Count;
            for (int i = 0; i < length - count; i++)
            {
                DepartmentStockInDetail detail = deptSODetailList[i];
                if (string.IsNullOrEmpty(detail.Product.ProductMaster.ProductMasterId)
                    && string.IsNullOrEmpty(detail.Product.ProductMaster.ProductName))
                {
                    deptSODetailList.RemoveAt(i - count);
                    count++;
                }
            }

            if (deptSODetailList.Count == 0)
            {
                MessageBox.Show("Không có sản phẩm nào để nhập kho!!!!");
                return;
            }

            // validate quantity
            int line = 1;
            foreach (DepartmentStockInDetail detail in deptSODetailList)
            {
                detail.CreateDate = DateTime.Now;
                detail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                detail.UpdateDate = DateTime.Now;
                detail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                foreach (DepartmentStock stock in departmentStockList)
                {
                    if (detail.Product.ProductId.Equals(stock.Product.ProductId))
                    {
                        if (detail.Quantity < 0)
                        {
                            MessageBox.Show("Lỗi ở dòng " + line + " : Số lượng phải là số dương. ");
                            return;
                        }
                    }
                }

                line++;
            }
            // confirm before save
            DialogResult isConfirmed = System.Windows.Forms.DialogResult.Cancel;
            if (!ClientSetting.ConfirmByEmployeeId)
            {
                LoginForm loginForm = GlobalUtility.GetFormObject<LoginForm>(FormConstants.CONFIRM_LOGIN_VIEW);
                loginForm.StartPosition = FormStartPosition.CenterScreen;
                isConfirmed = loginForm.ShowDialog();
            }
            else
            {
                EmployeeCheckingForm employeeCheckingForm = GlobalUtility.GetFormObject<EmployeeCheckingForm>(FormConstants.EMPLOYEE_CHECKING_VIEW);
                employeeCheckingForm.StartPosition = FormStartPosition.CenterScreen;
                isConfirmed = employeeCheckingForm.ShowDialog();
            }
            if (isConfirmed != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            // continue stock in
            if(rdoFastStockIn.Checked)
            {
                ShowMessage("Đang yêu cầu trả hàng ....");
            }

            if (deptSO == null)
            {
                deptSO = new DepartmentStockIn();
            }
            deptSO.DepartmentStockInPK = new DepartmentStockInPK
                                             {
                                                 DepartmentId = CurrentDepartment.Get().DepartmentId
                                             };
            deptSO.StockInDate = DateTime.Now;

            deptSO.DepartmentStockInDetails = ObjectConverter.ConvertToNonGenericList(deptSODetailList);
            //            deptSO.Description = txtDexcription.Text;
            var eventArgs = new DepartmentStockInEventArgs();
            eventArgs.DepartmentStockIn = deptSO;
            eventArgs.Department = (Department)cboDepartment.SelectedItem;
            eventArgs.DepartmentStockList = departmentStockList;
            if(rdoFastStockIn.Checked)
            {
                try
                {
                    EventUtility.fireEvent(DispatchDepartmentStockIn, this, eventArgs);
                }
                catch (Exception)
                {
                    lblMessage.ForeColor = Color.Red;
                    lblMessage.Text = " Không kết nối được với máy cửa hàng! ";
                    deptSO = new DepartmentStockIn();
                    deptSODetailList.Clear();
                    //                    txtDexcription.Text = "";
                    //                    txtPriceIn.Text = "";
                    //                    txtPriceOut.Text = "";
                    txtSumProduct.Text = "";
                    txtSumValue.Text = "";
                    return;
                }
            }
            else
            {
                EventUtility.fireEvent(SaveStockInBackEvent, this, eventArgs);
            }

            if (eventArgs.EventResult != null)
            {
                if (!rdoFastStockIn.Checked)
                {
                    lblMessage.ForeColor = Color.Blue;
                    lblMessage.Text = "Lưu thành công !";
                }
                deptSO = new DepartmentStockIn();
                deptSODetailList.Clear();
            //                    txtDexcription.Text = "";
            //                    txtPriceIn.Text = "";
            //                    txtPriceOut.Text = "";
                    txtSumProduct.Text = "";
                    txtSumValue.Text = "";
                    //CreateNewStockInDetail();
                txtBarcode.Focus();
            }
            else
            {
                if (rdoFastStockIn.Checked)
                {
                    lblMessage.ForeColor = Color.Blue;
                    lblMessage.Text = "Đã yêu cầu cửa hàng trả hàng ... ";
                    return;
                }
                lblMessage.ForeColor = Color.Red;
                lblMessage.Text = "Có lỗi khi lưu !";
            }
        }
        private DepartmentStockIn SaveDeptStockIn(bool isNeedSync)
        {
            // check for department
            var dept = cbbDept.SelectedItem as Department;
            if (dept == null)
            {
                MessageBox.Show("Không có cửa hàng nào để xuất hàng");
                return null;
            }

            // first remove all blank row
            int count = 0;
            int length = deptSIDetailList.Count;
            for (int i = 0; i < length - count; i++)
            {
                DepartmentStockInDetail detail = deptSIDetailList[i];
                if (string.IsNullOrEmpty(detail.Product.ProductMaster.ProductMasterId)
                    && string.IsNullOrEmpty(detail.Product.ProductMaster.ProductName))
                {
                    deptSIDetailList.RemoveAt(i - count);
                    count++;
                }
            }

            if (deptSIDetailList.Count == 0)
            {
                MessageBox.Show("Không có sản phẩm nào để xuất!!!!");
                return null;
            }

            // validate quantity
            StringBuilder errMsg = new StringBuilder();
            int line = 1;
            if(chkRemoveZero.Checked)
            {
                RemoveZeroLines();
            }
            foreach (DepartmentStockInDetail detail in deptSIDetailList)
            {
                if (detail.Quantity == 0)
                {
                    errMsg.Append(" " + line + " ");
                }
                line++;
            }
            if (errMsg.Length > 0)
            {
                MessageBox.Show("Lỗi ở dòng " + errMsg.ToString() + " : Số lượng phải lớn hơn 0");
                return null;
            }

            /*count = 0;
            foreach (DepartmentStockInDetail detail in deptSIDetailList)
            {
                line = 0;
                foreach (DepartmentStockInDetail detail2 in deptSIDetailList)
                {
                    if (detail.DelFlg == CommonConstants.DEL_FLG_NO
                        && detail.Product.ProductId.Equals(detail2.Product.ProductId))
                    {
                        if(count!=line)
                        {
                            MessageBox.Show("Lỗi : Mã vạch " + detail.Product.ProductId + " nhập 2 lần");
                            dgvDeptStockIn.CurrentCell = dgvDeptStockIn[3, line];
                            return null;
                        }
                    }
                    line++;
                }
                count++;
            }*/

            RemoveDuplicateRows();

            if (deptSI == null)
            {
                deptSI = new DepartmentStockIn();
            }

            deptSI.StockInDate = dtpImportDate.Value;
            deptSI.DepartmentId = dept.DepartmentId;
            deptSI.Description = txtDexcription.Text;
            deptSI.DepartmentStockInDetails = deptSIDetailList;

            var eventArgs = new DepartmentStockInEventArgs();
            eventArgs.IsForSync = isNeedSync;
            eventArgs.DepartmentStockIn = deptSI;
            eventArgs.ExportGoodsToDepartment = true;
            // update stock out
            foreach (DepartmentStockInDetail detail in deptSIDetailList)
            {
                bool newRow = true;
                foreach (StockOutDetail outDetail in StockOut.StockOutDetails)
                {
                    if(outDetail.Product.ProductId == detail.Product.ProductId)
                    {
                        newRow = false;
                        outDetail.Quantity = detail.Quantity;
                        outDetail.GoodQuantity = detail.Quantity;
                        outDetail.DelFlg = detail.DelFlg;
                        break;
                    }
                }
                if(newRow)
                {
                    StockOutDetail outDetail = new StockOutDetail();
                    outDetail.Product = detail.Product;
                    outDetail.CreateDate = detail.CreateDate;
                    outDetail.CreateId = detail.CreateId;
                    outDetail.UpdateDate = detail.UpdateDate;
                    outDetail.Price = detail.Price;
                    outDetail.StockOutId = StockOut.StockoutId;
                    outDetail.Quantity = detail.Quantity;
                    outDetail.GoodQuantity = detail.Quantity;
                    outDetail.ProductMaster = detail.Product.ProductMaster;
                    outDetail.StockOut = StockOut;
                    StockOut.StockOutDetails.Add(outDetail);
                }
            }
            eventArgs.UpdateStockOut = StockOut;
            EventUtility.fireEvent(UpdateStockOutEvent, this, eventArgs);
            if (eventArgs.EventResult != null)
            {
                MessageBox.Show("Lưu thành công");
                txtDexcription.Text = "";
                txtQuantity.Text = "";
                txtSumValue.Text = "";
                txtSumProduct.Text = "";
                ClearSelectionOnListBox(lstColor);
                ClearSelectionOnListBox(lstSize);
                return eventArgs.DepartmentStockIn;
            }
            else
            {
                return null;
            }
        }
        private void DepartmentStockInExtra_Load(object sender, EventArgs e)
        {
            rdoFastStockIn.Checked = true;

            DepartmentStockInEventArgs eventArgs = new DepartmentStockInEventArgs();
            EventUtility.fireEvent(LoadAllDepartments,this,eventArgs);
            if(eventArgs.DepartmentsList!= null && eventArgs.DepartmentsList.Count > 0)
            {
                BindingSource bdsDepartment = new BindingSource();
                bdsDepartment.DataSource = typeof (Department);
                cboDepartment.DataSource = bdsDepartment;
                cboDepartment.DisplayMember = "DepartmentName";
                foreach (Department department in eventArgs.DepartmentsList)
                {
                    if (department.DepartmentId != CurrentDepartment.Get().DepartmentId)
                    {
                        string deptId = department.DepartmentId.ToString();
                        string currId = CurrentDepartment.Get().DepartmentId.ToString();
                        if(currId.StartsWith(deptId))
                        {
                            bdsDepartment.Add(department);
                        }
                    }
                    if (ClientSetting.MarketDept.Equals(department.DepartmentId.ToString()))
                    {
                        bdsDepartment.Add(department);
                    }
                }
                bdsDepartment.EndEdit();
                cboDepartment.Refresh();
                cboDepartment.Invalidate();
            }

            foreach (Department department in cboDepartment.Items)
            {
                string departmentId = department.DepartmentId.ToString();
                string currentSubStock = CurrentDepartment.Get().DepartmentId.ToString();
                if (currentSubStock.StartsWith(departmentId))
                {
                    cboDepartment.SelectedItem = department;
                    cboDepartment.Enabled = false;
                    break;
                }
            }

            deptSODetailList = new DepartmentStockInDetailCollection(bdsStockIn);
            bdsStockIn.DataSource = deptSODetailList;
            dgvDeptStockIn.DataError += new DataGridViewDataErrorEventHandler(dgvDeptStockIn_DataError);
            UpdateStockOutDescription();
            GlobalMessage message = (GlobalMessage)GlobalUtility.GetObject("GlobalMessage");
            message.HasNewMessageEvent += new EventHandler<GlobalMessageEventArgs>(Instance_HasNewMessageEvent);
        }
        private void btnChoose_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection collection = dgvStockIn.SelectedRows;
            if(collection.Count > 0 )
            {
                IList stockInIds = new ArrayList();
                foreach (DataGridViewRow selectedRowCollection in collection)
                {
                    string stockInId = selectedRowCollection.Cells[0].Value.ToString();
                    stockInIds.Add(stockInId);
                }

                DepartmentStockInEventArgs ea = new DepartmentStockInEventArgs();
                ea.SelectedStockInIds = stockInIds;

                EventUtility.fireAsyncEvent(FindByStockInIdEvent,this,ea,new AsyncCallback(EndEvent));
                this.Enabled = false;
                //EventUtility.fireEvent(FindByStockInIdEvent,this,ea);
            }
            //stockinBindingSource.Clear();
        }
        private void ImportByFile_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)
                    {
                        var eventArgs = new DepartmentStockInEventArgs();
                        eventArgs.ProductId = barCodeLine.Key;
                        EventUtility.fireEvent(FindBarcodeEvent, this, eventArgs);
                        if (eventArgs.EventResult == null)
                        {
                            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(barCodeLine.Key + "," + barCodeLine.Value);
                            continue;
                        }
                        bool found = false;
                        DepartmentStockInDetail foundStockInDetail = null;
                        foreach (DepartmentStockInDetail detail in deptSODetailList)
                        {
                            if (eventArgs.SelectedDepartmentStockInDetail.Product.ProductId.Equals(detail.Product.ProductId))
                            {
                                found = true;
                                foundStockInDetail = detail;
                                break;
                            }
                        }

                        if (found)
                        {
                            foundStockInDetail.Quantity += barCodeLine.Value;
                            bdsStockIn.ResetBindings(false);
                            dgvDeptStockIn.Refresh();
                            dgvDeptStockIn.Invalidate();
                            CalculateTotalStorePrice();
                        }
                        else
                        {
                            // reset quantity to 1
                            eventArgs.SelectedDepartmentStockInDetail.Quantity = barCodeLine.Value;
                            deptSODetailList.Add(eventArgs.SelectedDepartmentStockInDetail);
                            bdsStockIn.ResetBindings(false);
                            dgvDeptStockIn.Refresh();
                            dgvDeptStockIn.Invalidate();
                            //LockField(deptSODetailList.Count - 1, eventArgs.SelectedDepartmentStockInDetail);
                            CalculateTotalStorePrice();
                        }

                        // process department stock
                        if (eventArgs.DepartmentStock != null)
                        {
                            found = false;
                            foreach (DepartmentStock detail in departmentStockList)
                            {
                                if (eventArgs.DepartmentStock.DepartmentStockPK.ProductId.Equals(detail.Product.ProductId))
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                departmentStockList.Add(eventArgs.DepartmentStock);
                            }
                        }
                    }

                }
                CalculateTotalStorePrice();
                if (_errorForm != null)
                {
                    _errorForm.ShowDialog();
                    _errorForm = null;
                }
            }
        }
 void departmentStockInController_CompletedFindByStockInEvent(object sender, DepartmentStockInEventArgs e)
 {
     IList list = e.SelectedStockOutDetails;
     if (list != null && list.Count > 0)
     {
         foreach (DepartmentStockInDetail stockInDetail in list)
         {
             if (!IsInList(deptSIDetailList, stockInDetail))
             {
                 deptSIDetailList.Add(stockInDetail);
             }
         }
     }
     RemoveDuplicateRows();
     this.Enabled = true;
     bdsStockIn.ResetBindings(false);
     dgvDeptStockIn.Refresh();
     dgvStockIn.Invalidate();
     panelStockIns.Visible = false;
     CalculateTotalStorePrice();
 }
        private void btnSyncToMain_Click(object sender, EventArgs e)
        {
            if(!CheckPOSSyncDriveExist())
                return;
            string POSSyncDrive = ClientUtility.GetPOSSyncDrives()[0].ToString();
            DialogResult dResult = MessageBox.Show(
                "Bạn muốn xuất hàng cho cửa hàng ? ",
                "Xuất hàng cho cửa hàng", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
            if (dResult == DialogResult.No)
            {
                return;
            }

            var configurationAppSettings = new AppSettingsReader();
            //var exportPath = (string)configurationAppSettings.GetValue("SyncExportPath", typeof(String));
            var configExportPath = POSSyncDrive + ClientSetting.SyncExportPath;
            if (string.IsNullOrEmpty(configExportPath) || !Directory.Exists(configExportPath))
            {
                MessageBox.Show("Không thể tìm thấy đường dẫn đến thư mục " + configExportPath + "!Hãy kiễm tra file cấu hình phần SyncExportPath");
                return;
            }
            IList resultList = new ArrayList();
            try
            {
                var deptEvent = new DepartmentStockInEventArgs();
                EventUtility.fireEvent(FillDepartmentEvent, this, deptEvent);

                IList departmentList = deptEvent.DepartmentList;
                foreach (Department department in departmentList)
                {
                    var exportPath = ClientUtility.EnsureSyncPath(configExportPath, department);
                    DateTime lastSyncTime = ClientUtility.GetLastSyncTime(exportPath,department,ClientUtility.SyncType.SyncDown);
                    deptEvent = new DepartmentStockInEventArgs();
                    deptEvent.LastSyncTime = lastSyncTime;
                    deptEvent.Department = department;
                    EventUtility.fireEvent(LoadDepartemntStockInForExportEvent, this, deptEvent);

                    if(deptEvent.SyncFromMainToDepartment!=null
                        && deptEvent.SyncFromMainToDepartment.StockOutList!=null
                        && deptEvent.SyncFromMainToDepartment.StockOutList.Count > 0 )
                    {
                        string fileName = exportPath + "\\" + department.DepartmentId + "_SyncDown_" +
                                                              DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + CommonConstants.SERVER_SYNC_FORMAT;
                        SyncResult result = new SyncResult();
                        result.FileName = fileName;
                        result.Status = "Thành công";
                        resultList.Add(result);
                        Stream stream = File.Open(fileName, FileMode.Create);
                        BinaryFormatter bf = new BinaryFormatter();
                        bf.Serialize(stream, deptEvent.SyncFromMainToDepartment);
                        stream.Close();
                        // write last sync time
                        //ClientUtility.WriteLastSyncTime(exportPath,department,ClientUtility.SyncType.SyncDown);
                    }

                }
            }
            catch (Exception)
            {
                throw;
            }
            MessageBox.Show("Đồng bộ hoàn tất !");
            syncResultBindingSource.DataSource = resultList;
        }
        private void DepartmentStockInFromMainEditForm_Shown(object sender, EventArgs e)
        {
            if(StockOut == null )
            {
                return;
            }

            deptSIDetailList.Clear();
            foreach (StockOutDetail outDetail in StockOut.StockOutDetails)
            {
                DepartmentStockInDetail deptDetail = new DepartmentStockInDetail();
                deptDetail.CreateDate = DateTime.Now;
                deptDetail.UpdateDate = DateTime.Now;
                deptDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                deptDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                deptDetail.DepartmentStockInDetailPK = new DepartmentStockInDetailPK();
                deptDetail.Product = outDetail.Product;
                deptDetail.ProductMaster = outDetail.Product.ProductMaster;
                deptDetail.Quantity = outDetail.Quantity;
                deptDetail.StockOutDetailId = outDetail.StockOutDetailId;
                deptSIDetailList.Add(deptDetail);
            }
            DepartmentStockInEventArgs eventArgs = new DepartmentStockInEventArgs();
            eventArgs.DepartmentStockInDetailList = ObjectConverter.ConvertToNonGenericList(deptSIDetailList);

            EventUtility.fireEvent(FindRemainsQuantity,this,eventArgs);

            deptSIDetailList.Clear();

            foreach (DepartmentStockInDetail departmentStockInDetail in eventArgs.DepartmentStockInDetailList)
            {
                deptSIDetailList.Add(departmentStockInDetail);
            }

            foreach (Department department in cbbDept.Items)
            {
                if(department.DepartmentId == StockOut.DepartmentId)
                {
                    cbbDept.SelectedItem = department;
                    break;
                }
            }
        }
        private void doSync()
        {
            if (!CheckPOSSyncDriveExist())
                return;
            string POSSyncDrive = ClientUtility.GetPOSSyncDrives()[0].ToString();
            DialogResult dResult = MessageBox.Show(
                "Bạn muốn xuất hàng cho cửa hàng ? ",
                "Xuất hàng cho cửa hàng", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
            if (dResult == DialogResult.No)
            {
                return;
            }

            var configurationAppSettings = new AppSettingsReader();
            //var exportPath = (string)configurationAppSettings.GetValue("SyncExportPath", typeof(String));
            var configExportPath = POSSyncDrive + ClientSetting.SyncExportPath;
            if (string.IsNullOrEmpty(configExportPath) || !Directory.Exists(configExportPath))
            {
                MessageBox.Show("Không thể tìm thấy đường dẫn đến thư mục " + configExportPath + "!Hãy kiễm tra file cấu hình phần SyncExportPath");
                return;
            }
            resultList = new ArrayList();
            try
            {
                if(chkMasterData.Checked)
                {
                    if(!chkDepartments.Checked && !chkPrdMaster.Checked && !chkPrice.Checked)
                    {
                        MessageBox.Show("Bạn phải chọn ít nhất một thông tin chung để đồng bộ.");
                        return;
                    }
                    DatabaseUtils.LoadMasterData(chkPrdMaster.Checked,chkDepartments.Checked,chkPrice.Checked);
                }

                // sync stock-out to dept
                var deptEvent = new DepartmentStockInEventArgs();
                EventUtility.fireEvent(FillDepartmentEvent, this, deptEvent);

                IList departmentList = deptEvent.DepartmentList;
                foreach (Department department in departmentList)
                {
                    CleanUSBDrive(POSSyncDrive);
                    if(department.DepartmentId != syncDeptId) continue;

                    var exportPath = ClientUtility.EnsureSyncPath(configExportPath, department);
                    DateTime lastSyncTime = ClientUtility.GetLastSyncTime(exportPath, department, ClientUtility.SyncType.SyncDown);
                    deptEvent = new DepartmentStockInEventArgs();
                    deptEvent.LastSyncTime = lastSyncTime;
                    deptEvent.Department = department;
                    EventUtility.fireEvent(LoadDepartmentStockInForExportEvent, this, deptEvent);

                    int countSyncFile = 1;
                    if (deptEvent.SyncFromMainToDepartment != null)
                        //&& deptEvent.SyncFromMainToDepartment.StockOutList != null
                        //&& deptEvent.SyncFromMainToDepartment.StockOutList.Count > 0)
                    {

                        // ++ AMEND : SEPARATE STOCKOUTS AND COMMON INFO

                        //var exportPath = ClientUtility.EnsureSyncPath(configExportPath, department);
                        #region oldsynccode
                        /*string fileName = exportPath + "\\" + department.DepartmentId
                                          + "_SyncDown_"
                                          + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")
                                          + CommonConstants.SERVER_SYNC_FORMAT;
                        SyncResult result = new SyncResult();
                        result.FileName = fileName;
                        result.Status = "Thành công";
                        resultList.Add(result);
                        Stream stream = File.Open(fileName, FileMode.Create);
                        BinaryFormatter bf = new BinaryFormatter();
                        bf.Serialize(stream, deptEvent.SyncFromMainToDepartment);
                        stream.Flush();
                        stream.Close();*/

                        #endregion

                        SyncFromMainToDepartment common = new SyncFromMainToDepartment();

                            common.Department = deptEvent.SyncFromMainToDepartment.Department;
                            common.DepartmentList = deptEvent.SyncFromMainToDepartment.DepartmentList;
                            common.EmployeeList = deptEvent.SyncFromMainToDepartment.EmployeeList;
                            common.DepartmentPriceMasterList =
                                deptEvent.SyncFromMainToDepartment.DepartmentPriceMasterList;
                            common.DepartmentStockTemps = deptEvent.SyncFromMainToDepartment.DepartmentStockTemps;
                            common.ProductMasterList = deptEvent.SyncFromMainToDepartment.ProductMasterList;
                            common.UserInfoList = deptEvent.SyncFromMainToDepartment.UserInfoList;

                            string fileName = exportPath + "\\" + department.DepartmentId
                                              + "_" + countSyncFile.ToString()
                                              + "_SyncDown_"
                                              + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")
                                              + CommonConstants.SERVER_SYNC_FORMAT;
                            SyncResult result = new SyncResult();
                            result.FileName = fileName;
                            result.Status = "Thành công";
                            resultList.Add(result);
                            Stream stream = File.Open(fileName, FileMode.Create);
                            BinaryFormatter bf = new BinaryFormatter();
                            bf.Serialize(stream, deptEvent.SyncFromMainToDepartment);
                            stream.Flush();
                            stream.Close();

                        // write each stock out to a sync file for avoiding duplicate update
                        if(deptEvent.SyncFromMainToDepartment.StockOutList!=null
                           && deptEvent.SyncFromMainToDepartment.StockOutList.Count > 0 )
                        {
                            foreach (StockOut stockOut in deptEvent.SyncFromMainToDepartment.StockOutList)
                            {
                                countSyncFile += 1;
                                SyncFromMainToDepartment soSync = new SyncFromMainToDepartment();
                                soSync.Department = deptEvent.SyncFromMainToDepartment.Department;
                                soSync.StockOutList = new ArrayList();
                                soSync.StockOutList.Add(stockOut);

                                string soFileName = exportPath + "\\" + department.DepartmentId
                                              + "_" + countSyncFile.ToString()
                                              + "_SyncDown_"
                                              + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")
                                              + CommonConstants.SERVER_SYNC_FORMAT;
                                SyncResult soResult = new SyncResult();
                                soResult.FileName = soFileName;
                                soResult.Status = "Thành công";
                                resultList.Add(soResult);
                                Stream soStream = File.Open(soFileName, FileMode.Create);
                                BinaryFormatter soBf = new BinaryFormatter();
                                soBf.Serialize(soStream, soSync);
                                soStream.Flush();
                                soStream.Close();
                            }
                        }

                        // -- AMEND : SEPARATE STOCKOUTS AND COMMON INFO
                        // write last sync time
                        //ClientUtility.WriteLastSyncTime(exportPath,department,ClientUtility.SyncType.SyncDown);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            MessageBox.Show("Đồng bộ hoàn tất !");
        }
        private void dgvDeptStockIn_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                DepartmentStockInEventArgs mainStockInEventArgs = new DepartmentStockInEventArgs();
                int selectedIndex = dgvDeptStockIn.CurrentRow.Index;
                mainStockInEventArgs.SelectedIndex = selectedIndex;
                mainStockInEventArgs.SelectedDepartmentStockInDetail = deptSIDetailList[selectedIndex];

                if (e.ColumnIndex == 1 || e.ColumnIndex == 2)
                {
                    mainStockInEventArgs.SelectedDepartmentStockInDetail.Product.ProductMaster.ProductMasterId =
                        dgvDeptStockIn.CurrentCell.Value as string;
                    if (e.ColumnIndex == 1)
                    {
                        EventUtility.fireEvent(LoadGoodsByIdEvent, this, mainStockInEventArgs);
                    }
                    else
                    {
                        EventUtility.fireEvent(LoadGoodsByNameEvent, this, mainStockInEventArgs);
                    }

                    // load goods to current row
                    ProductMaster loadGoods =
                        mainStockInEventArgs.SelectedDepartmentStockInDetail.Product.ProductMaster;
                    deptSIDetailList[selectedIndex] = mainStockInEventArgs.SelectedDepartmentStockInDetail;
                    bdsDeptStockIn.EndEdit();

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("Mã sản phẩm không hợp lệ hoặc lỗi khi nhập");
            }
        }
Esempio n. 28
0
 private void btnInput_Click(object sender, EventArgs e)
 {
     //cboProductMasters.SelectedIndex;
     //            string productName = cboProductMasters.SelectedItem as string;
     //            BindingSource bindingSource = (BindingSource) cboProductMasters.DataSource;
     //            PopulateGridByProductMaster((ProductMaster) bindingSource[cboProductMasters.SelectedIndex]);
     if (string.IsNullOrEmpty(txtBarcode.Text))
     {
         MessageBox.Show("Hãy nhập mã vạch để tái nhập kho");
         return;
     }
     long outValue = 0;
     if (!NumberUtility.CheckLongNullIsZero(txtQty.Text, out outValue)
         || outValue < 0)
     {
         MessageBox.Show("Số lượng phải là số dương");
         return;
     }
     var eventArgs = new DepartmentStockInEventArgs();
     eventArgs.ProductId = txtBarcode.Text;
     EventUtility.fireEvent(FindByBarcodeEvent, this, eventArgs);
     if (eventArgs.EventResult != null)
     {
         if (eventArgs.DepartmentStockInDetail == null)
         {
             MessageBox.Show("Không thể tìm thấy mã vạch " + txtBarcode.Text + " trong kho tạm xuất");
             return;
         }
         else
         {
             foreach (DepartmentStockInDetail detail in deptSIDetailList)
             {
                 if (detail.Product.ProductId.Equals(eventArgs.DepartmentStockInDetail.Product.ProductId))
                 {
                     MessageBox.Show("Mã vạch " + txtBarcode.Text + " đã được nhập rồi");
                     return;
                 }
             }
         }
         eventArgs.DepartmentStockInDetail.Quantity = outValue;
         deptSIDetailList.Add(eventArgs.DepartmentStockInDetail);
         deptSIDetailList.EndNew(deptSIDetailList.Count - 1);
         for (int i = 0; i < dgvDeptStockIn.ColumnCount; i++)
         {
             if (i != 6)
             {
                 dgvDeptStockIn[i, deptSIDetailList.Count - 1].Style.ForeColor = Color.Gray;
             }
         }
     }
     CalculateTotalPrice();
 }
 private void FillProductToComboBox(object sender, string name)
 {
     DepartmentStockInEventArgs mainStockInEventArgs = new DepartmentStockInEventArgs();
     int selectedIndex = dgvDeptStockIn.CurrentRow.Index;
     mainStockInEventArgs.SelectedIndex = selectedIndex;
     mainStockInEventArgs.SelectedDepartmentStockInDetail = deptSIDetailList[selectedIndex];
     mainStockInEventArgs.IsFillToComboBox = true;
     if (name.Equals("columnProductName"))
     {
         mainStockInEventArgs.ComboBoxDisplayMember = "ProductName";
     }
     if (name.Equals("columnProductId"))
     {
         mainStockInEventArgs.ComboBoxDisplayMember = "ProductMasterId";
     }
     EventUtility.fireEvent<DepartmentStockInEventArgs>(FillProductToComboEvent, sender, mainStockInEventArgs);
 }
        public void _departmentStockInView_LoadDepartemntStockInForExportEvent(object sender, DepartmentStockInEventArgs e)
        {
            DateTime lastSyncTime = e.LastSyncTime;
            e.SyncFromMainToDepartment = new SyncFromMainToDepartment();
            var stockTempCri = new ObjectCriteria();
            stockTempCri.AddEqCriteria("Fixed", CommonConstants.DEL_FLG_YES);
            stockTempCri.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);

            IList processedStockTemps = DepartmentStockTempLogic.FindAll(stockTempCri);
            e.SyncFromMainToDepartment.DepartmentStockTemps = processedStockTemps;

            var criteria = new ObjectCriteria();
            criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
            criteria.AddEqCriteria("DepartmentId", e.Department.DepartmentId);
            criteria.AddGreaterOrEqualsCriteria("CreateDate", lastSyncTime);

            e.SyncFromMainToDepartment.StockOutList = StockOutLogic.FindAll(criteria);
            e.SyncFromMainToDepartment.Department = e.Department;
            criteria = new ObjectCriteria();
            criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
            //criteria.AddEqCriteria("EmployeePK.DepartmentId", e.Department.DepartmentId);
            e.SyncFromMainToDepartment.Department.Employees = EmployeeLogic.FindAll(criteria);
            //foreach (DepartmentStockIn departmentStockIn in e.DepartmentStockInList)
            if (e.SyncFromMainToDepartment.StockOutList == null || e.SyncFromMainToDepartment.StockOutList.Count == 0)
            {
                return; // don't need to get detail
            }
            foreach (StockOut departmentStockIn in e.SyncFromMainToDepartment.StockOutList)
            {

                foreach (StockOutDetail detail in departmentStockIn.StockOutDetails)
                {
                    DepartmentPrice price =
                        DepartmentPriceLogic.FindById(new DepartmentPricePK
                                                          {
                                                              DepartmentId = 0,
                                                              ProductMasterId =
                                                                  detail.Product.ProductMaster.ProductMasterId
                                                          });
                    if (price != null)
                    {
                        detail.Price = price.Price;

                    }
                }
            }
        }