예제 #1
0
        /// <summary>
        /// 保存方法
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult Save(PlanBatchInfo model)
        {
            var ajaxData = new AjaxDataResult()
            {
                code = 0, msg = "保存失败!"
            };

            try
            {
                if (model != null)
                {
                    db.PlanBatchInfos.Add(model);
                    var result = db.SaveChanges() > 0;

                    if (result)
                    {
                        ajaxData.code = 1;
                        ajaxData.msg  = "保存成功!";
                    }
                }
            }
            catch (Exception ex)
            {
                ajaxData.msg = ex.Message;
            }

            return(Json(ajaxData, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        /// <summary>
        /// 获取Excel数据
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        private static List <PlanBatchInfo> GetExcelData(string fileName)
        {
            var list = new List <PlanBatchInfo>();
            var url  = System.AppDomain.CurrentDomain.BaseDirectory + fileName;

            Workbook  book  = new Workbook(url);
            Worksheet sheet = book.Worksheets[0];
            Cells     cells = sheet.Cells;
            DataTable dt    = cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true);

            if (dt.Rows.Count > 0)
            {
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    var     i     = 0;
                    DataRow dr    = dt.Rows[j];
                    var     model = new PlanBatchInfo();
                    model.PlanBatch   = dr[i++].ToString();
                    model.PlanName    = dr[i++].ToString();
                    model.CityPlace   = dr[i++].ToString();
                    model.BidMode     = dr[i++].ToString();
                    model.BuyWay      = dr[i++].ToString();
                    model.BidYear     = dr[i++].ToString();
                    model.BidFlag     = dr[i++].ToString();
                    model.PlanCheckDt = Convert.ToDateTime(dr[i++].ToString());
                    model.Status      = dr[i++].ToString();
                    model.PlanStartDt = Convert.ToDateTime(dr[i++].ToString());
                    model.PlanEndDt   = Convert.ToDateTime(dr[i++].ToString());
                    model.CityStartDt = Convert.ToDateTime(dr[i++].ToString());
                    model.Period      = dr[i++].ToString();

                    list.Add(model);
                }
            }

            return(list);
        }