Beispiel #1
0
    private int ImportCombination(int idProduct, string referenceCode, decimal basePrice, decimal priceBeforeImpact, decimal impactPrice, decimal PriceAfterImpact, decimal price, decimal impactWeight, decimal weight, int Quantity, int idColor, int idSize)
    {
        try
        {
            DataClassesDataContext db = new DataClassesDataContext();
            int            firstQty   = 0;
            Class_Employee emp        = new Class_Employee();
            var            employee   = emp.GetData_By_Token(HttpContext.Current.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieAdmin"].ToString()].Value);

            if (db.TBProduct_Combinations.Where(x => !x.Deflag && x.ReferenceCode == referenceCode).FirstOrDefault() != null)
            {
                TBProduct_Combination data = db.TBProduct_Combinations.Where(x => !x.Deflag && x.ReferenceCode == referenceCode).FirstOrDefault();
                firstQty      = data.Quantity;
                data.Quantity = Quantity;
                db.SubmitChanges();
                return(data.IDProduct_Combination);
            }

            TBProduct_Combination _newData = new TBProduct_Combination();
            TBValue color = db.TBValues.Where(x => !x.Deflag && x.IDValue == idColor).FirstOrDefault();
            TBValue size  = db.TBValues.Where(x => !x.Deflag && x.IDValue == idSize).FirstOrDefault();
            _newData.IDProduct          = idProduct;
            _newData.ReferenceCode      = referenceCode;
            _newData.Name               = color.TBAttribute.Name + " : " + color.Name + ", " + size.TBAttribute.Name + " : " + size.Name;
            _newData.DateInsert         = DateTime.Now;
            _newData.DateLastUpdate     = DateTime.Now;
            _newData.BasePrice          = basePrice;
            _newData.PriceBeforeImpact  = priceBeforeImpact;
            _newData.PriceAfterImpact   = PriceAfterImpact;
            _newData.Price              = price;
            _newData.WeightBeforeImpact = weight;
            _newData.Weight             = weight;
            _newData.Quantity           = Quantity;
            _newData.DateLastUpdate     = DateTime.Now;
            _newData.DateInsert         = DateTime.Now;
            db.TBProduct_Combinations.InsertOnSubmit(_newData);
            db.SubmitChanges();

            //INSERT DETAIL COMBINATAION COLOR
            TBProduct_Combination_Detail _detail = new TBProduct_Combination_Detail();
            _detail.IDProduct_Combination = _newData.IDProduct_Combination;
            _detail.IDValue       = color.IDValue;
            _detail.NameAttribute = color.TBAttribute.Name;
            _detail.NameValue     = color.Name;
            _detail.DateInsert    = DateTime.Now;
            db.TBProduct_Combination_Details.InsertOnSubmit(_detail);

            //INSERT DETAIL COMBINATAION Size
            TBProduct_Combination_Detail _detailSize = new TBProduct_Combination_Detail();
            _detailSize.IDProduct_Combination = _newData.IDProduct_Combination;
            _detailSize.IDValue       = size.IDValue;
            _detailSize.NameAttribute = size.TBAttribute.Name;
            _detailSize.NameValue     = size.Name;
            _detailSize.DateInsert    = DateTime.Now;
            db.TBProduct_Combination_Details.InsertOnSubmit(_detailSize);
            db.SubmitChanges();

            //INSERT LOG
            Class_Log_Stock log = new Class_Log_Stock();
            log.Insert(employee.IDEmployee, _detail.TBProduct_Combination.IDProduct_Combination, _detail.TBProduct_Combination.Name, firstQty, Quantity, Quantity, "initial", "Import master product" + " by " + employee.Name + "( " + employee.Email + " )");

            return(_newData.IDProduct_Combination);
        }
        catch (Exception)
        {
            return(0);
        }
    }
Beispiel #2
0
    protected void btnImport_Click(object sender, EventArgs e)
    {
        if (fuFile.HasFile)
        {
            lblSuccess.Text = "";
            lblError.Text   = "";
            try
            {
                DataClassesDataContext db = new DataClassesDataContext();

                Class_Employee emp  = new Class_Employee();
                var            test = emp.DecryptToken(HttpContext.Current.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieAdmin"].ToString()].Value);
                if (emp.DecryptToken(HttpContext.Current.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieAdmin"].ToString()].Value) != null && HttpContext.Current.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieAdmin"].ToString()] != null)
                {
                    fuFile.SaveAs(Server.MapPath("~/assets/import/inventory/" + fuFile.FileName));
                    StreamReader sr = new StreamReader(Server.MapPath("~/assets/import/inventory/" + fuFile.FileName));
                    try
                    {
                        CsvReader csvread = new CsvReader(sr);
                        csvread.Configuration.Delimiter       = ";";
                        csvread.Configuration.HasHeaderRecord = false;
                        char[] delimeter = { ',' };

                        List <CSV_Inventory> record = csvread.GetRecords <CSV_Inventory>().ToList();
                        int totalRead     = 0;
                        int totalNotfound = 0;
                        int totalUpdate   = 0;
                        foreach (var item in record)
                        {
                            totalRead++;
                            TBProduct_Combination data = db.TBProduct_Combinations.Where(x => !x.Deflag && x.TBProduct.ReferenceCode == item.ReferenceCodeProduct && x.ReferenceCode == item.ReferenceCodeCombination).FirstOrDefault();
                            var employee = emp.GetData_By_Token(HttpContext.Current.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieAdmin"].ToString()].Value);
                            if (data != null)
                            {
                                string jenis = "";
                                data.Quantity = item.Quantity;
                                if (data.Quantity > item.Quantity)
                                {
                                    jenis = "decrease";
                                }
                                else
                                {
                                    jenis = "increase";
                                }
                                db.SP_Update_Qty(item.ReferenceCodeCombination, item.Quantity);
                                totalUpdate++;

                                TBLog_Stock log = new TBLog_Stock();
                                log.Description           = "import inventory";
                                log.IDEmployee            = employee.IDEmployee;
                                log.IDProduct_Combination = data.IDProduct_Combination;
                                log.ProductName           = data.TBProduct.Name;
                                log.UserName   = employee.Name;
                                log.Type       = jenis;
                                log.Quantity   = item.Quantity;
                                log.InsertDate = DateTime.Now;

                                db.TBLog_Stocks.InsertOnSubmit(log);
                                db.SP_Insert_LogStock("import inventory", employee.IDEmployee, data.IDProduct_Combination, data.TBProduct.Name, employee.Name, jenis, item.Quantity, DateTime.Now);
                            }
                            else
                            {
                                totalNotfound++;
                            }
                        }

                        sr.Close();
                        lblSuccess.Text += totalRead + " row(s) read, " + totalUpdate + " row(s) updated, " + totalNotfound + " row(s) not found data";
                        alertError.Style.Add(HtmlTextWriterStyle.Display, "none");
                        alertSuccess.Style.Add(HtmlTextWriterStyle.Display, "block");
                    }
                    catch (Exception ex)
                    {
                        sr.Close();
                        lblError.Text = ex.Message;
                        alertError.Style.Add(HtmlTextWriterStyle.Display, "block");
                        alertSuccess.Style.Add(HtmlTextWriterStyle.Display, "none");
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
                alertError.Style.Add(HtmlTextWriterStyle.Display, "block");
                alertSuccess.Style.Add(HtmlTextWriterStyle.Display, "none");
            }
        }
    }