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 MainStockInEventArgs();
     eventArgs.ProductId = txtBarcode.Text;
     EventUtility.fireEvent(FindByBarcodeEvent, this, eventArgs);
     if (eventArgs.EventResult != null)
     {
         if (eventArgs.StockInDetail == null)
         {
             MessageBox.Show("Không thể tìm thấy mã vạch " + txtBarcode.Text + " trong kho tạm xuất");
             return;
         } else
         {
             foreach (StockInDetail detail in deptSIDetailList)
             {
                 if (detail.Product.ProductId.Equals(eventArgs.StockInDetail.Product.ProductId))
                 {
                     MessageBox.Show("Mã vạch " + txtBarcode.Text + " đã được nhập rồi");
                     return;
                 }
             }
         }
         eventArgs.StockInDetail.Quantity = outValue;
         deptSIDetailList.Add(eventArgs.StockInDetail);
         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;
             }
         }
     }
 }
        public void mainStockInView_SaveReStockInEvent(object sender, MainStockInEventArgs e)
        {
            try
            {
                StockInLogic.AddReStock(e.StockIn);
                e.HasErrors = false;
                e.EventResult = "Success";
            }
            catch (Exception)
            {

                throw;
            }
        }
        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 = deptSIDetailList.Count;
            for (int i = 0; i < length - count; i++)
            {
                StockInDetail 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 để nhập kho!!!!");
                return;
            }

            // validate quantity
            StringBuilder errMsg = new StringBuilder();
            int line = 1;
            foreach (StockInDetail 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;
            }
            foreach (StockInDetail detail in deptSIDetailList)
            {
                count = 0;
                foreach (StockInDetail detail2 in deptSIDetailList)
                {
                    if (detail.DelFlg == CommonConstants.DEL_FLG_NO && detail.Product.ProductMaster.ProductMasterId.Equals(detail2.Product.ProductMaster.ProductMasterId))
                    {
                        if (count == 0)
                        {
                            count++;
                        }
                        else
                        {
                            MessageBox.Show("Lỗi : Mã hàng " + detail.Product.ProductMaster.ProductMasterId + " nhập 2 lần");
                            return;
                        }
                    }

                }
            }

            bool isNeedClearData = string.IsNullOrEmpty(deptSI.StockInId);
            deptSI.StockInDate = dtpImportDate.Value;
            deptSI.StockInDetails = deptSIDetailList;
            deptSI.Description = txtDexcription.Text;
            var eventArgs = new MainStockInEventArgs();
            eventArgs.StockIn = StockIn;
            eventArgs.StockIn.StockInDetails = ObjectConverter.ConvertToNonGenericList(deptSIDetailList);
            EventUtility.fireEvent(SaveStockInEvent, this, eventArgs);
            if (eventArgs.EventResult != null)
            {
                MessageBox.Show("Lưu thành công");
                if (isNeedClearData)
                {
                    deptSI = new StockIn();
                    deptSIDetailList.Clear();
                    txtDexcription.Text = "";
                    txtPriceIn.Text = "";
                    txtPriceOut.Text = "";
                    txtSumProduct.Text = "";
                    txtSumValue.Text = "";
                    ClearSelectionOnListBox(lstColor);
                    ClearSelectionOnListBox(lstSize);
                    //CreateNewStockInDetail();
                }
            }
            else
            {
                //MessageBox.Show("Có lỗi khi lưu");
            }
        }
