예제 #1
0
 public ActionResult Product_Generic_Data_Create(product_details model)
 {
     if (ModelState.IsValid)
     {
         product_generic_data item = new product_generic_data();
         if (TryUpdateModel(item))
         {
             erpdb.product_generic_data.Add(item);
             erpdb.SaveChanges();
             return(RedirectToAction("Product_Generic_Data_List"));
         }
         else
         {
             return(View("Error"));
         }
     }
     else
     {
         ModelState.AddModelError("", "发生错误");
         return(View(model));
     }
 }
예제 #2
0
 public ActionResult Product_Generic_Data_Edit(product_generic_data model)
 {
     if (ModelState.IsValid)
     {
         product_generic_data item = new product_generic_data();
         if (TryUpdateModel(item))
         {
             erpdb.Entry(item).State = System.Data.Entity.EntityState.Modified;
             erpdb.SaveChanges();
             return(RedirectToAction("Product_Generic_Data_List"));
         }
         else
         {
             return(View("Error"));
         }
     }
     else
     {
         ModelState.AddModelError("", "发生错误");
         return(View(model));
     }
 }
예제 #3
0
 private List <Excel_DataMessage> analyseExcel_GenericTable(string filename, List <Excel_DataMessage> messageList)
 {
     try
     {
         string          folder  = HttpContext.Server.MapPath("~/Content/xlsx/");
         string          strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + folder + filename + ";Extended Properties='Excel 12.0; HDR=1; IMEX=1'"; //此连接可以操作.xls与.xlsx文件
         OleDbConnection conn    = new OleDbConnection(strConn);
         conn.Open();
         DataSet          ds   = new DataSet();
         OleDbDataAdapter odda = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", "Sheet1$"), conn);                    //("select * from [Sheet1$]", conn);
         odda.Fill(ds, "[Sheet1$]");
         conn.Close();
         DataTable dt          = ds.Tables[0];
         int       i           = 0;
         bool      result_flag = true;
         foreach (DataRow dr in dt.Rows)
         {
             i++;
             try
             {
                 // 判断是否含有数据
                 string   storename  = dr["店铺名称"].ToString();
                 DateTime date       = Convert.ToDateTime(ExcelOperation.ConvertDateTime(dr, "月份"));
                 string   item_code  = dr["商品编码"].ToString();
                 var      exist_item = erpdb.product_generic_data.SingleOrDefault(m => m.storename == storename && m.date == date && m.item_code == item_code);
                 if (exist_item != null)
                 {
                     // 更新数据
                     exist_item.storename    = storename;
                     exist_item.date         = date;
                     exist_item.item_code    = item_code;
                     exist_item.simple_name  = dr["商品简称"].ToString();
                     exist_item.uv           = ExcelOperation.ConvertInt(dr, "访客数");
                     exist_item.pv           = ExcelOperation.ConvertInt(dr, "浏览量");
                     exist_item.order_count  = ExcelOperation.ConvertInt(dr, "订单数");
                     exist_item.order_amount = ExcelOperation.ConvertDecimal(dr, "销售金额");
                     exist_item.product_unit = ExcelOperation.ConvertInt(dr, "下单件数");
                     exist_item.convertion   = ExcelOperation.ConvertInt(dr, "转化率");
                     messageList.Add(new Excel_DataMessage(i, "数据修改成功", false));
                 }
                 else
                 {
                     // 添加数据
                     product_generic_data details = new product_generic_data()
                     {
                         storename    = storename,
                         date         = date,
                         item_code    = item_code,
                         simple_name  = dr["商品简称"].ToString(),
                         uv           = ExcelOperation.ConvertInt(dr, "访客数"),
                         pv           = ExcelOperation.ConvertInt(dr, "浏览量"),
                         order_count  = ExcelOperation.ConvertInt(dr, "订单数"),
                         order_amount = ExcelOperation.ConvertDecimal(dr, "销售金额"),
                         product_unit = ExcelOperation.ConvertInt(dr, "下单件数"),
                         convertion   = ExcelOperation.ConvertInt(dr, "转化率")
                     };
                     erpdb.product_generic_data.Add(details);
                     messageList.Add(new Excel_DataMessage(i, "数据添加成功", false));
                 }
             }
             catch (Exception e)
             {
                 result_flag = false;
                 messageList.Add(new Excel_DataMessage(i, "格式错误或列名不存在," + e.InnerException, true));
             }
         }
         if (result_flag)
         {
             erpdb.SaveChanges();
             messageList.Add(new Excel_DataMessage(0, "数据存储成功", false));
         }
         else
         {
             messageList.Add(new Excel_DataMessage(0, "数据行发生错误,未保存", true));
         }
     }
     catch (Exception e)
     {
         messageList.Add(new Excel_DataMessage(-1, "表格格式错误" + e.ToString(), true));
     }
     return(messageList);
 }
예제 #4
0
        public ActionResult Product_Generic_Data_Create()
        {
            product_generic_data data = new product_generic_data();

            return(View(data));
        }