Наследование: System.Web.UI.Page
Пример #1
0
        public ActionResult PruductDetails(product_details ob_Product, HttpPostedFileBase product_image)
        {
            if (ModelState.IsValid)
            {
                var path = "";
                if (product_image != null)
                {
                    var fileName = "";

                    if ((product_image.ContentLength > 0))
                    {
                        fileName = DateTime.Now.ToString("ddMMyyyyhhmmss") + Path.GetFileName(product_image.FileName);
                        path     = Path.Combine(Server.MapPath("~/Upload_Product"), fileName);
                        product_image.SaveAs(path);
                        path = Url.Content(Path.Combine("~/Upload_Product", fileName));
                    }
                    ob_Product.product_image = path;
                }
                else if (ob_Product.product_image != "" && ob_Product.product_image != null)
                {
                    path = ob_Product.product_image;
                }
                else
                {
                    ModelState.AddModelError("", "Choose product image");
                    return(View(ob_Product));
                }
                var get = m_db.product_details.Where(a => a.id == ob_Product.id).FirstOrDefault();
                if (get != null)
                {
                    get.m_service_type_id   = ob_Product.m_service_type_id;
                    get.price               = ob_Product.price;
                    get.product_description = ob_Product.product_description;
                    get.product_image       = path;
                    get.product_name        = ob_Product.product_name;
                    get.product_title       = ob_Product.product_title;
                    m_db.Entry(get).State   = EntityState.Modified;
                    m_db.SaveChanges();
                    return(RedirectToAction("ViewProduct", "Admin"));
                }
                else
                {
                    m_db.product_details.Add(ob_Product);
                    m_db.SaveChanges();
                }
                ViewData["Message"] = "Product Details is Saved Successfully";
                return(RedirectToAction("PruductDetails", "Admin"));
            }
            else
            {
                return(View(ob_Product));
            }
        }
Пример #2
0
 public ActionResult Product_Details_Edit(product_details model)
 {
     if (ModelState.IsValid)
     {
         product_details item = new product_details();
         if (TryUpdateModel(item))
         {
             erpdb.Entry(item).State = System.Data.Entity.EntityState.Modified;
             erpdb.SaveChanges();
             return(RedirectToAction("Product_Details_List"));
         }
         else
         {
             return(View("Error"));
         }
     }
     else
     {
         ModelState.AddModelError("", "发生错误");
         return(View(model));
     }
 }
Пример #3
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));
     }
 }
Пример #4
0
 private List <Excel_DataMessage> analyseExcel_StoreTable(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_details.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.sales_count  = Convert.ToInt32(ExcelOperation.ConvertInt(dr, "销售数量"));
                     exist_item.sales_amount = Convert.ToDecimal(dr["销售金额"]);
                     messageList.Add(new Excel_DataMessage(i, "数据修改成功", false));
                 }
                 else
                 {
                     // 添加数据
                     product_details details = new product_details()
                     {
                         storename    = storename,
                         date         = date,
                         item_code    = item_code,
                         simple_name  = dr["商品简称"].ToString(),
                         sales_count  = Convert.ToInt32(ExcelOperation.ConvertInt(dr, "销售数量")),
                         sales_amount = Convert.ToDecimal(dr["销售金额"])
                     };
                     erpdb.product_details.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);
 }
Пример #5
0
        public ActionResult Product_Details_Create()
        {
            product_details data = new product_details();

            return(View(data));
        }