Exemple #4
0
        private void dgvDeptStockIn_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                var mainStockInEventArgs = new MainStockInEventArgs();
                if (dgvDeptStockIn == null || dgvDeptStockIn.CurrentRow == null)
                {
                    return;
                }
                int selectedIndex = dgvDeptStockIn.CurrentRow.Index;
                mainStockInEventArgs.SelectedIndex = selectedIndex;
                mainStockInEventArgs.SelectedStockInDetail = deptSIDetailList[selectedIndex];

                // bind the quantity, price and sellprice
                long qty = NumberUtility.ParseLong(dgvDeptStockIn[QUANTITY_POS, selectedIndex].Value);
                long inPrice = NumberUtility.ParseLong(dgvDeptStockIn[PRICE_POS, selectedIndex].Value);
                long sellPrice = NumberUtility.ParseLong(dgvDeptStockIn[SELL_PRICE_POS, selectedIndex].Value);

                if (e.ColumnIndex == 1 || e.ColumnIndex == 2)
                {
                    mainStockInEventArgs.SelectedStockInDetail.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
                    var loadGoods =
                        mainStockInEventArgs.SelectedStockInDetail.Product.ProductMaster;
                    deptSIDetailList[selectedIndex] = mainStockInEventArgs.SelectedStockInDetail;
                    bdsStockIn.EndEdit();

                }
                else if (e.ColumnIndex == 3)
                {
                    // get the product name
                    var name = dgvDeptStockIn[2, dgvDeptStockIn.CurrentCell.RowIndex].Value as string;
                    if (string.IsNullOrEmpty(name))
                    {
                        // ignore
                        return;
                    }
                    // get the color (if selected)
                    ProductColor color = null;
                    var colorStr = dgvDeptStockIn.CurrentCell.Value as string;
                    if (CurrentRowProductColorList != null)
                    {
                        foreach (ProductColor c in CurrentRowProductColorList)
                        {
                            if (c.ColorName.Equals(colorStr))
                            {
                                color = c;
                                break;
                            }
                        }
                    }

                    mainStockInEventArgs.SelectedStockInDetail.Product.ProductMaster.ProductName = name;
                    mainStockInEventArgs.SelectedStockInDetail.Product.ProductMaster.ProductColor = color;
                    EventUtility.fireEvent(LoadGoodsByNameColorEvent, this, mainStockInEventArgs);
                    // load goods to current row
                    var loadGoods =
                        mainStockInEventArgs.SelectedStockInDetail.Product.ProductMaster;
                    deptSIDetailList[selectedIndex] = mainStockInEventArgs.SelectedStockInDetail;
                    bdsStockIn.EndEdit();
                }
                else if (e.ColumnIndex == 4)
                {
                    // get the product name
                    var name = dgvDeptStockIn[2, dgvDeptStockIn.CurrentCell.RowIndex].Value as string;
                    if (string.IsNullOrEmpty(name))
                    {
                        // ignore
                        return;
                    }
                    // get the color (if selected)
                    // get the color (if selected)
                    ProductColor color = null;
                    var colorStr = dgvDeptStockIn[3, dgvDeptStockIn.CurrentCell.RowIndex].Value as string;
                    if (CurrentRowProductColorList != null)
                    {
                        foreach (ProductColor c in CurrentRowProductColorList)
                        {
                            if (c.ColorName.Equals(colorStr))
                            {
                                color = c;
                                break;
                            }
                        }
                    }

                    // get the color (if selected)
                    ProductSize size = null;
                    var sizeStr = dgvDeptStockIn.CurrentCell.Value as string;
                    if (CurrentRowProductSizeList != null)
                    {
                        foreach (ProductSize c in CurrentRowProductSizeList)
                        {
                            if (c.SizeName.Equals(sizeStr))
                            {
                                size = c;
                                break;
                            }
                        }
                    }

                    mainStockInEventArgs.SelectedStockInDetail.Product.ProductMaster.ProductName = name;
                    mainStockInEventArgs.SelectedStockInDetail.Product.ProductMaster.ProductSize = size;
                    mainStockInEventArgs.SelectedStockInDetail.Product.ProductMaster.ProductColor = color;
                    EventUtility.fireEvent(LoadGoodsByNameColorSizeEvent, this, mainStockInEventArgs);
                    // load goods to current row
                    var loadGoods =
                        mainStockInEventArgs.SelectedStockInDetail.Product.ProductMaster;
                    deptSIDetailList[selectedIndex] = mainStockInEventArgs.SelectedStockInDetail;
                    bdsStockIn.EndEdit();
                }
                if (deptSIDetailList[selectedIndex] != null)
                {
                    deptSIDetailList[selectedIndex].Quantity = qty;
                    deptSIDetailList[selectedIndex].Price = inPrice;
                    deptSIDetailList[selectedIndex].SellPrice = sellPrice;
                    CalculateTotalStorePrice();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Mã sản phẩm không hợp lệ hoặc lỗi khi nhập");
            }
        }
Exemple #5
0
 private void FillProductToComboBox(object sender, string name)
 {
     var mainStockInEventArgs = new MainStockInEventArgs();
     if (dgvDeptStockIn == null || dgvDeptStockIn.CurrentRow == null)
     {
         return;
     }
     int selectedIndex = dgvDeptStockIn.CurrentRow.Index;
     mainStockInEventArgs.SelectedIndex = selectedIndex;
     mainStockInEventArgs.SelectedStockInDetail = deptSIDetailList[selectedIndex];
     mainStockInEventArgs.IsFillToComboBox = true;
     if (name.Equals("columnProductName"))
     {
         mainStockInEventArgs.ComboBoxDisplayMember = "ProductName";
     }
     if (name.Equals("columnProductId"))
     {
         mainStockInEventArgs.ComboBoxDisplayMember = "ProductMasterId";
     }
     EventUtility.fireEvent<MainStockInEventArgs>(FillProductToComboEvent, sender, mainStockInEventArgs);
 }
 private void cboProductMasters_DropDown(object sender, EventArgs e)
 {
     var mainStockInEventArgs = new MainStockInEventArgs();
     /*if (dgvDeptStockIn == null || dgvDeptStockIn.CurrentRow == null)
     {
         return;
     }*/
     // selectectIndex is the firstrow
     //int selectedIndex = 0;
     //mainStockInEventArgs.SelectedIndex = selectedIndex;
     //mainStockInEventArgs.SelectedStockInDetail = deptSIDetailList[selectedIndex];
     mainStockInEventArgs.SelectedStockInDetail = new StockInDetail { Product = new Product { ProductMaster = new ProductMaster { ProductName = cboProductMasters.Text } } };
     mainStockInEventArgs.IsFillToComboBox = true;
     mainStockInEventArgs.ComboBoxDisplayMember = "ProductName";
     EventUtility.fireEvent<MainStockInEventArgs>(FillProductToComboEvent, cboProductMasters, mainStockInEventArgs);
 }
