Exemple #1
0
        private void loadSomeData()
        {
            ProductAttributeService productAttrService = new ProductAttributeService();

            products = new BindingList <ProductAttributeModel>(productAttrService.GetProductAndAttribute());
            units    = new BindingList <MeasurementUnit>(unitService.GetMeasurementUnits());
            if (entranceStock != null)
            {
                txtCode.Text = entranceStock.EntranceCode;
                txtNote.Text = entranceStock.Note;
                txtDate.Text = entranceStock.CreatedDate.ToString(BHConstant.DATE_FORMAT);
                txtUser.Text = entranceStock.SystemUser.FullName;
            }
            else
            {
                if (Global.CurrentUser != null)
                {
                    txtUser.Text = Global.CurrentUser.FullName;
                }
                txtUser.Enabled = false;
                txtDate.Text    = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate().ToString(BHConstant.DATE_FORMAT);
                txtCode.Text    = Global.GetTempSeedID(BHConstant.PREFIX_FOR_ENTRANCE);
            }
            txtDate.Enabled = false;
            txtUser.Enabled = false;
        }
Exemple #2
0
 public void updateProductionRequestDetailCells()
 {
     if (isUpdating && entranceStock != null && entranceStockDetails.Count < dgvStockEntranceDetails.RowCount)
     {
         ProductAttributeService productAttrService = new ProductAttributeService();
         for (int i = 0; i < entranceStockDetails.Count; i++)
         {
             // Product + Attribute
             if (dgvStockEntranceDetails.Rows[i].Cells[ProductAttrCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgvStockEntranceDetails.Rows[i].Cells[ProductAttrCell];
                 try
                 {
                     pkgBoxCell.Value = productAttrService.GetProductAttribute(entranceStockDetails[i].ProductId,
                                                                               entranceStockDetails[i].AttributeId).Id;
                 }
                 catch { }
             }
             // Unit
             if (dgvStockEntranceDetails.Rows[i].Cells[UnitCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgvStockEntranceDetails.Rows[i].Cells[UnitCell];
                 try
                 {
                     pkgBoxCell.Value = entranceStockDetails[i].UnitId;
                 }
                 catch { }
             }
         }
     }
 }
 public void Init()
 {
     productAttributeService                 = new ProductAttributeService();
     productAttributeService.Credentials     = new System.Net.NetworkCredential(WEBSERVICE_LOGIN, WEBSERVICE_PASSWORD);
     productAttributeService.PreAuthenticate = true;
     productAttributeService.Url             = WEBSERVICE_URL;
 }
 private void dgvProductAttributeList_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (sender is DataGridView)
     {
         DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
         if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
         {
             DialogResult result = MessageBox.Show("Bạn có muốn xóa Quy cách sản phẩm này?",
                                                   "Xoá Quy cách sản phẩm này",
                                                   MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Question);
             if (result == DialogResult.Yes)
             {
                 DataGridViewRow      currentRow           = dgvProductAttributeList.Rows[e.RowIndex];
                 BaseAttributeService baseAttributeService = new BaseAttributeService();
                 int id = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id");
                 ProductAttributeService productAttributeService = new ProductAttributeService();
                 List <ProductAttribute> productList             = productAttributeService.SelectProductAttributeByWhere(x => x.AttributeId == id);
                 if (productList.Count > 0)
                 {
                     MessageBox.Show("Quy cách sản phẩm này đang được sử dụng. Không xóa được!");
                 }
                 else
                 {
                     if (!baseAttributeService.DeleteBaseAttribute(id))
                     {
                         MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                     loadProductAttributeList();
                 }
             }
         }
     }
 }
 private void loadSomeData()
 {
     ProductAttributeService productAttrService = new ProductAttributeService();
     products = new BindingList<ProductAttributeModel>(productAttrService.GetProductAndAttribute());
     units = new BindingList<MeasurementUnit>(unitService.GetMeasurementUnits());
     if (entranceStock != null)
     {
         txtCode.Text = entranceStock.EntranceCode;
         txtNote.Text = entranceStock.Note;
         txtDate.Text = entranceStock.CreatedDate.ToString(BHConstant.DATE_FORMAT);
         txtUser.Text = entranceStock.SystemUser.FullName;
     }
     else
     {
         if (Global.CurrentUser != null)
         {
             txtUser.Text = Global.CurrentUser.FullName;
         }                
         txtUser.Enabled = false;
         txtDate.Text = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate().ToString(BHConstant.DATE_FORMAT);
         txtCode.Text = Global.GetTempSeedID(BHConstant.PREFIX_FOR_ENTRANCE);
     }
     txtDate.Enabled = false;
     txtUser.Enabled = false;
 }
Exemple #6
0
        public ActionResult Index4()
        {
            IProductAttributeInfo       attBll  = new ProductAttributeService();
            List <ProductAttributeInfo> attlist = attBll.SearchByproductid("320620");

            return(View());
        }
Exemple #7
0
        private void btnCreateSP_Click(object sender, EventArgs e)
        {
            AddProduct frmProduct = new AddProduct();

            if (frmProduct.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ProductAttributeService productAttrService = new ProductAttributeService();
                products = new BindingList <ProductAttributeModel>(productAttrService.GetProductAndAttribute());
                ((DataGridViewComboBoxColumn)dgvStockEntranceDetails.Columns[0]).DataSource = products;
            }
        }
        private bool UpdateAttribute(long newProductId)
        {
            DataGridViewRowCollection selectedRows            = dgvBaseAttributes.Rows;
            ProductAttributeService   productAttributeService = new ProductAttributeService();

            bool       result = true;
            List <int> newAttr = new List <int>();
            List <int> addAttr, removeAttr;

            foreach (DataGridViewRow dgv in selectedRows)
            {
                DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dgv.Cells[0];
                if (checkbox.Value != null &&
                    (checkbox.Value.ToString().Equals(bool.TrueString) || checkbox.Value.ToString().Equals("1")))
                {
                    newAttr.Add(((BaseAttribute)dgv.DataBoundItem).Id);
                }
            }

            addAttr    = newAttr.Except(oldAttr).ToList();
            removeAttr = oldAttr.Except(newAttr).ToList();

            foreach (int add in addAttr)
            {
                ProductAttribute pa = new ProductAttribute()
                {
                    ProductId   = (int)newProductId,
                    AttributeId = add
                };
                result = productAttributeService.AddProductAttribute(pa);
            }

            foreach (int remove in removeAttr)
            {
                int removeId = -1;
                using (BaoHienDBDataContext context = new BaoHienDBDataContext(SettingManager.BuildStringConnection()))
                {
                    ProductAttribute pa = context.ProductAttributes
                                          .Where(p => p.AttributeId == remove && p.ProductId == (int)newProductId).SingleOrDefault();
                    if (pa != null)
                    {
                        removeId = pa.Id;
                    }
                }
                if (removeId != -1)
                {
                    result = productAttributeService.DeleteProductAttribute(removeId);
                }
            }
            BaoHienRepository.ResetDBDataContext();
            return(result);
        }
Exemple #9
0
        private void dgvStockEntranceDetails_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;

            if (entranceStockDetails == null)
            {
                entranceStockDetails = new BindingList <EntranceStockDetail>();
            }
            if (entranceStockDetails.Count < dgvStockEntranceDetails.RowCount - 1)
            {
                EntranceStockDetail entranceStockDetail = new EntranceStockDetail();
                entranceStockDetails.Add(entranceStockDetail);
            }
            if (dgv.CurrentCell.Value != null)
            {
                switch (e.ColumnIndex)
                {
                case ProductAttrCell:
                {
                    ProductAttributeService productAttrService = new ProductAttributeService();
                    ProductAttribute        pa = productAttrService.GetProductAttribute((int)dgv.CurrentCell.Value);
                    if (pa != null)
                    {
                        entranceStockDetails[e.RowIndex].ProductId   = pa.ProductId;
                        entranceStockDetails[e.RowIndex].AttributeId = pa.AttributeId;
                    }
                } break;

                case NumberUnitCell:
                {
                    int value = (int)dgv.CurrentCell.Value;
                    if (value < 0)
                    {
                        entranceStockDetails[e.RowIndex].NumberUnit = 0;
                    }
                    else
                    {
                        entranceStockDetails[e.RowIndex].NumberUnit = value;
                    }
                } break;

                case UnitCell:
                    entranceStockDetails[e.RowIndex].UnitId = (int)dgv.CurrentCell.Value;
                    break;

                case NoteCell:
                    entranceStockDetails[e.RowIndex].Note = (string)dgv.CurrentCell.Value;
                    break;
                }
            }
        }
        private static ShoppingCart PrepareCart()
        {
            var contentManager              = new ContentManagerStub(Products.Cast <IContent>().Union(ProductAttributes));
            var cartStorage                 = new FakeCartStorage();
            var attributeService            = new ProductAttributeService(contentManager);
            var attributeExtensionProviders = new List <IProductAttributeExtensionProvider> {
                new TextProductAttributeExtensionProvider(new ShapeFactoryStub())
            };
            var priceService    = new PriceService(new IPriceProvider[0], attributeService);
            var attributeDriver = new ProductAttributesPartDriver(attributeService, attributeExtensionProviders);
            var cart            = new ShoppingCart(contentManager, cartStorage, priceService, new[] { attributeDriver }, null, new Notifier());

            return(cart);
        }
    protected DataSet BindAttributeData()
    {
        int attributeTypeId = int.Parse(lstAttributeTypeList.SelectedValue);

        ProductAttributeService attributeService = new ProductAttributeService();
        TList<ProductAttribute> _attribute;

        if (attributeTypeId != 0)
        {
            _attribute = attributeService.GetByAttributeTypeId(attributeTypeId);
        }
        else
        {
            _attribute = attributeService.GetAll();
        }

        return _attribute.ToDataSet(true);
    }
        public BaseController()
        {
            _relatedProductService = new RelatedProductService();
            _productSpecificationAttributeMappingService = new ProductSpecificationAttributeMappingService();
            _specificationAttributeValueService          = new SpecificationAttributeValueService();
            _specificationAttributeService = new SpecificationAttributeService();
            _prodcutAttributeValueService  = new ProdcutAttributeValueService();
            _productAttributeService       = new ProductAttributeService();
            _productCategoryMappingService = new ProductCategoryMappingService();
            _categoryService = new CategoryService();
            _productPictureMappingService = new ProductPictureMappingService();
            _pictureService           = new PictureService();
            _productService           = new ProductService();
            _brandService             = new BrandService();
            _productTagMappingService = new ProductTagMappingService();
            _produtTagService         = new ProductTagService();
            _predefinedProductAttributeValueService = new PredefinedProductAttributeValueService();
            _productAttributeMappingService         = new ProductAttributeMappingService();

            _customerService            = new CustomerService();
            _customerRoleService        = new CustomerRoleService();
            _customerRoleMappingService = new CustomerRolMappingService();
        }
        public void ProductAttributeServiceCanFindAttributesOnProducts()
        {
            var productAttributeService = new ProductAttributeService(null, new FakeContentDefinitionManager(), new FakeContentDefinitionService(), null);
            var product = new ContentItem()
            {
                ContentType = "Product"
            };
            var productPart1         = new ContentPart {
            };
            var boolProductAttribute = new BooleanProductAttributeField();

            productPart1.Weld("foobool", boolProductAttribute);
            productPart1.Weld("barbool", new BooleanField());
            product.Weld("ProductPart1", productPart1);
            var productPart2         = new ContentPart {
            };
            var textProductAttribute = new TextProductAttributeField();

            productPart2.Weld("footext", textProductAttribute);
            productPart2.Weld("bartext", new TextField());
            product.Weld("ProductPart2", productPart2);

            var productAttributeFields = productAttributeService.GetProductAttributeFields(product).ToArray();

            Assert.Equal(2, productAttributeFields.Length);
            var foobool = productAttributeFields.FirstOrDefault(f => f.Name == "foobool");

            Assert.Equal("ProductPart1", foobool.PartName);
            Assert.Equal(boolProductAttribute, foobool.Field);
            Assert.IsType <BooleanProductAttributeFieldSettings>(foobool.Settings);
            var footext = productAttributeFields.FirstOrDefault(f => f.Name == "footext");

            Assert.Equal("ProductPart2", footext.PartName);
            Assert.Equal(textProductAttribute, footext.Field);
            Assert.IsType <TextProductAttributeFieldSettings>(footext.Settings);
        }
 private void btnCreateSX_Click(object sender, EventArgs e)
 {
     AddProductionRequest frmRequest = new AddProductionRequest();
     frmRequest.ShowDialog();
     ProductAttributeService productAttrService = new ProductAttributeService();
     productAttrs = new BindingList<ProductAttributeModel>(productAttrService.GetProductAndAttribute());
     ((DataGridViewComboBoxColumn)dgwOrderDetails.Columns[0]).DataSource = productAttrs;
 }
 private void btnCreateNK_Click(object sender, EventArgs e)
 {
     AddEntranceStock frmStock = new AddEntranceStock();
     frmStock.ShowDialog();
     ProductAttributeService productAttrService = new ProductAttributeService();
     productForProducts = new BindingList<ProductAttributeModel>(productAttrService.GetProductAndAttribute());
     ((DataGridViewComboBoxColumn)dgvMaterial.Columns[0]).DataSource = productForProducts;
     ((DataGridViewComboBoxColumn)dgvProduct.Columns[0]).DataSource = productForProducts;
 }
 public void updateProductionRequestDetailCells()
 {
     ProductAttributeService productAttrService = new ProductAttributeService();
     if (isUpdating && productionRequest != null && productionRequestDetailInProductions.Count < dgvProduct.RowCount)
     {
         for (int i = 0; i < productionRequestDetailInProductions.Count; i++)
         {
             if (dgvProduct.Rows[i].Cells[ProductAttrCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgvProduct.Rows[i].Cells[ProductAttrCell];
                 try
                 {
                     pkgBoxCell.Value = productAttrService.GetProductAttribute(productionRequestDetailInProductions[i].ProductId,
                         productionRequestDetailInProductions[i].AttributeId).Id;
                 }
                 catch { }
             }
             // Unit
             if (dgvProduct.Rows[i].Cells[UnitCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgvProduct.Rows[i].Cells[UnitCell];
                 try
                 {
                     pkgBoxCell.Value = productionRequestDetailInProductions[i].UnitId;
                 }
                 catch { }
             }
         }
     }
     if (isUpdating && productionRequest != null && productionRequestDetailInMaterials.Count < dgvMaterial.RowCount)
     {
         for (int i = 0; i < productionRequestDetailInMaterials.Count; i++)
         {
             if (dgvMaterial.Rows[i].Cells[ProductAttrCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgvMaterial.Rows[i].Cells[ProductAttrCell];
                 try
                 {
                     pkgBoxCell.Value = productAttrService.GetProductAttribute(productionRequestDetailInMaterials[i].ProductId,
                         productionRequestDetailInMaterials[i].AttributeId).Id;
                 }
                 catch { }
             }
             // Unit
             if (dgvMaterial.Rows[i].Cells[UnitCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgvMaterial.Rows[i].Cells[UnitCell];
                 try
                 {
                     pkgBoxCell.Value = productionRequestDetailInMaterials[i].UnitId;
                 }
                 catch { }
             }
         }
     }
 }
 private void dgvProduct_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     DataGridView dgv = (DataGridView)sender;
     if (productionRequestDetailInProductions == null)
     {
         productionRequestDetailInProductions = new BindingList<ProductionRequestDetail>();
     }
     if (productionRequestDetailInProductions.Count < dgvProduct.RowCount - 1)
     {
         ProductionRequestDetail productionRequestDetail = new ProductionRequestDetail();
         productionRequestDetailInProductions.Add(productionRequestDetail);
     }
     if (dgv.CurrentCell.Value != null)
     {
         switch (e.ColumnIndex)
         {
             case ProductAttrCell:
                 {
                     ProductAttributeService productAttrService = new ProductAttributeService();
                     ProductAttribute pa = productAttrService.GetProductAttribute((int)dgv.CurrentCell.Value);
                     if (pa != null)
                     {
                         productionRequestDetailInProductions[e.RowIndex].ProductId = pa.ProductId;
                         productionRequestDetailInProductions[e.RowIndex].AttributeId = pa.AttributeId;
                     }
                 } break;
             case NumberUnitCell:
                 productionRequestDetailInProductions[e.RowIndex].NumberUnit = (int)dgv.CurrentCell.Value;
                 break;
             case UnitCell:
                 productionRequestDetailInProductions[e.RowIndex].UnitId = (int)dgv.CurrentCell.Value;
                 break;
             case NoteCell:
                 productionRequestDetailInProductions[e.RowIndex].Note = (string)dgv.CurrentCell.Value;
                 break;
         }
     }
 }
        private void loadSomeData()
        {
            if (productionRequest != null)
            {
                txtDate.Text = productionRequest.CreatedDate.ToString(BHConstant.DATE_FORMAT);
                txtDate.Enabled = false;
                txtUser.Text = productionRequest.SystemUser.FullName;
                txtUser.Enabled = false;
                txtNote.Text = productionRequest.Note;
                txtCode.Text = productionRequest.ReqCode;
            }
            else
            {
                txtDate.Text = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate().ToString(BHConstant.DATE_FORMAT);
                txtDate.Enabled = false;
                txtUser.Text = (Global.CurrentUser != null) ? Global.CurrentUser.FullName : "";
                txtUser.Enabled = false;

                txtCode.Text = Global.GetTempSeedID(BHConstant.PREFIX_FOR_PRODUCTION);
            }
            ProductAttributeService productAttrService = new ProductAttributeService();
            productForProducts = new BindingList<ProductAttributeModel>(productAttrService.GetProductAndAttribute());
            units = new BindingList<MeasurementUnit>(unitService.GetMeasurementUnits());
        }
 private void dgwOrderDetails_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     DataGridView dgv = (DataGridView)sender;
     if (orderDetails == null)
     {
         orderDetails = new BindingList<OrderDetail>();
     }
     if (orderDetails.Count < dgwOrderDetails.RowCount - 1)
     {
         OrderDetail orderDetail = new OrderDetail();
         orderDetails.Add(orderDetail);
     }
     if (dgv.CurrentCell.Value != null)
     {
         switch (e.ColumnIndex)
         {
             case ProductAttrCell:
                 {
                     ProductAttributeService productAttrService = new ProductAttributeService();
                     ProductAttribute pa = productAttrService.GetProductAttribute((int)dgv.CurrentCell.Value);
                     if (pa != null)
                     {
                         orderDetails[e.RowIndex].ProductId = pa.ProductId;
                         orderDetails[e.RowIndex].AttributeId = pa.AttributeId;
                     }
                 } break;
             case PriceCell:
                 {
                     double price = 0;
                     try
                     {
                         price = (double)dgv.CurrentCell.Value;
                         if (price < 0)
                             price = 0;
                     }
                     catch { price = 0; }
                     orderDetails[e.RowIndex].Price = price;
                     dgv.CurrentCell.ToolTipText = Global.formatVNDCurrencyText(price.ToString());
                 } break;
             case CommissionCell:
                 {
                     double commission = 0;
                     try
                     {
                         commission = (double)dgv.CurrentCell.Value;
                         if (commission < 0)
                             commission = 0;
                     }
                     catch { commission = 0; }
                     orderDetails[e.RowIndex].Commission = commission;
                     dgv.CurrentCell.ToolTipText = Global.formatVNDCurrencyText(commission.ToString());
                 } break;
             case TotalCell:
                 {
                     dgv.CurrentCell.ToolTipText = Global.formatVNDCurrencyText(orderDetails[e.RowIndex].Cost.ToString());
                 } break;
             case NoteCell:
                 {
                     orderDetails[e.RowIndex].Note = (string)dgv.CurrentCell.Value;
                 } break;
             default:
                 break;
         }
     }
     calculateNumberUnit(dgv, e.RowIndex, e.ColumnIndex);
     calculateTotal();
     orderDetails[e.RowIndex].Cost = (int)dgwOrderDetails.Rows[e.RowIndex].Cells[NumberUnitCell].Value
         * (double)dgwOrderDetails.Rows[e.RowIndex].Cells[PriceCell].Value;
     dgwOrderDetails.Rows[e.RowIndex].Cells[TotalCell].ToolTipText = Global.formatVNDCurrencyText(orderDetails[e.RowIndex].Cost.ToString());
 }
 private void dgvStockEntranceDetails_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     DataGridView dgv = (DataGridView)sender;
     if (entranceStockDetails == null)
     {
         entranceStockDetails = new BindingList<EntranceStockDetail>();
     }
     if (entranceStockDetails.Count < dgvStockEntranceDetails.RowCount - 1)
     {
         EntranceStockDetail entranceStockDetail = new EntranceStockDetail();
         entranceStockDetails.Add(entranceStockDetail);
     }
     if (dgv.CurrentCell.Value != null)
     {
         switch (e.ColumnIndex)
         {
             case ProductAttrCell:
                 {
                     ProductAttributeService productAttrService = new ProductAttributeService();
                     ProductAttribute pa = productAttrService.GetProductAttribute((int)dgv.CurrentCell.Value);
                     if (pa != null)
                     {
                         entranceStockDetails[e.RowIndex].ProductId = pa.ProductId;
                         entranceStockDetails[e.RowIndex].AttributeId = pa.AttributeId;
                     }
                 } break;
             case NumberUnitCell:
                 {
                     int value = (int)dgv.CurrentCell.Value;
                     if (value < 0)
                         entranceStockDetails[e.RowIndex].NumberUnit = 0;
                     else
                         entranceStockDetails[e.RowIndex].NumberUnit = value;
                 } break;
             case UnitCell:
                 entranceStockDetails[e.RowIndex].UnitId = (int)dgv.CurrentCell.Value;
                 break;
             case NoteCell:
                 entranceStockDetails[e.RowIndex].Note = (string)dgv.CurrentCell.Value;
                 break;
         }
     }
 }
 public void updateProductionRequestDetailCells()
 {
     if (isUpdating && entranceStock != null && entranceStockDetails.Count < dgvStockEntranceDetails.RowCount)
     {
         ProductAttributeService productAttrService = new ProductAttributeService();
         for (int i = 0; i < entranceStockDetails.Count; i++)
         {
             // Product + Attribute
             if (dgvStockEntranceDetails.Rows[i].Cells[ProductAttrCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgvStockEntranceDetails.Rows[i].Cells[ProductAttrCell];
                 try
                 {
                     pkgBoxCell.Value = productAttrService.GetProductAttribute(entranceStockDetails[i].ProductId,
                         entranceStockDetails[i].AttributeId).Id;
                 }
                 catch { }
             }
             // Unit
             if (dgvStockEntranceDetails.Rows[i].Cells[UnitCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgvStockEntranceDetails.Rows[i].Cells[UnitCell];
                 try
                 {
                     pkgBoxCell.Value = entranceStockDetails[i].UnitId;
                 }
                 catch { }
             }
         }
     }
 }
Exemple #22
0
        private static void CreateIndex(List <ProductInfo> list)
        {
            IProductShopCategoryInfo shopBll    = new ProductShopCategoryService();
            IFreightTemplate         freBll     = new FreightTemplateService();
            IProductInfo             pBll       = new ProductInfoService();
            IProductAttributeInfo    proAttrBll = new ProductAttributeService();
            IAttributeValueInfo      attrBll    = new AttributeValueService();
            string indexpath = ConfigurationManager.AppSettings["Indexpath"];
            IProductDescriptionInfo desBll = new ProductDescriptionInfoService();
            IBrandInfo braBll = new BrandInfoService();

            FSDirectory directory = FSDirectory.Open(new DirectoryInfo(indexpath), new NativeFSLockFactory());
            //IndexReader:对索引库进行读取的类
            bool isExist = IndexReader.IndexExists(directory);  //是否存在索引库文件夹以及索引库特征文件

            if (isExist)
            {
                //如果索引目录被锁定(比如索引过程中程序异常退出或另一进程在操作索引库),则解锁
                //Q:存在问题 如果一个用户正在对索引库写操作 此时是上锁的 而另一个用户过来操作时 将锁解开了 于是产生冲突 --解决方法后续
                if (IndexWriter.IsLocked(directory))
                {
                    IndexWriter.Unlock(directory);
                }
            }

            IndexWriter writer = new IndexWriter(directory, new PanGuAnalyzer(), !isExist, IndexWriter.MaxFieldLength.UNLIMITED);

            try
            {
                foreach (var pitem in list)
                {
                    string shopcategoryid = "";
                    List <ProductShopCategoryInfo> shoplist = new List <ProductShopCategoryInfo>();
                    shoplist = shopBll.SearchbyProid(pitem.Id.ToString());
                    foreach (var shopitem in shoplist)
                    {
                        shopcategoryid += shopitem.ShopCategoryId.ToString() + ",";
                    }
                    FreightTemplateInfo freinfo = new FreightTemplateInfo();
                    freinfo = freBll.SearchByid(pitem.FreightTemplateId.ToString());

                    List <ProductAttributeInfo> attrlist = new List <ProductAttributeInfo>();
                    string proattr = ",";
                    string attrval = "";
                    string attr    = "";
                    attrlist = proAttrBll.SearchByproductid(pitem.Id.ToString());     //产品属性
                    foreach (var attitem in attrlist)
                    {
                        proattr += attitem.ValueId + ","; //属性ID用于精确查找
                        attr     = attrBll.GetAttributeValueById(attitem.ValueId);
                        attrval += attr + ",";            //属性值用于模糊查询
                    }
                    string desinfo = "";
                    desinfo = desBll.GetByProductId(pitem.Id);  //产品描述  用于模糊查询

                    string brand = "";
                    brand    = braBll.GetNameById(pitem.BrandId); //品牌名字  用于模糊查询
                    attrval += brand;                             //品牌属性

                    Document document    = new Document();
                    Field    id          = new Field("Id", pitem.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED);                                             //商品ID
                    Field    ProductName = new Field("ProductName", pitem.ProductName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); //商品名称
                    ProductName.SetBoost(0.5f);
                    //Field BrandName = new Field("BrandName", brand, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);   //品牌名字
                    Field Description = new Field("Description", desinfo, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);           //描述
                    Description.SetBoost(0.15f);
                    Field BrandAttribution = new Field("BrandAttribution", attrval, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); //品牌属性
                    BrandAttribution.SetBoost(0.35f);

                    Field        AuditStatus       = new Field("AuditStatus", pitem.AuditStatus.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); //
                    Field        SaleStatus        = new Field("SaleStatus", pitem.SaleStatus.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);   //销售状态
                    NumericField ShopId            = new NumericField("ShopId", Field.Store.YES, true).SetLongValue(pitem.ShopId);                                                           //商家ID
                    Field        CategoryPath      = new Field("CategoryPath", pitem.CategoryPath, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);          //分类路径
                    NumericField CategoryId        = new NumericField("CategoryId", Field.Store.YES, true).SetLongValue(pitem.CategoryId);                                                   //分类ID
                    NumericField BrandId           = new NumericField("BrandId", Field.Store.YES, true).SetLongValue(pitem.BrandId);                                                         //品牌ID
                    NumericField MinSalePrice      = new NumericField("MinSalePrice", Field.Store.YES, true).SetDoubleValue(Convert.ToDouble(pitem.MinSalePrice));                           //价格
                    NumericField SaleCounts        = new NumericField("SaleCounts", Field.Store.YES, true).SetLongValue(pitem.SaleCounts);                                                   //销售数量
                    NumericField AddedDate         = new NumericField("AddedDate", Field.Store.YES, true).SetLongValue(pitem.AddedDate.Ticks);                                               //商品上架时间
                    Field        FreightTemplateId = new Field("FreightTemplateId", pitem.FreightTemplateId.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
                    Field        Shopcategoryid    = new Field("Shopcategoryid", shopcategoryid, Field.Store.YES, Field.Index.NOT_ANALYZED);                                                 //商家分类ID
                    Field        ProductAttribute  = new Field("ProductAttribute", proattr, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);                 //商品属性
                    Field        ProductImage      = new Field("ProductImage", string.IsNullOrEmpty(pitem.ImagePath) ? "未知" : pitem.ImagePath, Field.Store.YES, Field.Index.NOT_ANALYZED);
                    Field        SaleUnit          = new Field("SaleUnit", string.IsNullOrEmpty(pitem.MeasureUnit) ? "未知" : pitem.MeasureUnit, Field.Store.YES, Field.Index.NOT_ANALYZED);   //销售单位

                    int SourceAddress = 0;
                    if (freinfo.SourceAddress != null)
                    {
                        SourceAddress = (int)freinfo.SourceAddress;
                    }
                    NumericField AddressId  = new NumericField("AddressId", Field.Store.YES, true).SetIntValue(SourceAddress); //地区ID
                    int          commentnum = pBll.SearchComments(pitem.Id.ToString());
                    NumericField CommentNum = new NumericField("CommentNum", Field.Store.YES, true).SetIntValue(commentnum);   //评论数
                    document.Add(id);
                    document.Add(ProductName);
                    //document.Add(BrandName);
                    document.Add(Description);
                    document.Add(BrandAttribution);
                    document.Add(AuditStatus);
                    document.Add(SaleStatus);
                    document.Add(ShopId);
                    document.Add(CategoryPath);
                    document.Add(CategoryId);
                    document.Add(BrandId);
                    document.Add(MinSalePrice);
                    document.Add(SaleCounts);
                    document.Add(AddedDate);
                    document.Add(FreightTemplateId);
                    document.Add(Shopcategoryid);
                    document.Add(ProductAttribute);
                    document.Add(ProductImage);
                    document.Add(SaleUnit);
                    document.Add(AddressId);
                    document.Add(CommentNum);
                    writer.AddDocument(document);  //文档写入索引库
                }
                writer.Optimize();
                writer.Close();      //会自动解锁
                directory.Close();   //不要忘了Close,否则索引结果搜不到
            }
            catch (Exception ex)
            {
                Utility.writelog("创建索引出问题:" + ex + "");
            }
        }
        public JsonResult OnDelete(int id)
        {
            var result = ProductAttributeService.Delete(id);

            return(Json(new { code = result }));
        }
Exemple #24
0
        public ActionResult OnCreate(ProductModels product)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(product.Code))
                {
                    product.Code = string.Format("{0}-{1}", ConfigHelper.ProductCode, DateTime.Now.Ticks.GetHashCode());
                }
                product.ImageUrl = product.Image != null?
                                   product.Image.Upload() :
                                       product.ImageUrl;

                var newProduct = new Product
                {
                    Name         = product.Name,
                    Type         = product.CategoryId,
                    Summary      = product.Summary,
                    Code         = product.Code,
                    Image        = product.ImageUrl,
                    BrandId      = product.BrandId,
                    Country      = product.Country,
                    Store        = product.Store,
                    Manufacturer = product.ManufacturerId,
                    AccountId    = 0,
                    Number       = product.Number,
                    Unit1        = product.Unit,
                    Weight       = product.Weight,
                    Quantity     = product.Quantity,
                    Npp          = Convert.ToDouble(product.Npp),
                    Width        = product.Width,
                    Height       = product.Height,
                    Depth        = product.Depth,
                    Detail       = product.Detail,
                    WarrantyTime = product.WarrantyTime,
                    ExpireDate   = product.ExpireDate,
                    Title        = product.MetaTitle,
                    Keyword      = product.MetaKeyword,
                    Description  = product.MetaDescription,
                    Price        = product.Price,
                    Transport1   = product.Transport1,
                    Transport2   = product.Transport2,
                    Status       = false
                };
                var result = ProductService.Insert(newProduct);

                //Tao cac anh Slide va properties
                if (product.ProductImages != null && product.ProductImages.Length > 0)
                {
                    ProductImageService.Insert(newProduct.ID, product.Name, product.ProductImages);
                }
                //Tao cac gia tri thuoc tinh
                if (product.AttrLabel != null && product.AttrLabel.Length > 0)
                {
                    ProductAttributeService.Insert(newProduct.ID, product.AttrLabel, product.AttrDesc);
                }
                //Tao saleOff
                if (!string.IsNullOrWhiteSpace(product.Percent))
                {
                    ProductSaleOffService.Insert(new ProductSaleOff
                    {
                        ProductID = newProduct.ID,
                        Percent   = Convert.ToDouble(product.Percent),
                        StartTime = Convert.ToDateTime(product.StartDate),
                        EndTime   = Convert.ToDateTime(product.EndDate)
                    });
                }
                //Tao kich co
                if (product.Size != null && product.Size.Length > 0)
                {
                    ProductSizeService.Insert(newProduct.ID, product.Size);
                }
                //Tao mau sac
                if (product.Color != null && product.Color.Length > 0)
                {
                    ProductColorService.Insert(newProduct.ID, product.Color);
                }
                SetFlashMessage(result == Result.Ok?
                                $"Thêm sản phẩm '{product.Name}' thành công.":
                                "Lỗi khi thêm mới sản phẩm");
                if (product.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListCategory     = BuildListCategory();
                ViewBag.ListBrand        = ProductBrandService.GetAll();
                ViewBag.ListCountry      = CountryService.GetAll();
                ViewBag.ListStore        = ProductStoreService.GetAll();
                ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
                ViewBag.ListUnit         = UnitService.GetAll();
                ViewBag.ListColor        = BuildListColor(product.Color);
                ViewBag.ListSize         = BuildListSize(product.Size);
                ViewBag.ListHour         = DataHelper.ListHour;
                ModelState.Clear();
                return(View("Create", product.ResetValue()));
            }
            ViewBag.ListCategory     = BuildListCategory();
            ViewBag.ListBrand        = ProductBrandService.GetAll();
            ViewBag.ListCountry      = CountryService.GetAll();
            ViewBag.ListStore        = ProductStoreService.GetAll();
            ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
            ViewBag.ListUnit         = UnitService.GetAll();
            ViewBag.ListColor        = BuildListColor(product.Color);
            ViewBag.ListSize         = BuildListSize(product.Size);
            ViewBag.ListHour         = DataHelper.ListHour;

            return(View("Create", product));
        }
        private bool UpdateAttribute(long newProductId)
        {
            DataGridViewRowCollection selectedRows = dgvBaseAttributes.Rows;
            ProductAttributeService productAttributeService = new ProductAttributeService();

            bool result = true;
            List<int> newAttr = new List<int>();
            List<int> addAttr, removeAttr;

            foreach (DataGridViewRow dgv in selectedRows)
            {
                DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dgv.Cells[0];
                if (checkbox.Value != null &&
                    (checkbox.Value.ToString().Equals(bool.TrueString) || checkbox.Value.ToString().Equals("1")))
                {
                    newAttr.Add(((BaseAttribute)dgv.DataBoundItem).Id);
                }
            }

            addAttr = newAttr.Except(oldAttr).ToList();
            removeAttr = oldAttr.Except(newAttr).ToList();

            foreach (int add in addAttr)
            {
                ProductAttribute pa = new ProductAttribute()
                {
                    ProductId = (int)newProductId,
                    AttributeId = add
                };
                result = productAttributeService.AddProductAttribute(pa);
            }

            foreach (int remove in removeAttr)
            {
                int removeId = -1;
                using (BaoHienDBDataContext context = new BaoHienDBDataContext(SettingManager.BuildStringConnection()))
                {
                    ProductAttribute pa = context.ProductAttributes
                        .Where(p => p.AttributeId == remove && p.ProductId == (int)newProductId).SingleOrDefault();
                    if (pa != null)
                        removeId = pa.Id;
                }
                if (removeId != -1)
                    result = productAttributeService.DeleteProductAttribute(removeId);
            }
            BaoHienRepository.ResetDBDataContext();
            return result;
        }
        private void loadSomeData()
        {
            if(customers == null)
            {
                CustomerService customerService = new CustomerService();
                customers = new BindingList<Customer>(customerService.GetCustomers().OrderBy(x => x.CustCode).ToList());
                customers.Insert(0, new Customer() { Id = 0, CustCode = "", CustomerName = ""});
            }
            if (customers != null)
            {
                cbxCustomer.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                cbxCustomer.AutoCompleteSource = AutoCompleteSource.ListItems;

                cbxCustomer.DataSource = customers;
                cbxCustomer.DisplayMember = "CustCode";
                cbxCustomer.ValueMember = "Id";
            }
            ProductAttributeService productAttrService = new ProductAttributeService();
            productAttrs = new BindingList<ProductAttributeModel>(productAttrService.GetProductAndAttribute());
            units = new BindingList<MeasurementUnit>(unitService.GetMeasurementUnits());
            if (order != null)
            {
                if (customers != null)
                {
                    cbxCustomer.SelectedIndex = customers.ToList().FindIndex(cus => cus.Id == order.CustId);
                }
                txtDiscount.WorkingText = order.Discount.HasValue ? order.Discount.Value.ToString() : "";
                txtNote.Text = order.Note;
                txtVAT.WorkingText = order.VAT.HasValue ? order.VAT.Value.ToString() : "";
                txtOrderCode.Text = order.OrderCode;
                txtCreatedDate.Text = order.CreatedDate.ToString(BHConstant.DATE_FORMAT);

                txtVAT.Text = Global.formatVNDCurrencyText(txtVAT.WorkingText);
                txtDiscount.Text = Global.formatVNDCurrencyText(txtDiscount.WorkingText);
                txtWare.Text = order.WareHouse;
                txtReason.Text = order.Reason;
            }
            else
            {
                txtCreatedDate.Text = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate().ToString(BHConstant.DATE_FORMAT);
                txtOrderCode.Text = Global.GetTempSeedID(BHConstant.PREFIX_FOR_ORDER);
            }
        }
 public void updateProductionRequestDetailCells()
 {
     if (isUpdating && order != null && orderDetails.Count < dgwOrderDetails.RowCount)
     {
         ProductAttributeService productAttrService = new ProductAttributeService();
         for (int i = 0; i < orderDetails.Count; i++)
         {
             if (dgwOrderDetails.Rows[i].Cells[ProductAttrCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgwOrderDetails.Rows[i].Cells[ProductAttrCell];
                 try
                 {
                     pkgBoxCell.Value = productAttrService.GetProductAttribute(orderDetails[i].ProductId, orderDetails[i].AttributeId).Id;
                 }
                 catch { }
             }
             // Unit
             if (dgwOrderDetails.Rows[i].Cells[UnitCell] is DataGridViewComboBoxCell)
             {
                 DataGridViewComboBoxCell pkgBoxCell = (DataGridViewComboBoxCell)dgwOrderDetails.Rows[i].Cells[UnitCell];
                 try
                 {
                     pkgBoxCell.Value = orderDetails[i].UnitId;
                 }
                 catch { }
             }
         }
     }            
 }
 private void btnCreateSP_Click(object sender, EventArgs e)
 {
     AddProduct frmProduct = new AddProduct();
     if (frmProduct.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         ProductAttributeService productAttrService = new ProductAttributeService();
         products = new BindingList<ProductAttributeModel>(productAttrService.GetProductAndAttribute());
         ((DataGridViewComboBoxColumn)dgvStockEntranceDetails.Columns[0]).DataSource = products;
     }
 }
Exemple #29
0
        public ActionResult OnEdit(ProductModels product)
        {
            var productUpdate = ProductService.Find(product.Id);

            if (productUpdate != null)
            {
                if (string.IsNullOrWhiteSpace(product.Code))
                {
                    product.Code = $"MP-{DateTime.Now.Ticks.GetHashCode()}";
                }
                product.ImageUrl = product.Image != null?
                                   product.Image.Upload() :
                                       product.ImageUrl.ToImageOriginalPath();

                productUpdate.Name         = product.Name;
                productUpdate.Type         = product.CategoryId;
                productUpdate.Summary      = product.Summary;
                productUpdate.Code         = product.Code;
                productUpdate.Image        = product.ImageUrl;
                productUpdate.BrandId      = product.BrandId;
                productUpdate.Country      = product.Country;
                productUpdate.Store        = product.Store;
                productUpdate.Manufacturer = product.ManufacturerId;
                productUpdate.AccountId    = product.AccountId;
                productUpdate.Number       = product.Number;
                productUpdate.Unit1        = product.Unit;
                productUpdate.Weight       = product.Weight;
                productUpdate.Quantity     = product.Quantity;
                productUpdate.Npp          = Convert.ToDouble(product.Npp);
                productUpdate.Width        = product.Width;
                productUpdate.Height       = product.Height;
                productUpdate.Depth        = product.Depth;
                productUpdate.Detail       = product.Detail;
                productUpdate.WarrantyTime = product.WarrantyTime;
                productUpdate.ExpireDate   = product.ExpireDate;
                productUpdate.Title        = product.MetaTitle;
                productUpdate.Keyword      = product.MetaKeyword;
                productUpdate.Description  = product.MetaDescription;
                productUpdate.Price        = product.Price;
                productUpdate.Transport1   = product.Transport1;
                productUpdate.Transport2   = product.Transport2;
                var result = ProductService.Update(productUpdate);
                //Tao cac anh san pham
                if (product.ProductImages != null && product.ProductImages.Length > 0)
                {
                    ProductImageService.Insert(productUpdate.ID, product.Name, product.ProductImages);
                }
                //Tao cac gia tri thuoc tinh
                if (product.AttrLabel != null && product.AttrLabel.Length > 0)
                {
                    ProductAttributeService.Insert(productUpdate.ID, product.AttrLabel, product.AttrDesc);
                }
                //Tao saleOff
                if (!string.IsNullOrWhiteSpace(product.Percent))
                {
                    ProductSaleOffService.Insert(new ProductSaleOff
                    {
                        ProductID = productUpdate.ID,
                        Percent   = Convert.ToDouble(product.Percent),
                        StartTime = Convert.ToDateTime(product.StartDate),
                        EndTime   = Convert.ToDateTime(product.EndDate)
                    });
                }
                //Tao kich co
                if (product.Size != null && product.Size.Length > 0)
                {
                    ProductSizeService.Insert(productUpdate.ID, product.Size);
                }
                //Tao mau sac
                if (product.Color != null && product.Color.Length > 0)
                {
                    ProductColorService.Insert(productUpdate.ID, product.Color);
                }

                SetFlashMessage(result == Result.Ok?
                                $"Cập nhật sản phẩm '{product.Name}' thành công.":
                                "Lỗi khi cập nhật sản phẩm '{product.Name}'"
                                );
                if (product.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListCategory     = BuildListCategory();
                ViewBag.ListBrand        = ProductBrandService.GetAll();
                ViewBag.ListCountry      = CountryService.GetAll();
                ViewBag.ListStore        = ProductStoreService.GetAll();
                ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
                ViewBag.ListUnit         = UnitService.GetAll();
                ViewBag.ListColor        = BuildListColor(product.Color);
                ViewBag.ListSize         = BuildListSize(product.Size);
                ViewBag.ListHour         = DataHelper.ListHour;
                return(View("Edit", product));
            }
            ViewBag.ListBrand        = ProductBrandService.GetAll();
            ViewBag.ListCountry      = CountryService.GetAll();
            ViewBag.ListStore        = ProductStoreService.GetAll();
            ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
            ViewBag.ListUnit         = UnitService.GetAll();
            ViewBag.ListColor        = BuildListColor(product.Color);
            ViewBag.ListSize         = BuildListSize(product.Size);
            ViewBag.ListHour         = DataHelper.ListHour;
            return(View("Edit", product));
        }
        private void dgvProductAttributeList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (sender is DataGridView)
            {
                DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
                if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn xóa Quy cách sản phẩm này?",
                    "Xoá Quy cách sản phẩm này",
                     MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        DataGridViewRow currentRow = dgvProductAttributeList.Rows[e.RowIndex];
                        BaseAttributeService baseAttributeService = new BaseAttributeService();
                        int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id");
                        ProductAttributeService productAttributeService = new ProductAttributeService();
                        List<ProductAttribute> productList = productAttributeService.SelectProductAttributeByWhere(x => x.AttributeId == id);
                        if (productList.Count > 0)
                        {
                            MessageBox.Show("Quy cách sản phẩm này đang được sử dụng. Không xóa được!");
                        }
                        else
                        {
                            if (!baseAttributeService.DeleteBaseAttribute(id))
                            {
                                MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            loadProductAttributeList();
                        }
                    }

                }

            }
        }