Esempio n. 1
0
    public dynamic DYNAMIC_AddToCart_Renew(int idProduct, int idCustomer, int idCustomerProduct)
    {
        try
        {
            DataClassesDataContext db     = new DataClassesDataContext();
            Class_Order            _Order = new Class_Order();
            var dataOrder = db.TBProducts.Where(x => x.IDProduct == idProduct).FirstOrDefault();
            //HttpCookie _cookie = HttpContext.Current.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieCart"].ToString()];
            string       anonID  = HttpContext.Current.Request.AnonymousID;
            TBOrder_temp _cookie = _Order.GetEncodedDataOrder(anonID);

            string _token = "";
            Dictionary <string, dynamic>         _product     = new Dictionary <string, dynamic>();
            List <Dictionary <string, dynamic> > _listProduct = new List <Dictionary <string, dynamic> >();
            Dictionary <string, dynamic>         _tokenData   = new Dictionary <string, dynamic>();
            TBProduct_Combination productCombination          = db.TBProduct_Combinations.Where(x => !x.Deflag && x.IDProduct_Combination == dataOrder.TBProduct_Combinations.FirstOrDefault().IDProduct_Combination).FirstOrDefault();
            if (productCombination == null)
            {
                return(ReturnData.MessageFailed("Data not found", null));
            }

            _product.Add("IDProduct", dataOrder.IDProduct);
            _product.Add("IDCombination", dataOrder.TBProduct_Combinations.FirstOrDefault().IDProduct_Combination);
            _product.Add("Price", dataOrder.Price * 1);
            _product.Add("CombinationName", dataOrder.TBProduct_Combinations.FirstOrDefault().Name);
            _product.Add("Quantity", 1);
            _product.Add("ProductName", dataOrder.Name);
            _product.Add("PricePerUnit", dataOrder.Price);
            _product.Add("Weight", productCombination.Weight);
            _product.Add("WeightPerUnit", productCombination.Weight);

            _listProduct.Add(_product);
            _tokenData.Add("Product", _listProduct);
            _tokenData.Add("TotalPrice", dataOrder.Price);
            _tokenData.Add("TotalQuantity", 1);
            _tokenData.Add("TotalWeight", productCombination.Weight);
            _tokenData.Add("Subtotal", dataOrder.Price);
            _tokenData.Add("IDCurrency", Class_Currency.GetActiveCurrencyID());
            _tokenData.Add("OrderType", "renew");
            _tokenData.Add("IDCustomerProduct", idCustomerProduct);
            _token = OurClass.EncryptToken(_tokenData);
            //HttpContext.Current.Response.Cookies.Add(new HttpCookie(System.Configuration.ConfigurationManager.AppSettings["cookieCart"].ToString(), _token));
            _Order.SaveEncodeDataOrder(HttpContext.Current.Request.AnonymousID, _token);
            //HttpContext.Current.Response.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieCart"].ToString()].Expires = DateTime.Now.AddMinutes(120);
            return(ReturnData.MessageSuccess("Product add to cart successfully", _tokenData));

            //cek cookies nya ada ngga, kalo ada ganti token
            //kalo ga ada tambahin dulu _witcomcrt_
            //cek kalo token nya kosong
            // kalo ngga kosong, decrypt dulu, ambil object nya.
            //trus tambahin sama cart yang baru
        }
        catch (Exception ex)
        {
            Class_Log_Error log = new Class_Log_Error();
            log.Insert(ex.Message, ex.StackTrace);

            return(ReturnData.MessageFailed(ex.Message, null));
        }
    }
Esempio n. 2
0
 public int UpdateQty(string appKey, string combinationCode, int qty)
 {
     try
     {
         appKey = "Uxp46H91dAHVce1C";
         //string token = "Uxp46H91dAHVce1C";
         DataClassesDataContext db  = new DataClassesDataContext();
         TBProduct_Combination  cmb = db.TBProduct_Combinations.Where(x => !x.Deflag && x.ReferenceCode == combinationCode).FirstOrDefault();
         if (cmb == null)
         {
             return(0);
         }
         else
         {
             cmb.Quantity = qty;
             db.SubmitChanges();
             return(1);
         }
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Esempio n. 3
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);
        }
    }
Esempio n. 4
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");
            }
        }
    }