Exemple #7
0
        private void barcodePrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            var height = 87;
            var numberToPrint = (int)numericUpDownBarcode.Value;
            string code = deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductId;

            if (numberToPrint > 3)
            {
                height = (numberToPrint / 3) * 87;
                numberToPrint = 3;
            }
            var eventArgs = new MainStockInEventArgs{ProductMasterIdForPrice = deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductMaster.ProductMasterId};
            EventUtility.fireEvent(GetPriceEvent, this, eventArgs);
            string titleString = "";
            string name = deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductMaster.ProductName;
            if (eventArgs.DepartmentPrice != null)
            {
                //titleString = name + " Giá : " + eventArgs.DepartmentPrice.Price.ToString("#,##", CultureInfo.CreateSpecificCulture("de-DE")) ;
                titleString = name + " - " + eventArgs.DepartmentPrice.Price.ToString() + ".00 ";
            }
            var code39 = new Code39
                             {
                                 FontFamilyName = "3 of 9 Barcode",
                                 //2.FontFamilyName = "MW6 Code39MT",
                                 //3.FontFamilyName = "MW6 Code39S",
                                 //4.FontFamilyName = "MW6 Code39LT",
                                 //5.FontFamilyName = "Code EAN13",
                                 FontFileName = "Common\\3OF9_NEW.TTF",
                                 //2.FontFileName = "Common\\MW6Code39MT.TTF",
                                 //3.FontFileName = "Common\\MW6Code39S.TTF",
                                 //4.FontFileName = "Common\\MW6Code39LT.TTF",
                                 //5.FontFileName = "Common\\ean13.ttf",
                                 ShowCodeString = true,
                                 FontSize = 12,
                                 TitleFont = new Font("Tahoma", 12),
                                 CodeStringFont = new Font("Tahoma",12),
                                 Title = titleString + " VND"
                        };

            //barcodeControl1.BarcodeData = deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductId;

            BarcodeLib.Barcode barcode = new Barcode();

            string barCodeStr = deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductId;
            Image imageBC = barcode.Encode(BarcodeLib.TYPE.CODE39, barCodeStr, Color.Black, Color.White, (int)(1.35 * e.Graphics.DpiX), (int)(0.45 * e.Graphics.DpiY));

            /*var code39Gen = code39.GenerateBarcode(deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductId,
                                                   (int)((float)(1.5*e.Graphics.DpiX)),(int)((float)(0.75*e.Graphics.DpiY)));*/

            Bitmap bitmap1 = new Bitmap(imageBC);
            bitmap1.SetResolution(204,204);
            /*Bitmap bitmap2 = new Bitmap(code39Gen);
            bitmap2.SetResolution(203,203);*/
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;

            // draw title string

                // calculate scale for title
                var titleStrSize = e.Graphics.MeasureString(titleString.PadRight(25), new Font("Arial",10));
                float currTitleSize = new Font("Arial",10).Size;
                float scaledTitleSize = (150 * currTitleSize) / titleStrSize.Width;
                //Font _titleFont = new Font("Arial", scaledTitleSize);
                Font _titleFont = new Font("Arial", 7);
                string nameString = titleString.Substring(0, titleString.IndexOf(" - "));
                string priceString = titleString.Substring(titleString.IndexOf(" - "));
                var priceTotalSize = e.Graphics.MeasureString(titleString, _titleFont);
                var nameSize = e.Graphics.MeasureString(nameString, _titleFont);
                var priceSize = e.Graphics.MeasureString(priceString, _titleFont);
                var barCodeSize = e.Graphics.MeasureString(barCodeStr, _titleFont);
                /*Bitmap bitmapName = new Bitmap(nameString, true);
                Bitmap bitmapPrice = new Bitmap(priceString, true);*/
            for (int i = 0; i < numberToPrint; i++)
            {

                System.Drawing.Rectangle rc = new System.Drawing.Rectangle((i % 3) * 135, 50, (int)(1.4 * 100), (int)(0.4 * 100));

                //(i % 3) * 124, (i / 3) * 87, 117, 79
                /*e.Graphics.DrawString(nameString, _titleFont, new SolidBrush(Color.Black), (i % 3) * 135 + XCentered(nameSize.Width, 140), 25);
                e.Graphics.DrawString(priceString, _titleFont, new SolidBrush(Color.Black), (i % 3) * 135 + XCentered(priceSize.Width, 140), (float)22.5 + nameSize.Height);*/
                e.Graphics.DrawString(titleString, _titleFont, new SolidBrush(Color.Black), (i % 3) * 140 + XCentered(priceTotalSize.Width, 140), (float)25);
                e.Graphics.DrawImage(bitmap1, new Rectangle((i % 3) * 140 + (int)XCentered((float)(1.35 * 100), 140), (int)(25 + priceTotalSize.Height), (int)(1.35 * 100), (int)(0.45 * 100)));
                e.Graphics.DrawString(barCodeStr, _titleFont, new SolidBrush(Color.Black), (i % 3) * 140 + XCentered(barCodeSize.Width, 140), (float)88);
                //e.Graphics.DrawImage(barcodeControl1.GetMetaFile(), new Rectangle((i % 3) * 135, 120, (i % 3) * 135 + (int)(1.4 * 100), (int)(0.75 * 100)));

            }
        }
        void _departmentStockInView_LoadGoodsByIdEvent(object sender, MainStockInEventArgs e)
        {
            StockInDetail detail = e.SelectedStockInDetail;
            ProductMaster prodMaster = ProductMasterLogic.FindById(detail.Product.ProductMaster.ProductMasterId);
            if (prodMaster == null)
            {
                return;
            }
            detail.Product.ProductMaster = prodMaster;

            e.SelectedStockInDetail = detail;
        }
 void _departmentStockInView_LoadGoodsByNameColorSizeEvent(object sender, MainStockInEventArgs e)
 {
     StockInDetail detail = e.SelectedStockInDetail;
     ObjectCriteria objectCriteria = new ObjectCriteria();
     objectCriteria.AddEqCriteria("ProductName", detail.Product.ProductMaster.ProductName);
     objectCriteria.AddEqCriteria("ProductType", e.SelectedStockInDetail.Product.ProductMaster.ProductType);
     objectCriteria.AddEqCriteria("Country", e.SelectedStockInDetail.Product.ProductMaster.Country);
     objectCriteria.AddEqCriteria("Manufacturer", e.SelectedStockInDetail.Product.ProductMaster.Manufacturer);
     objectCriteria.AddEqCriteria("Distributor", e.SelectedStockInDetail.Product.ProductMaster.Distributor);
     objectCriteria.AddEqCriteria("Packager", e.SelectedStockInDetail.Product.ProductMaster.Packager);
     objectCriteria.AddEqCriteria("ProductColor", e.SelectedStockInDetail.Product.ProductMaster.ProductColor);
     objectCriteria.AddEqCriteria("ProductSize", e.SelectedStockInDetail.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.SelectedStockInDetail = detail;
 }
        void _departmentStockInView_FillProductToComboEvent(object sender, MainStockInEventArgs e)
        {
            ComboBox comboBox = (ComboBox) sender;
            string originalText = comboBox.Text;
            if (e.IsFillToComboBox)
            {
                ProductMaster searchPM = e.SelectedStockInDetail.Product.ProductMaster;
                System.Collections.IList result = null;
                if (e.ComboBoxDisplayMember.Equals("ProductMasterId"))
                {
                    result = ProductMasterLogic.FindProductMasterById(searchPM.ProductMasterId, 50,true);
                }
                else
                {
                    //result = ProductMasterLogic.FindProductMasterByName(searchPM.ProductName, 50,true);
                    ObjectCriteria criteria = new ObjectCriteria();
                    criteria.AddLikeCriteria("ProductName", "%" + searchPM.ProductName + "%");
                    criteria.AddOrder("ProductName", true);
                    criteria.MaxResult = 200;
                    result = ProductMasterLogic.FindAll(criteria);

                }
                if(result==null)
                {
                    return;
                }

                BindingList<ProductMaster> productMasters = new BindingList<ProductMaster>();
                if (result != null)
                {
                    result = RemoveDuplicateName(result);
                    foreach (ProductMaster master in result)
                    {

                        productMasters.Add(master);
                    }
                }
                BindingSource bindingSource = new BindingSource();
                bindingSource.DataSource = productMasters;
                comboBox.DataSource = bindingSource;
                comboBox.DisplayMember = "ProductName";
                comboBox.ValueMember = e.ComboBoxDisplayMember;
                comboBox.DropDownWidth = 300;
                comboBox.DropDownHeight = 200;
                // keep the original text
                comboBox.Text = originalText;
                if (result.Count > 0)
                {
                    comboBox.SelectedIndex = 0;
                }

                comboBox.SelectionStart = comboBox.Text.Length;
                //comboBox.DroppedDown = false;
                comboBox.MaxDropDownItems = 15;
            }
        }
 void _departmentStockInView_GetPriceEvent(object sender, MainStockInEventArgs e)
 {
     var pk = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = e.ProductMasterIdForPrice };
     e.DepartmentPrice = DepartmentPriceLogic.FindById(pk);
 }
 void mainStockInView_LoadStockInEvent(object sender, MainStockInEventArgs e)
 {
     StockIn stockIn = StockInLogic.FindById(e.StockInId);
     if(stockIn!= null)
     {
         foreach (StockInDetail inDetail in stockIn.StockInDetails)
         {
             inDetail.OldQuantity = inDetail.Quantity;
         }
         e.StockIn = stockIn;
     }
 }
        void mainStockInView_LoadAllGoodsByNameEvent(object sender, MainStockInEventArgs e)
        {
            if(e.SelectedProductMaster!=null)
            {
                var criteria = new ObjectCriteria();
                criteria.AddEqCriteria("ProductName", e.SelectedProductMaster.ProductName);
                // sort by color and size

                IList productMastersList = ProductMasterLogic.FindAll(criteria);

                e.ProductMasterList = productMastersList;
            }
        }
 void departmentStockInExtraView_LoadProductSizeEvent(object sender, MainStockInEventArgs e)
 {
     if (e.SelectedStockInDetail != null && e.SelectedStockInDetail.Product != null && !string.IsNullOrEmpty(e.SelectedStockInDetail.Product.ProductMaster.ProductName))
     {
         var subCriteria = new SubObjectCriteria("ProductMasters");
         subCriteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
         subCriteria.AddEqCriteria("ProductType", e.SelectedStockInDetail.Product.ProductMaster.ProductType);
         subCriteria.AddEqCriteria("ProductName", e.SelectedStockInDetail.Product.ProductMaster.ProductName);
         subCriteria.AddEqCriteria("ProductColor", e.SelectedStockInDetail.Product.ProductMaster.ProductColor);
         subCriteria.AddEqCriteria("Country", e.SelectedStockInDetail.Product.ProductMaster.Country);
         subCriteria.AddEqCriteria("Manufacturer", e.SelectedStockInDetail.Product.ProductMaster.Manufacturer);
         subCriteria.AddEqCriteria("Distributor", e.SelectedStockInDetail.Product.ProductMaster.Distributor);
         subCriteria.AddEqCriteria("Packager", e.SelectedStockInDetail.Product.ProductMaster.Packager);
         var criteria = new ObjectCriteria();
         criteria.AddSubCriteria("ProductMasters", subCriteria);
         IList productSizes = ProductSizeLogic.FindAll(criteria);
         e.ProductSizeList = productSizes;
     }
 }
        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 (StockInDetail 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;
                }

                if (detail.Quantity > (detail.StockOutQuantity-detail.ReStockQuantity))
                {
                    MessageBox.Show("Lỗi ở dòng " + errMsg.ToString() + " : Số lượng phải nhỏ hơn số lượng tạm xuất là " + (detail.StockOutQuantity - detail.ReStockQuantity).ToString());
                    return;
                }
                line++;
            }

            if (deptSI == null)
            {
                deptSI = new StockIn();
            }
            bool isNeedClearData = string.IsNullOrEmpty(deptSI.StockInId);
            deptSI.StockInDate = dtpImportDate.Value;
            deptSI.StockInDetails = deptSIDetailList;
            deptSI.Description = txtDexcription.Text;
            deptSI.StockInCost = cost;
            var eventArgs = new MainStockInEventArgs();
            eventArgs.StockIn = deptSI;
            EventUtility.fireEvent(SaveReStockInEvent, this, eventArgs);
            if (eventArgs.EventResult != null)
            {
                MessageBox.Show("Lưu thành công");
                if (isNeedClearData)
                {
                    deptSI = new StockIn();
                    deptSIDetailList.Clear();
                    txtBarcode.Text = "";
                    txtQty.Text = "";
                    txtDexcription.Text = "";
                    txtPriceIn.Text = "";
                    txtPriceOut.Text = "";
                    txtSumProduct.Text = "";
                    txtSumValue.Text = "";
                    ClearSelectionOnListBox(lstColor);
                    ClearSelectionOnListBox(lstSize);
                    //CreateNewStockInDetail();
                }
            }
            else
            {
                //MessageBox.Show("Có lỗi khi lưu");
            }
        }
 void _departmentStockInView_LoadGoodsByNameEvent(object sender, MainStockInEventArgs e)
 {
     StockInDetail detail = e.SelectedStockInDetail;
     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.SelectedStockInDetail = detail;
     ObjectCriteria priceCrit = new ObjectCriteria();
     DepartmentPricePK pricePk = new DepartmentPricePK
                                     {
                                         ProductMasterId = prodMaster.ProductMasterId,
                                         DepartmentId = 0
                                     };
     DepartmentPrice price = DepartmentPriceLogic.FindById(pricePk);
     e.DepartmentPrice = price;
 }
        private void barcodePrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            var height = 87;
            var numberToPrint = (int)numericUpDownBarcode.Value;
            string code = deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductId;

            if (numberToPrint > 3)
            {
                height = (numberToPrint / 3) * 87;
            }
            var eventArgs = new MainStockInEventArgs { ProductMasterIdForPrice = deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductMaster.ProductMasterId };
            EventUtility.fireEvent(GetPriceEvent, this, eventArgs);
            string priceStr = "";
            if (eventArgs.DepartmentPrice != null)
            {
                priceStr = "Giá" + eventArgs.DepartmentPrice.Price.ToString("#,##", CultureInfo.CreateSpecificCulture("de-DE"));
            }
            /*var code39 = new Code39
                          {
                         FontFamilyName = "Free 3 of 9 Extended",
                         //2.FontFamilyName = "MW6 Code39MT",
                         //3.FontFamilyName = "MW6 Code39S",
                         //4.FontFamilyName = "MW6 Code39LT",
                         //5.FontFamilyName = "Code EAN13",
                         FontFileName = "Common\\FRE3OF9X.TTF",
                         //2.FontFileName = "Common\\MW6Code39MT.TTF",
                         //3.FontFileName = "Common\\MW6Code39S.TTF",
                         //4.FontFileName = "Common\\MW6Code39LT.TTF",
                         //5.FontFileName = "Common\\ean13.ttf",
                         ShowCodeString = true,
                         FontSize = 25,
                         Title = "Giá " + priceStr + " VND"
                        };

            var codeGen = code39.GenerateBarcode("*" + deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductId+ "*");*/
            /*var setting = new Code39Settings();
            setting.BarCodeHeight = 50;
            setting.DrawText = true;
            var code39Ex = new Code39Ex(deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductId,
                setting);*/

            /*BarcodeX codeGen = new BarcodeX();
            codeGen.Title = priceStr.ToUpper();
            codeGen.Font = new Font("Arial", (float)12, FontStyle.Regular);
            codeGen.Data = "*" + deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductId + "*";
            codeGen.Width = (int)(1.25 * 150);
            codeGen.Height = (int)(0.75 * 150);
            codeGen.Symbology = bcType.Code39;
            codeGen.ShowText = true;

            for (int i = 0; i < numberToPrint; i++)
            {
                System.Drawing.Rectangle rc = new System.Drawing.Rectangle((i % 3) * 135, (i / 3) * 100, (int)(1.25 * 100), (int)(0.75 * 100));
                //(i % 3) * 124, (i / 3) * 87, 117, 79
                e.Graphics.DrawImage(codeGen.Image((int)((float)1.25 * e.Graphics.DpiX), (int)((float)0.75 * e.Graphics.DpiY)), rc);

                //e.HasMorePages=false;
                //e.Graphics.DrawImageUnscaled(codeGen.Image(codeGen.Width,codeGen.Height));
            }*/
        }
 void _departmentStockInView_SaveStockInEvent(object sender, MainStockInEventArgs e)
 {
     if (string.IsNullOrEmpty(e.StockIn.StockInId))
     {
         StockInLogic.Add(e.StockIn);
         ClientUtility.Log(logger, e.StockIn.ToString(), CommonConstants.ACTION_ADD_STOCK_IN);
     }
     else
     {
         StockInLogic.Update(e.StockIn);
         ClientUtility.Log(logger, e.StockIn.ToString(), CommonConstants.ACTION_UPDATE_STOCK_IN);
     }
     e.EventResult = "Success";
 }
        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 MainStockInEventArgs();
            mainStockInEventArgs.SelectedStockInDetail = new StockInDetail();
            mainStockInEventArgs.SelectedStockInDetail.Product = new Product{ProductMaster = new ProductMaster()};
            mainStockInEventArgs.SelectedStockInDetail.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 LoadProductMasterToComboBox()
 {
     var mainStockInEventArgs = new MainStockInEventArgs();
     mainStockInEventArgs.SelectedStockInDetail = new StockInDetail{Product = new Product{ProductMaster = new ProductMaster{ProductName = ""}}};
     mainStockInEventArgs.IsFillToComboBox = true;
     mainStockInEventArgs.ComboBoxDisplayMember = "ProductName";
     EventUtility.fireEvent<MainStockInEventArgs>(FillProductToComboEvent, cboProductMasters, mainStockInEventArgs);
 }
