Beispiel #1
0
 private int ImportShipping(int idCarrier, int idDistrict, decimal price)
 {
     try
     {
         DataClassesDataContext db = new DataClassesDataContext();
         var existData             = db.TBShippings.Where(x => !x.Deflag && x.IDDistrict == idDistrict && x.IDCarrier == idCarrier).FirstOrDefault();
         if (existData == null)
         {
             TBShipping newData = new TBShipping();
             newData.IDCarrier      = idCarrier;
             newData.IDDistrict     = idDistrict;
             newData.Price          = price;
             newData.Deflag         = false;
             newData.DateInsert     = DateTime.Now;
             newData.DateLastUpdate = DateTime.Now;
             db.TBShippings.InsertOnSubmit(newData);
             db.SubmitChanges();
             totalInsert++;
             return(newData.IDShipping);
         }
         else
         {
             existData.Price = price;
             db.SubmitChanges();
             totalUpdate++;
             updateData += existData.TBDistrict.TBCity.TBProvince.TBCountry.Name + " - " + existData.TBDistrict.TBCity.TBProvince.Name + " - " + existData.TBDistrict.TBCity.Name + " - " + existData.TBDistrict.Name + " - " + existData.Price + "<br/>";
             return(existData.IDShipping);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #2
0
    public ReturnData AJAX_Update_Price(int idShipping, decimal price)
    {
        try
        {
            DataClassesDataContext db        = new DataClassesDataContext();
            TBShipping             _shipping = db.TBShippings.Where(x => x.IDShipping == idShipping && !x.Deflag).FirstOrDefault();
            if (_shipping == null)
            {
                return(ReturnData.MessageFailed("Data not found", null));
            }
            else
            {
                _shipping.Price = price;
                db.SubmitChanges();
                return(ReturnData.MessageSuccess("Shipping price updated", null));
            }
        }
        catch (Exception ex)
        {
            Class_Log_Error log = new Class_Log_Error();
            log.Insert(ex.Message, ex.StackTrace);

            return(ReturnData.MessageFailed(ex.Message, null));
        }
    }
Beispiel #3
0
    protected void btnImport_Click(object sender, EventArgs e)
    {
        if (fuFile.HasFile)
        {
            try
            {
                DataClassesDataContext db = new DataClassesDataContext();
                fuFile.SaveAs(Server.MapPath("~/assets/import/shipping/" + fuFile.FileName));
                StreamReader sr = new StreamReader(Server.MapPath("~/assets/import/shipping/" + fuFile.FileName));
                try
                {
                    CsvReader csvread = new CsvReader(sr);
                    csvread.Configuration.Delimiter       = ";";
                    csvread.Configuration.HasHeaderRecord = true;

                    List <CSV_Shipping> record = csvread.GetRecords <CSV_Shipping>().ToList();
                    int totalRead   = 0;
                    int totalInsert = 0;
                    foreach (var item in record)
                    {
                        totalRead++;
                        if (db.TBShippings.Where(x => x.IDCarrier == item.IDCarrier && x.IDDistrict == item.IDDistrict).FirstOrDefault() == null)
                        {
                            TBShipping newShipping = new TBShipping {
                                IDCarrier = item.IDCarrier, IDDistrict = item.IDDistrict, Price = item.Price, Deflag = false, DateInsert = DateTime.Now, DateLastUpdate = DateTime.Now
                            };
                            db.TBShippings.InsertOnSubmit(newShipping);
                            totalInsert++;
                        }
                        else
                        {
                            lblSuccess.Text += "Error duplicate <br/>";
                        }
                    }
                    db.SubmitChanges();
                    sr.Close();
                    lblSuccess.Text += totalRead + " row(s) read, " + totalInsert + " row(s) inserted";
                    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");
            }
        }
    }