コード例 #1
0
        //delete button pressed for product supplier tab
        private void btnDeleteProductSupplier_Click(object sender, EventArgs e)
        {
            //showing yes or no message box to give user choice
            DialogResult     result          = MessageBox.Show("Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            Product_Supplier productSupplier = productSuppliers[product_SupplierDataGridView.CurrentCell.RowIndex];

            //SelectRowProducts_Suppliers(); //delete later
            if (result == DialogResult.Yes)
            {
                try
                {
                    if (!Product_SupplierDB.DeleteProduct_Supplier(productSupplier)) //if database delete was not sucessful
                    {
                        MessageBox.Show("Another user has updated or deleted this product supplier information", "Datebase Error");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
            this.DisplayProductSupplier();
            this.DisplayPackages();
            this.DisplayPackageProdSup();
        }
コード例 #2
0
 //get the product supplier selected by the user.
 private void dgvProdSups_SelectionChanged(object sender, EventArgs e)
 {
     if (dgvProdSups.SelectedRows.Count != 0)
     {
         selectedProductSupplier = (Product_Supplier)dgvProdSups.SelectedRows[0].DataBoundItem;
     }
 }
コード例 #3
0
        public ActionResult Index(Product product)
        {
            try
            {
                ProductTableData.updateProduct(product.ID, (int)product.Quantity_Available, (int)product.Unit_Price, (int)product.Selling_Price, product.Barcodes.ToArray(), product.Unique_Barcode, DateTime.Now);

                Supplier supplier = SupplierTableData.getSupplier(product.Model);//supplier name is saved in product model

                Product_Supplier product_Supplier = new Product_Supplier()
                {
                    Date = DateTime.Now, Quantity = product.Quantity_Available, Supplier = supplier, Ref_Number = product.Type, Product_ID = product.ID, Unit_Price = product.Unit_Price
                };

                Journal journal = new Journal();
                journal.Date            = product.Date_Updated;
                journal.Sub_Account_ID  = 10; ///purchase account
                journal.Type            = 0;  /// 0 means Debit
                journal.Status          = 1;  ///posted
                journal.PreparedBy      = 1;
                journal.AuthenticatedBy = 1;
                //Product_SupplierTableData.addNewProduct_Supplier()
                return(Json(new
                {
                    msg = "Successfully added " + product.ID + " " +
                          product.Quantity_Available + " " +
                          product.Selling_Price + " " +
                          product.Barcodes.First().Barcode_Serial
                }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
        public static bool AddPS(int pid, int sid)
        {
            SqlConnection    connection = TravelExpertsDB.GetConnection();
            Product_Supplier result     = new Product_Supplier();
            int rowAffected             = 0;

            try
            {
                string sql = "INSERT INTO Products_Suppliers (ProductId, " +
                             " SupplierId) " +
                             " VALUES (@pid, @sid);";
                SqlCommand command = new SqlCommand(sql, connection);

                command.Parameters.AddWithValue("@pid", pid);
                command.Parameters.AddWithValue("@sid", sid);
                rowAffected = command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
            if (rowAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
        public static List <Product_Supplier> GetProducts_Suppliers()
        {
            SqlConnection           connection = TravelExpertsDB.GetConnection();
            List <Product_Supplier> results    = new List <Product_Supplier>();

            try
            {
                string sql = "SELECT ProductSupplierID, ProductId, " +
                             " SupplierId FROM Products_Suppliers";
                SqlCommand    command = new SqlCommand(sql, connection);
                SqlDataReader reader  =
                    command.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    Product_Supplier s = new Product_Supplier();

                    s.ProductSupplierId = Convert.ToInt32(reader["ProductSupplierId"]);
                    s.ProductId         = Convert.ToInt32(reader["ProductId"]);
                    s.SupplierId        = Convert.ToInt32(reader["SupplierId"]);
                    results.Add(s);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
            return(results);
        }
コード例 #6
0
        public static bool UpdatePS(int psid, int pid, int sid)
        {
            SqlConnection    connection = TravelExpertsDB.GetConnection();
            Product_Supplier result     = new Product_Supplier();
            int rowAffected             = 0;

            try
            {
                string sql = "UPDATE Products_Suppliers SET ProductId=@pid," +
                             " SupplierId=@sid " +
                             " WHERE ProductSupplierId=@psid";
                SqlCommand command = new SqlCommand(sql, connection);

                command.Parameters.AddWithValue("@psid", psid);
                command.Parameters.AddWithValue("@pid", pid);
                command.Parameters.AddWithValue("@sid", sid);
                rowAffected = command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
            if (rowAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #7
0
        /// <summary>
        /// Set product supplier
        /// </summary>
        /// <param name="product_id">Product ID</param>
        /// <param name="supplier_id">Supplier ID</param>
        /// <returns>TRUE/FALSE</returns>
        public bool SetProductSupplier(int product_id, int supplier_id)
        {
            bool result = false;

            if (this.CurrentUserPermission.ADD_SUPPLIER == 0)
            {
                throw new KMJXCException("没有创建供应商的权限");
            }

            if (product_id == 0 || supplier_id == 0)
            {
                throw new KMJXCException("创建产品供应商时,产品和供应商都必须选择");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Product_Supplier pps = (from p in db.Product_Supplier where p.Product_ID == product_id && p.Supplier_ID == supplier_id select p).FirstOrDefault <Product_Supplier>();
                if (pps != null)
                {
                    throw new KMJXCException("");
                }
                Product_Supplier ps = new Product_Supplier();
                ps.Product_ID  = product_id;
                ps.Supplier_ID = supplier_id;
                db.Product_Supplier.Add(ps);
                db.SaveChanges();
                result = true;
            }
            return(result);
        }
コード例 #8
0
        // creates a Product_Supplier obbject from the selected indices of each datagrid
        private Product_Supplier createProductSupplier()
        {
            Product_Supplier newProdSup = new Product_Supplier();

            newProdSup.ProductId   = ActiveProduct.ProductId;
            newProdSup.ProductName = ActiveProduct.ProdName;
            newProdSup.SupName     = activeSupplier.SupName;
            newProdSup.SupplierId  = activeSupplier.SupplierID;
            return(newProdSup);
        }
コード例 #9
0
        //checks if the product supplier the user wants to add exists.
        public bool ProdSupDoesNotExist(Product_Supplier newPS)
        {
            var prodSups = productSuppliers.Where <Product_Supplier>(x => x.ProductName == newPS.ProductName && x.SupName == newPS.SupName);

            if (prodSups.Count() == 0)
            {
                return(true);
            }

            return(false);
        }
コード例 #10
0
 private void cbProductSuppliers_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cbProductSuppliers.SelectedItem != null)
     {
         selectedProductSupplier = (Product_Supplier)cbProductSuppliers.SelectedItem;
         txtSearch.Text          = (selectedProductSupplier.ToString() == null) ? "" : selectedProductSupplier.ToString();
         if (cbProductSuppliers.DroppedDown != false)
         {
             cbProductSuppliers.DroppedDown = false;
         }
     }
 }
コード例 #11
0
        //modify button pressed in products supplier tab
        private void btnModifyProductSupplier_Click(object sender, EventArgs e)
        {
            Product_Supplier productSupplier = productSuppliers[product_SupplierDataGridView.CurrentCell.RowIndex];
            //SelectRowProducts_Suppliers(); //delete later
            AddModifyProductsSupplier modifyProductsSupplier = new AddModifyProductsSupplier();

            modifyProductsSupplier.addProductSupplier = false;
            modifyProductsSupplier.productSupplier    = productSupplier; //making productSupplier in add modify form equal to the productSupplier in main form
            DialogResult result = modifyProductsSupplier.ShowDialog();   //show add modify products supplier form

            this.DisplayProductSupplier();
            this.DisplayPackages();
            this.DisplayPackageProdSup();
        }
コード例 #12
0
        //add button clicked in prodcuts supplier tab
        private void btnAddProductSupplier_Click(object sender, EventArgs e)
        {
            AddModifyProductsSupplier addProductsSupplier = new AddModifyProductsSupplier();

            addProductsSupplier.addProductSupplier = true;
            DialogResult result = addProductsSupplier.ShowDialog(); //showing add modify from for product supplier

            if (result == DialogResult.OK)                          // if user clicks accept
            {
                productSupplier = addProductsSupplier.productSupplier;
                this.DisplayProductSupplier();
                this.DisplayPackages();
                this.DisplayPackageProdSup();
            }
        }
コード例 #13
0
 //Creates a new product-supplier from the selections of the first two datagrid views, the
 private void btnCreateProdSup_Click(object sender, EventArgs e)
 {
     if (ActiveProduct != null && activeSupplier != null)
     {
         Product_Supplier newProdSup = createProductSupplier();
         if (ProdSupDoesNotExist(newProdSup))
         {
             newProdSup.ProductSupplierId = TravelExpertsDB.TravelExpertsDB.AddProduct_Supplier(newProdSup);
             MessageBox.Show("Added " + newProdSup);
             fillDGVs();
         }
         else
         {
             MessageBox.Show(newProdSup + " already exists and was not added.");
         }
     }
 }
コード例 #14
0
ファイル: Form2.cs プロジェクト: arielfc/TravelExperts
        private void button2_Click(object sender, EventArgs e)
        {
            string s1 = products[listBox1.SelectedIndex].ProdName.ToString();
            string s2 = sList[listBox2.SelectedIndex].SupName.ToString();

            list3.Add(s1 + " - " + s2);
            listBox3.DataSource    = null;
            listBox3.DataSource    = list3;
            listBox3.SelectedIndex = listBox3.Items.Count - 1;

            // Prepare for DB
            Product_Supplier nps = new Product_Supplier();

            nps.ProductId  = products[listBox1.SelectedIndex].ProductId;
            nps.SupplierId = sList[listBox2.SelectedIndex].SupplierId;
            list3_ToDB.Add(nps);
        }
コード例 #15
0
        public static bool addNewProduct_Supplier(Product_Supplier pro_supplier)
        {
            try
            {
                db.Product_Supplier.Add(pro_supplier);
                //db.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                ///throw new Exception(ex.Message + "Detailed Error: " + ex.StackTrace);
                CustomMessage.Message    = ex.Message;
                CustomMessage.StackTrace = ex.StackTrace;

                return(false);
            }
        }
コード例 #16
0
        /// <summary>
        ///
        /// </summary>

        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (ValidData())           //making sure data is valid
            {
                if (addPackageProdSup) // if user clciked the add button
                {
                    productSupplier = new Product_Supplier();
                    this.ProductSupplierData(productSupplier);
                    try
                    {
                        productSupplier.ProductSupplierID = Product_SupplierDB.AddProduct_Supplier(productSupplier);
                        Packages_Products_SuppliersDB.Add(productSupplier, package);
                        this.DialogResult = DialogResult.OK;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
                else //if user clicks modify button
                {
                    Product_Supplier newProductSupplier = new Product_Supplier();
                    newProductSupplier.ProductSupplierID = packProdSup.ProductSupplerID;
                    this.ProductSupplierData(newProductSupplier);
                    try
                    {
                        if (!Product_SupplierDB.UpdateProduct_Supplier_Packages(packProdSup, newProductSupplier)) //if product update was unsuccessful
                        {
                            MessageBox.Show("Another user has updated or " +
                                            "deleted that customer.", "Database Error");
                            this.DialogResult = DialogResult.Retry;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
コード例 #17
0
 //user clicks accept button
 private void btnAccept_Click(object sender, EventArgs e)
 {
     if (ValidData())
     {
         if (addProductSupplier) //add button was pressed
         {
             productSupplier = new Product_Supplier();
             this.ProductSupplierData(productSupplier); //set the product supplier data to the product supplier object
             try
             {
                 productSupplier.ProductSupplierID = Product_SupplierDB.AddProduct_Supplier(productSupplier);
                 this.DialogResult = DialogResult.OK;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
         else //modify button was pressed
         {
             Product_Supplier newProductSupplier = new Product_Supplier();
             newProductSupplier.ProductSupplierID = productSupplier.ProductSupplierID;
             this.ProductSupplierData(newProductSupplier);
             try
             {
                 if (!Product_SupplierDB.UpdateProduct_Supplier(productSupplier, newProductSupplier))
                 {
                     MessageBox.Show("Another user has updated or " +
                                     "deleted that customer.", "Database Error");
                     this.DialogResult = DialogResult.Retry;
                 }
                 else
                 {
                     this.DialogResult = DialogResult.OK;
                 }
             }
             catch (Exception ex)
             {
                 throw ex;
             }
         }
     }
 }
コード例 #18
0
 //sets the productSupplier value selected by user to the productSuppler object
 private void ProductSupplierData(Product_Supplier productSupplier)
 {
     productSupplier.ProductID  = Convert.ToInt32(cbProdName.SelectedValue);
     productSupplier.SupplierID = Convert.ToInt32(cbSupName.SelectedValue);
 }
コード例 #19
0
        private void AddProduct_Button_Click(object sender, RoutedEventArgs e)
        {
            if (DateTime.TryParse(date.ToString(), out datetime) == false)//parsing date for bill
            {
                datetime = DateTime.Now;
            }
            //checking trial subscription
            if (DateTime.Compare(datetime, Register.SubscriptionDateEnd) > 0)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Hey Contact to the developer.", " Subscription Error:", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (checkErrors() == false)
            {
                return;
            }

            int supplierID = SupplierTableData.getIDBySupplier(supplier.Text);

            Product pro = new Product {
                ID = product.ID, Type = productType.Text, Model = productModel.Text, Quantity_Available = quan, Unit_Price = unitP, Selling_Price = SellingP, Unique_Barcode = product.Unique_Barcode, Date_Updated = datetime
            };

            Product_Supplier pro_supp = new Product_Supplier {
                Product_ID = product.ID, Quantity = quan, Unit_Price = pro.Unit_Price, Ref_Number = referenceNo.Text, Supplier_ID = supplierID, Date = datetime
            };

            foreach (ListViewItems obj in listView.Items)
            {
                Barcode b = new Barcode {
                    Product_ID = pro.ID, Barcode_Serial = obj.IMEI, Color = obj.Color, Date = datetime
                };

                pro.Barcodes.Add(b);
            }

            grandTotalDouble  += (int)pro.Unit_Price * quan;///calculation total amount
            grandTotal.Content = grandTotalDouble;

            ///checked means he will pay through cash, cheque or card
            if (paymentCheckBox.IsChecked == true)
            {
                paymentDueDouble   = grandTotalDouble - totalPaymentDouble;
                paymentDue.Content = paymentDueDouble;

                payment.Text = paymentDueDouble.ToString();
            }
            else
            {
                paymentDueDouble   = 0;
                paymentDue.Content = "0.0";

                totalPaymentDouble   = grandTotalDouble;
                totalPayment.Content = totalPaymentDouble;
            }

            totalQuantityInt     += quan;///calculation total amount
            totalQuantity.Content = totalQuantityInt;

            DataGridItems DGItems = new DataGridItems(serial++, pro);

            DGItems.SubTotal = (int)pro.Unit_Price * quan;
            dataGrid.Items.Add(DGItems);
            listProduct.Add(pro);
            listProduct_Supplier.Add(pro_supp);

            productModel.SelectedIndex = -1;
            productType.SelectedIndex  = -1;
            quantity.Clear();
            unitPrice.Clear();
            sellingPrice.Clear();
            listView.Items.Clear();
            description.Clear();
            color.SelectedIndex   = -1;
            uniqBarcode.IsChecked = true;
            productType.Focus();
            supplier.IsEnabled           = false;
            addSupplier_Button.IsEnabled = false;
        }
コード例 #20
0
        /// <summary>
        /// Create single parent or child product which can contains Properties combination
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public void CreateProduct(BProduct product)
        {
            if (this.CurrentUserPermission.ADD_PRODUCT == 0)
            {
                throw new KMJXCException("没有权限创建产品");
            }

            Product dbProduct = new Product();

            dbProduct.Code        = product.Code;
            dbProduct.Create_Time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
            dbProduct.Name        = product.Title;
            dbProduct.Parent_ID   = product.ParentID;
            dbProduct.Quantity    = 0;
            dbProduct.Description = product.Description;
            if (product.Category != null)
            {
                dbProduct.Product_Class_ID = product.Category.ID;
            }
            dbProduct.Product_ID = 0;
            dbProduct.Price      = product.Price;
            if (product.Unit != null)
            {
                dbProduct.Product_Unit_ID = product.Unit.Product_Unit_ID;
            }
            dbProduct.Shop_ID = this.Shop.Shop_ID;
            dbProduct.User_ID = this.MainUser.ID;

            if (product.Parent != null && product.Parent.ID > 0)
            {
                dbProduct.Parent_ID = product.Parent.ID;
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                db.Product.Add(dbProduct);
                db.SaveChanges();
                if (dbProduct.Product_ID <= 0)
                {
                    throw new KMJXCException("产品创建失败");
                }
                product.ID = dbProduct.Product_ID;
                //Update product images
                if (product.Images != null && product.Images.Count > 0)
                {
                    List <int> img_ids = new List <int>();
                    foreach (Image img in product.Images)
                    {
                        img_ids.Add(img.ID);
                    }

                    List <Image> dbImages = (from img in db.Image where img_ids.Contains(img.ID) select img).ToList <Image>();
                    foreach (Image image in dbImages)
                    {
                        image.ProductID = product.ID;
                    }

                    db.SaveChanges();
                }
                Stock_Batch batch = null;
                if (dbProduct.Parent_ID == 0)
                {
                    batch = new Stock_Batch()
                    {
                        Name = "P0", ProductID = dbProduct.Product_ID, Price = 0, ShopID = dbProduct.Shop_ID, Desc = "", Created_By = this.CurrentUser.ID
                    };
                    batch.Created         = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    batch.ParentProductID = dbProduct.Parent_ID;
                    db.Stock_Batch.Add(batch);
                    db.SaveChanges();
                }
                else
                {
                    batch = (from b in db.Stock_Batch where b.ProductID == dbProduct.Parent_ID select b).FirstOrDefault <Stock_Batch>();
                }

                Store_House        defaultStoreHouse = null;
                List <Store_House> storeHouses       = (from h in db.Store_House where (h.Shop_ID == dbProduct.Shop_ID || h.Shop_ID == this.Main_Shop.Shop_ID) select h).ToList <Store_House>();

                if (storeHouses.Count == 0)
                {
                    defaultStoreHouse             = new Store_House();
                    defaultStoreHouse.Shop_ID     = dbProduct.Shop_ID;
                    defaultStoreHouse.Title       = "默认仓库";
                    defaultStoreHouse.Address     = "";
                    defaultStoreHouse.Phone       = "";
                    defaultStoreHouse.User_ID     = this.CurrentUser.ID;
                    defaultStoreHouse.Create_Time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    defaultStoreHouse.Default     = true;
                    defaultStoreHouse.Guard       = 0;
                    db.Store_House.Add(defaultStoreHouse);
                    db.SaveChanges();
                }
                else
                {
                    defaultStoreHouse = (from h in storeHouses where h.Default == true select h).FirstOrDefault <Store_House>();
                    if (defaultStoreHouse == null)
                    {
                        defaultStoreHouse         = storeHouses[0];
                        defaultStoreHouse.Default = true;
                    }
                }

                Stock_Pile stockPile = new Stock_Pile();
                stockPile.LastLeave_Time = 0;
                stockPile.Price          = 0;
                stockPile.Product_ID     = product.ID;
                stockPile.Quantity       = 0;
                stockPile.Shop_ID        = dbProduct.Shop_ID;
                stockPile.StockHouse_ID  = defaultStoreHouse.StoreHouse_ID;
                stockPile.StockPile_ID   = 0;
                stockPile.Batch_ID       = batch.ID;

                db.Stock_Pile.Add(stockPile);

                if (product.Properties != null && product.Properties.Count > 0)
                {
                    foreach (BProductProperty pro in product.Properties)
                    {
                        Product_Specifications ps = new Product_Specifications();
                        ps.Product_ID            = dbProduct.Product_ID;
                        ps.Product_Spec_ID       = pro.PID;
                        ps.Product_Spec_Value_ID = pro.PVID;
                        ps.User_ID = this.CurrentUser.ID;
                        ps.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        db.Product_Specifications.Add(ps);
                    }

                    //db.SaveChanges();
                }

                if (product.Suppliers != null)
                {
                    foreach (Supplier su in product.Suppliers)
                    {
                        Product_Supplier ps = new Product_Supplier();
                        ps.Product_ID  = product.ID;
                        ps.Supplier_ID = su.Supplier_ID;
                        db.Product_Supplier.Add(ps);
                    }

                    //db.SaveChanges();
                }

                if (product.Children != null)
                {
                    foreach (BProduct p in product.Children)
                    {
                        if (p.Parent == null)
                        {
                            p.ParentID = dbProduct.Product_ID;
                            p.Parent   = new BProduct()
                            {
                                ID = product.ID
                            };
                        }
                        p.Children = null;
                        this.CreateProduct(p);
                    }
                }
                else
                {
                    base.CreateActionLog(new BUserActionLog()
                    {
                        Shop = new BShop {
                            ID = dbProduct.Shop_ID
                        }, Action = new BUserAction()
                        {
                            Action_ID = UserLogAction.CREATE_PRODUCT
                        }, Description = ""
                    });
                }

                db.SaveChanges();
            }
        }
コード例 #21
0
        /// <summary>
        /// Update product information
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public bool UpdateProduct(ref BProduct bproduct)
        {
            BProduct product = bproduct;

            if (this.CurrentUserPermission.UPDATE_PRODUCT == 0)
            {
                throw new KMJXCException("没有权限更新产品");
            }

            bool            result = false;
            KuanMaiEntities db     = new KuanMaiEntities();

            try
            {
                Product dbProduct = (from pdt in db.Product where pdt.Product_ID == product.ID select pdt).FirstOrDefault <Product>();
                if (dbProduct == null)
                {
                    throw new KMJXCException("您要修改的产品信息不存在");
                }

                if (this.Shop.Shop_ID != this.Main_Shop.Shop_ID)
                {
                    if (dbProduct.Shop_ID == this.Main_Shop.Shop_ID)
                    {
                        throw new KMJXCException("您不能修改主店铺产品");
                    }

                    if (dbProduct.Shop_ID != this.Shop.Shop_ID)
                    {
                        throw new KMJXCException("您不能其他主店铺产品");
                    }
                }
                else
                {
                    int[] child_shops = (from c in this.DBChildShops select c.Shop_ID).ToArray <int>();
                    if (dbProduct.Shop_ID != this.Main_Shop.Shop_ID && !child_shops.Contains(dbProduct.Shop_ID))
                    {
                        throw new KMJXCException("您无法修改其他店铺的产品,只能修改主店铺或者子店铺产品");
                    }
                }

                dbProduct.Name        = product.Title;
                dbProduct.Description = product.Description;
                if (product.Category != null)
                {
                    dbProduct.Product_Class_ID = product.Category.ID;
                }
                dbProduct.Update_Time    = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                dbProduct.Update_User_ID = this.CurrentUser.ID;

                //update images
                if (product.Images != null && product.Images.Count > 0)
                {
                    List <Image> existedImages = (from img in db.Image where img.ProductID == product.ID select img).ToList <Image>();
                    //Update new uploaded images
                    foreach (Image newimg in product.Images)
                    {
                        Image tmp = (from eted in existedImages where eted.ID == newimg.ID select eted).FirstOrDefault <Image>();
                        if (tmp == null)
                        {
                            Image newone = (from ni in db.Image where ni.ID == newimg.ID select ni).FirstOrDefault <Image>();
                            newone.ProductID = product.ID;
                            db.Image.Add(newone);
                        }
                    }

                    //Remove deleted images
                    string rootPath = product.FileRootPath;
                    foreach (Image oldImg in existedImages)
                    {
                        Image tmp = (from eted in product.Images where eted.ID == oldImg.ID select eted).FirstOrDefault <Image>();
                        if (tmp == null)
                        {
                            db.Image.Remove(oldImg);
                            if (rootPath != null && System.IO.File.Exists(rootPath + oldImg.Path))
                            {
                                System.IO.File.Delete(rootPath + oldImg.Path);
                            }
                        }
                    }
                }

                //update suppliers
                if (product.Suppliers != null)
                {
                    foreach (Supplier s in product.Suppliers)
                    {
                        Product_Supplier ps = new Product_Supplier()
                        {
                            Product_ID = product.ID, Supplier_ID = s.Supplier_ID, Enabled = true, Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now), Created_By = this.CurrentUser.ID
                        };
                        db.Product_Supplier.Add(ps);
                    }
                }

                //update children
                List <Product> children = (from p in db.Product where p.Parent_ID == dbProduct.Product_ID select p).ToList <Product>();
                foreach (Product child in children)
                {
                    child.Name             = dbProduct.Name;
                    child.Product_Class_ID = dbProduct.Product_Class_ID;
                    child.Description      = dbProduct.Description;
                }

                db.SaveChanges();

                if (product.Children != null && product.Children.Count > 0)
                {
                    foreach (BProduct child in product.Children)
                    {
                        if (child.ID == 0)
                        {
                            //create new child product with properties
                            child.Parent   = product;
                            child.Children = null;
                            this.CreateProduct(child);
                        }
                        else
                        {
                            //Update properties
                            if (child.Properties != null && child.Properties.Count > 0)
                            {
                                List <Product_Specifications> properties = (from prop in db.Product_Specifications
                                                                            where prop.Product_ID == child.ID
                                                                            select prop).ToList <Product_Specifications>();

                                List <Product_Specifications> newProps = new List <Product_Specifications>();
                                if (properties.Count > 0)
                                {
                                    //current just support edit existed property's value, doesn't support deleting property
                                    foreach (BProductProperty p in child.Properties)
                                    {
                                        Product_Specifications psprop = (from ep in properties where ep.Product_Spec_ID == p.PID select ep).FirstOrDefault <Product_Specifications>();
                                        if (psprop == null)
                                        {
                                            //cretae new property for existed product
                                            psprop = new Product_Specifications()
                                            {
                                                Product_ID = child.ID, Product_Spec_ID = p.PID, Product_Spec_Value_ID = p.PVID, Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now), User_ID = this.CurrentUser.ID
                                            };
                                            db.Product_Specifications.Add(psprop);
                                        }
                                        else
                                        {
                                            //update existed property's value
                                            if (psprop.Product_Spec_Value_ID != p.PVID)
                                            {
                                                psprop.Product_Spec_Value_ID = p.PVID;
                                            }
                                        }
                                    }

                                    db.SaveChanges();
                                }
                            }
                        }
                    }
                }


                bproduct = this.GetProductFullInfo(product.ID);

                base.CreateActionLog(new BUserActionLog()
                {
                    Shop = new BShop {
                        ID = bproduct.Shop.Shop_ID
                    }, Action = new BUserAction()
                    {
                        Action_ID = UserLogAction.UPDATE_PRODUCT
                    }, Description = "商品编号:" + bproduct.ID + "\n商品名称:" + bproduct.Title
                });
                result = true;
            }
            catch (KMJXCException kex)
            {
                throw kex;
            }
            catch
            {
            }
            finally
            {
                db.Dispose();
            }
            return(result);
        }
コード例 #22
0
 public int Insert(Product_Supplier obj)
 {
     this.context.Product_Suppliers.Add(obj);
     return(this.context.SaveChanges());
 }
コード例 #23
0
 public int Update(Product_Supplier obj)
 {
     this.context.Product_Suppliers.Attach(obj);
     context.Entry(obj).State = System.Data.EntityState.Modified;
     return(this.context.SaveChanges());
 }
コード例 #24
0
        /// <summary>
        /// Update supplier products
        /// </summary>
        /// <param name="product_ids"></param>
        /// <param name="supplier_id"></param>
        public void UpdateSupplierProducts(int[] product_ids, int supplier_id)
        {
            if (supplier_id <= 0)
            {
                throw new KMJXCException("更新供应商产品时必须输入供应商编号");
            }

            if (this.CurrentUserPermission.UPDATE_SUPPLIER_PRODUCT == 0)
            {
                throw new KMJXCException("没有权限更新供应商产品");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Supplier supplier = (from s in db.Supplier where s.Supplier_ID == supplier_id select s).FirstOrDefault <Supplier>();
                if (supplier == null)
                {
                    throw new KMJXCException("编号为:" + supplier_id + " 的供应商信息不存在");
                }

                if (this.Shop.Shop_ID == this.Main_Shop.Shop_ID)
                {
                    int[] child_shops = (from c in this.ChildShops select c.ID).ToArray <int>();
                    if (this.Shop.Shop_ID != supplier.Shop_ID && !child_shops.Contains(supplier.Shop_ID))
                    {
                        throw new KMJXCException("不能操作其他店铺的供应商,只能使用主店铺和子店铺的供应商");
                    }
                }
                else
                {
                    if (supplier.Shop_ID != this.Shop.Shop_ID && supplier.Shop_ID != this.Main_Shop.Shop_ID)
                    {
                        throw new KMJXCException("不能操作其他店铺的供应商,只能使用主店铺和子店铺的供应商");
                    }
                }

                List <Product_Supplier> products = (from s in db.Product_Supplier where s.Supplier_ID == supplier_id select s).ToList <Product_Supplier>();
                if (product_ids == null || product_ids.Length <= 0)
                {
                    foreach (Product_Supplier p in products)
                    {
                        p.Enabled = false;
                    }

                    db.SaveChanges();
                }
                else
                {
                    for (int i = 0; i < product_ids.Length; i++)
                    {
                        Product_Supplier ps = (from s in products where s.Product_ID == product_ids[i] select s).FirstOrDefault <Product_Supplier>();
                        if (ps == null)
                        {
                            ps             = new Product_Supplier();
                            ps.Supplier_ID = supplier_id;
                            ps.Product_ID  = product_ids[i];
                            ps.Enabled     = true;
                            ps.Created     = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                            ps.Created_By  = this.CurrentUser.ID;
                            db.Product_Supplier.Add(ps);
                        }
                        else
                        {
                            ps.Enabled = true;
                        }
                    }

                    db.SaveChanges();
                }
            }
        }