Exemple #21
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // first remove all blank row
            int count = 0;
            int length = deptSIDetailList.Count;
            for (int i = 0; i < length - count; i++)
            {
                StockInDetail 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 để nhập kho!!!!");
                return;
            }

            // validate quantity
            StringBuilder errMsg = new StringBuilder();
            int line = 1;
            foreach (StockInDetail 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;
            }
            foreach (StockInDetail detail in deptSIDetailList)
            {
                count = 0;
                foreach (StockInDetail detail2 in deptSIDetailList)
                {
                    if (detail.DelFlg == CommonConstants.DEL_FLG_NO && detail.Product.ProductMaster.ProductMasterId.Equals(detail2.Product.ProductMaster.ProductMasterId))
                    {
                        if (count == 0)
                        {
                            count++;
                        }
                        else
                        {
                            MessageBox.Show("Lỗi : Mã hàng " + detail.Product.ProductMaster.ProductMasterId + " nhập 2 lần");
                            return;
                        }
                    }

                }
            }

            if (deptSI == null)
            {
                deptSI = new StockIn();
            }
            bool isNeedClearData = string.IsNullOrEmpty(deptSI.StockInId);
            deptSI.StockInDate = dtpImportDate.Value;
            deptSI.StockInDetails = deptSIDetailList;
            var eventArgs = new MainStockInEventArgs();
            eventArgs.StockIn = deptSI;
            EventUtility.fireEvent(SaveStockInEvent, this, eventArgs);
            if (!string.IsNullOrEmpty(deptSI.StockInId))
            {
                MessageBox.Show("Lưu thành công");
                if (isNeedClearData)
                {
                    deptSI = new StockIn();
                    deptSIDetailList.Clear();
                    CreateNewStockInDetail();
                }
            }
            else
            {
                MessageBox.Show("Có lỗi khi lưu");
            }
        }
 private void LoadStockIn()
 {
     deptSIDetailList.Clear();
     MainStockInEventArgs eventArgs = new MainStockInEventArgs();
     eventArgs.StockIn = StockIn;
     foreach (StockInDetail inDetail in StockIn.StockInDetails)
     {
         inDetail.ProductMaster = inDetail.Product.ProductMaster;
         deptSIDetailList.Add(inDetail);
     }
     bdsStockIn.ResetBindings(false);
     dgvDeptStockIn.Refresh();
     dgvDeptStockIn.Invalidate();
 }
