Example #1
0
 public ActionResult CreateSalesMonthPartial(Off_SalesInfo_Month model)
 {
     if (ModelState.IsValid)
     {
         Off_SalesInfo_Month item = new Off_SalesInfo_Month();
         if (TryUpdateModel(item))
         {
             item.UploadTime = DateTime.Now;
             item.UploadUser = User.Identity.Name;
             _offlineDB.Off_SalesInfo_Month.Add(item);
             _offlineDB.SaveChanges();
             return(Content("SUCCESS"));
         }
         ModelState.AddModelError("", "发生错误");
         var storelist = from m in _offlineDB.Off_Store
                         orderby m.StoreName
                         select new { Key = m.Id, Value = m.StoreName };
         ViewBag.StoreDropDown = new SelectList(storelist, "Key", "Value");
         return(PartialView(model));
     }
     else
     {
         ModelState.AddModelError("", "发生错误");
         var storelist = from m in _offlineDB.Off_Store
                         orderby m.StoreName
                         select new { Key = m.Id, Value = m.StoreName };
         ViewBag.StoreDropDown = new SelectList(storelist, "Key", "Value");
         return(PartialView(model));
     }
 }
Example #2
0
        public ActionResult CreateSalesMonthPartial()
        {
            var user      = UserManager.FindById(User.Identity.GetUserId());
            var item      = new Off_SalesInfo_Month();
            var storelist = from m in _offlineDB.Off_Store
                            where m.Off_System_Id == user.DefaultSystemId
                            orderby m.StoreName
                            select new { Key = m.Id, Value = m.StoreName };

            ViewBag.StoreDropDown = new SelectList(storelist, "Key", "Value");
            return(PartialView(item));
        }
Example #3
0
 public ActionResult EditMonthSalesPartial(int id, FormCollection form)
 {
     if (ModelState.IsValid)
     {
         var item = new Off_SalesInfo_Month();
         if (TryUpdateModel(item))
         {
             item.UploadTime = DateTime.Now;
             item.UploadUser = User.Identity.Name;
             _offlineDB.Entry(item).State = System.Data.Entity.EntityState.Modified;
             _offlineDB.SaveChanges();
             return(Content("SUCCESS"));
         }
         else
         {
             ModelState.AddModelError("", "错误");
             return(PartialView(item));
         }
     }
     else
     {
         return(PartialView("ErrorPartial"));
     }
 }
Example #4
0
        // Origin:analyseExcel_MonthInfoTable
        public async Task <List <Excel_DataMessage> > UploadMonthSalesByExcelAsync(string filename, List <Excel_DataMessage> messageList)
        {
            try
            {
                var             user    = UserManager.FindById(User.Identity.GetUserId());
                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();
                        var    exist_store = _offlineDB.Off_Store.SingleOrDefault(m => m.StoreName == storename && m.Off_System_Id == user.DefaultSystemId);
                        if (exist_store == null)
                        {
                            messageList.Add(new Excel_DataMessage(i, "店铺不存在", true));
                            result_flag = false;
                            continue;
                        }
                        // 判断是否含已有数据
                        DateTime info_date = Convert.ToDateTime(dr["月份"]);
                        info_date = new DateTime(info_date.Year, info_date.Month, 1);
                        var exist_dailyinfo = _offlineDB.Off_SalesInfo_Daily.SingleOrDefault(m => m.Date.Year == info_date.Year && m.Date.Month == info_date.Month && m.StoreId == exist_store.Id);
                        if (exist_dailyinfo != null)
                        {
                            messageList.Add(new Excel_DataMessage(i, "当月数据已存在", true));
                            result_flag = false;
                            continue;
                        }
                        else
                        {
                            Off_SalesInfo_Month monthinfo = new Off_SalesInfo_Month()
                            {
                                StoreId    = exist_store.Id,
                                Date       = info_date,
                                Item_Brown = ExcelOperation.ConvertInt(dr, "红糖姜茶"),
                                Item_Black = ExcelOperation.ConvertInt(dr, "黑糖姜茶"),
                                Item_Lemon = ExcelOperation.ConvertInt(dr, "柠檬姜茶"),
                                Item_Honey = ExcelOperation.ConvertInt(dr, "蜂蜜姜茶"),
                                Item_Dates = ExcelOperation.ConvertInt(dr, "红枣姜茶"),
                                UploadTime = DateTime.Now,
                                UploadUser = User.Identity.Name
                            };
                            _offlineDB.Off_SalesInfo_Month.Add(monthinfo);
                            messageList.Add(new Excel_DataMessage(i, "数据类型验证成功", false));
                        }
                    }
                    catch (Exception e)
                    {
                        result_flag = false;
                        messageList.Add(new Excel_DataMessage(i, "表格格式错误," + e.ToString(), true));
                    }
                }
                if (result_flag)
                {
                    await _offlineDB.SaveChangesAsync();

                    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);
        }