Exemple #23
0
        private void dgvDeptStockIn_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            string columnName = dgvDeptStockIn.CurrentCell.OwningColumn.Name;
            if (columnName.Equals("columnProductId")
                || columnName.Equals("columnProductName"))
            {

                var 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);
            }

            var mainStockInEventArgs = new MainStockInEventArgs();
            if (dgvDeptStockIn == null || dgvDeptStockIn.CurrentRow == null)
            {
                return;
            }
            int selectedIndex = dgvDeptStockIn.CurrentRow.Index;
            mainStockInEventArgs.SelectedIndex = selectedIndex;
            mainStockInEventArgs.SelectedStockInDetail = deptSIDetailList[selectedIndex];

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

            if( columnName.Equals("columnSize"))
            {
                // put size to list
                EventUtility.fireEvent(LoadProductSizeEvent, this, mainStockInEventArgs);
                if (mainStockInEventArgs.ProductSizeList != null && mainStockInEventArgs.ProductSizeList.Count > 0)
                {
                    var comboBox = ((ComboBox)e.Control);
                    comboBox.DataSource = mainStockInEventArgs.ProductSizeList;
                    CurrentRowProductSizeList = mainStockInEventArgs.ProductSizeList;
                    comboBox.DisplayMember = "SizeName";
                    comboBox.ValueMember = "SizeName";
                }
                else
                {
                    CurrentRowProductSizeList = null;
                }
                mainStockInEventArgs.ProductSizeList = null;
            }
        }
        private void barcodePrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            var height = 87;
            var numberToPrint = (int)numericUpDownBarcode.Value;
            string code = deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductId;

            if (numberToPrint > 3)
            {
                height = (numberToPrint / 3) * 87;
            }
            var eventArgs = new MainStockInEventArgs { ProductMasterIdForPrice = deptSIDetailList[dgvDeptStockIn.CurrentRow.Index].Product.ProductMaster.ProductMasterId };
            EventUtility.fireEvent(GetPriceEvent, this, eventArgs);
            string priceStr = "";
            if (eventArgs.DepartmentPrice != null)
            {
                priceStr = "Giá" + eventArgs.DepartmentPrice.Price.ToString("#,##", CultureInfo.CreateSpecificCulture("de-DE"));
            }
        }
        private void barcodePrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            if (!chkContinuePrint.Checked)
            {
                var height = 87;
                var numberToPrint = (int)numericUpDownBarcode.Value;
                string code = deptStockOutDetailList[dgvStockOutDetail.CurrentRow.Index].StockOutDetail.Product.ProductId;

                if (numberToPrint > 3)
                {
                    height = (numberToPrint / 3) * 87;
                    numberToPrint = 3;
                }
                var eventArgs = new MainStockInEventArgs
                {
                    ProductMasterIdForPrice = deptStockOutDetailList[dgvStockOutDetail.CurrentRow.Index].StockOutDetail.ProductMaster.ProductMasterId
                };
                EventUtility.fireEvent(GetPriceEvent, this, eventArgs);
                string titleString = "";
                string name = deptStockOutDetailList[dgvStockOutDetail.CurrentRow.Index].StockOutDetail.ProductMaster.ProductName;
                if (chkPricePrint.Checked && eventArgs.DepartmentPrice != null)
                {
                    titleString = name + " - " + eventArgs.DepartmentPrice.Price.ToString() + ".00 ";
                }
                else
                {
                    titleString = name;
                }

                BarcodeLib.Barcode barcode = new Barcode();
                string barCodeStr = deptStockOutDetailList[dgvStockOutDetail.CurrentRow.Index].StockOutDetail.Product.ProductId;
                string colorSize = "";
                if (deptStockOutDetailList[dgvStockOutDetail.CurrentRow.Index].StockOutDetail.ProductMaster.ProductColor.ColorId > 0)
                {
                    colorSize += "M:" +
                                 deptStockOutDetailList[dgvStockOutDetail.CurrentRow.Index].StockOutDetail.ProductMaster.ProductColor.
                                     ColorName;
                }
                if (deptStockOutDetailList[dgvStockOutDetail.CurrentRow.Index].StockOutDetail.ProductMaster.ProductSize.SizeId > 0)
                {
                    if (colorSize.Length > 0)
                    {
                        colorSize += " - ";
                    }
                    colorSize += "S:" +
                                 deptStockOutDetailList[dgvStockOutDetail.CurrentRow.Index].StockOutDetail.ProductMaster.ProductSize.
                                     SizeName;
                }
                Image imageBC = null;
                if (ClientSetting.BarcodeType == BarcodeLib.TYPE.CODE128)
                {
                    imageBC = barcode.Encode(ClientSetting.BarcodeType, barCodeStr, Color.Black, Color.White,
                                                    (int)(1.3 * e.Graphics.DpiX), (int)(0.3 * e.Graphics.DpiY));
                }
                else
                {
                    imageBC = barcode.Encode(ClientSetting.BarcodeType, barCodeStr, Color.Black, Color.White,
                                                   (int)(1.35 * e.Graphics.DpiX), (int)(0.3 * e.Graphics.DpiY));
                }

                Bitmap bitmap1 = new Bitmap(imageBC);
                bitmap1.SetResolution(204, 204);
                e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                e.Graphics.CompositingQuality = CompositingQuality.HighQuality;

                // draw title string

                // calculate scale for title
                var titleStrSize = e.Graphics.MeasureString(titleString.PadRight(25), new Font("Arial", 10));
                float currTitleSize = new Font("Arial", 10).Size;
                float scaledTitleSize = (150 * currTitleSize) / titleStrSize.Width;
                Font _titleFont = new Font("Arial", 7);
                var priceTotalSize = e.Graphics.MeasureString(titleString, _titleFont);
                var colorSizeSize = e.Graphics.MeasureString(colorSize, _titleFont);
                var barCodeSize = e.Graphics.MeasureString(barCodeStr, _titleFont);
                for (int i = 0; i < numberToPrint; i++)
                {

                    System.Drawing.Rectangle rc = new System.Drawing.Rectangle((i % 3) * 135, 50, (int)(1.4 * 100),
                                                                               (int)(0.4 * 100));

                    //(i % 3) * 124, (i / 3) * 87, 117, 79
                    e.Graphics.DrawString(titleString, _titleFont, new SolidBrush(Color.Black),
                                          (i % 3) * 135 + XCentered(priceTotalSize.Width, 140), (float)25);

                    if (ClientSetting.BarcodeType == BarcodeLib.TYPE.CODE128)
                    {
                        e.Graphics.DrawImage(bitmap1,
                                             new Rectangle((i % 3) * 140 + (int)XCentered((float)(1.3 * 100), 140),
                                                           (int)(25 + priceTotalSize.Height), (int)(1.3 * 100),
                                                           (int)(0.3 * 100)));
                    }
                    else
                    {
                        e.Graphics.DrawImage(bitmap1,
                                             new Rectangle((i % 3) * 140 + (int)XCentered((float)(1.35 * 100), 140),
                                                           (int)(25 + priceTotalSize.Height), (int)(1.35 * 100),
                                                           (int)(0.3 * 100)));
                    }

                    e.Graphics.DrawString(barCodeStr, _titleFont, new SolidBrush(Color.Black),
                                          (i % 3) * 140 + XCentered(barCodeSize.Width, 140), (float)72);
                    e.Graphics.DrawString(colorSize, _titleFont, new SolidBrush(Color.Black),
                                          (i % 3) * 140 + XCentered(colorSizeSize.Width, 140), (float)88);

                }
            }
            else // continue printing
            {
                var height = 87;
                if (printList == null || printList.Count == 0)
                {
                    return;
                }
                var numberToPrint = printList.Count;

                for (int i = 0; i < numberToPrint; i++)
                {
                    string code = printList[i].ProductId;
                    var eventArgs = new MainStockInEventArgs
                    {
                        ProductMasterIdForPrice = printList[i].ProductMaster.ProductMasterId
                    };
                    EventUtility.fireEvent(GetPriceEvent, this, eventArgs);
                    string titleString = "";
                    string name = printList[i].ProductMaster.ProductName;
                    if (chkPricePrint.Checked && eventArgs.DepartmentPrice != null)
                    {
                        titleString = name + " - " + eventArgs.DepartmentPrice.Price.ToString() + ".00 ";
                    }
                    else
                    {
                        titleString = name;
                    }

                    BarcodeLib.Barcode barcode = new Barcode();
                    string barCodeStr = printList[i].ProductId;
                    string colorSize = "";
                    if (printList[i].ProductMaster.ProductColor.ColorId > 0)
                    {
                        colorSize += "M:" +
                                     printList[i].ProductMaster.ProductColor.ColorName;
                    }
                    if (printList[i].ProductMaster.ProductSize.SizeId > 0)
                    {
                        if (colorSize.Length > 0)
                        {
                            colorSize += " - ";
                        }
                        colorSize += "S:" +
                                     printList[i].ProductMaster.ProductSize.SizeName;
                    }
                    Image imageBC = null;
                    if (ClientSetting.BarcodeType == BarcodeLib.TYPE.CODE128)
                    {
                        imageBC = barcode.Encode(ClientSetting.BarcodeType, barCodeStr, Color.Black, Color.White,
                                                        (int)(1.3 * e.Graphics.DpiX), (int)(0.3 * e.Graphics.DpiY));
                    }
                    else
                    {
                        imageBC = barcode.Encode(ClientSetting.BarcodeType, barCodeStr, Color.Black, Color.White,
                                                       (int)(1.35 * e.Graphics.DpiX), (int)(0.3 * e.Graphics.DpiY));
                    }

                    Bitmap bitmap1 = new Bitmap(imageBC);
                    bitmap1.SetResolution(204, 204);
                    e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                    e.Graphics.CompositingQuality = CompositingQuality.HighQuality;

                    // draw title string

                    // calculate scale for title
                    var titleStrSize = e.Graphics.MeasureString(titleString.PadRight(25), new Font("Arial", 10));
                    float currTitleSize = new Font("Arial", 10).Size;
                    float scaledTitleSize = (150 * currTitleSize) / titleStrSize.Width;
                    Font _titleFont = new Font("Arial", 7);
                    Font _barCodeFont = new Font("Arial", 8);
                    var priceTotalSize = e.Graphics.MeasureString(titleString, _titleFont);
                    var colorSizeSize = e.Graphics.MeasureString(colorSize, _titleFont);
                    var barCodeSize = e.Graphics.MeasureString(barCodeStr, _barCodeFont);

                    System.Drawing.Rectangle rc = new System.Drawing.Rectangle((i % 3) * 135, 50, (int)(1.4 * 100),
                                                                               (int)(0.4 * 100));

                    e.Graphics.DrawString(titleString, _titleFont, new SolidBrush(Color.Black),
                                          (i % 3) * 135 + XCentered(priceTotalSize.Width, 140), (float)25);

                    if (ClientSetting.BarcodeType == BarcodeLib.TYPE.CODE128)
                    {
                        e.Graphics.DrawImage(bitmap1,
                                             new Rectangle((i % 3) * 140 + (int)XCentered((float)(1.3 * 100), 140),
                                                           (int)(25 + priceTotalSize.Height), (int)(1.3 * 100),
                                                           (int)(0.3 * 100)));
                    }
                    else
                    {
                        e.Graphics.DrawImage(bitmap1,
                                             new Rectangle((i % 3) * 140 + (int)XCentered((float)(1.35 * 100), 140),
                                                           (int)(25 + priceTotalSize.Height), (int)(1.35 * 100),
                                                           (int)(0.3 * 100)));
                    }
                    e.Graphics.DrawString(barCodeStr, _barCodeFont, new SolidBrush(Color.Black),
                                          (i % 3) * 140 + XCentered(barCodeSize.Width, 140), (float)72);
                    e.Graphics.DrawString(colorSize, _titleFont, new SolidBrush(Color.Black),
                                          (i % 3) * 140 + XCentered(colorSizeSize.Width, 140), (float)88);

                }
            }
        }
        public void mainStockInView_FindByBarcodeEvent(object sender, MainStockInEventArgs e)
        {
            var subCriteria = new SubObjectCriteria("StockOut");
            subCriteria.AddEqCriteria("DefectStatus.DefectStatusId", (long)4); // tạm xuất là 4
            var objectCriteria = new ObjectCriteria();
            objectCriteria.AddEqCriteria("Product.ProductId", e.ProductId);
            objectCriteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
            objectCriteria.AddEqCriteria("DefectStatus.DefectStatusId", (long) 4);
            //objectCriteria.AddSubCriteria("StockOut", subCriteria);
            IList list = StockOutDetailLogic.FindAll(objectCriteria);
            if (list!=null && list.Count > 0)
            {
                var detail = new StockInDetail { Product = ((StockOutDetail)list[0]).Product };
                foreach (StockOutDetail soDetail in list)
                {
                    detail.StockOutQuantity += soDetail.Quantity;
                }
                e.StockInDetail = detail;
            }

            IList reStockInList = StockInLogic.FindReStockIn(e.ProductId);
            if(reStockInList!=null)
            {
                foreach (StockInDetail inDetail in reStockInList)
                {
                    e.StockInDetail.ReStockQuantity += inDetail.Quantity;
                }
            }

            e.EventResult = "Success";
        }