Пример #1
0
 /// <summary>
 /// 導入Excel數據
 /// </summary>
 /// <returns></returns>
 public HttpResponseBase AppCategoryUpExcel()
 {
     string json = string.Empty;//json字符串
     int successcount = 0;
     int failcount = 0;
     int typeerror = 0;//要匯入的數據類型錯誤
     try
     {
         if (Request.Files["ImportFileMsg"] != null && Request.Files["ImportFileMsg"].ContentLength > 0)//判斷文件是否為空
         {
             HttpPostedFileBase excelFile = Request.Files["ImportFileMsg"];//獲取文件流
             FileManagement fileManagement = new FileManagement();//實例化 FileManagement
             StringBuilder str = new StringBuilder();
             string fileLastName = excelFile.FileName;
             string newExcelName = Server.MapPath(excelPath) + "App功能管理" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名
             excelFile.SaveAs(newExcelName);//上傳文件
             DataTable dt = new DataTable();
             NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName);
             dt = helper.SheetData();//根據這個表,插入到數據庫中
             DataRow[] dr = dt.Select(); //定义一个DataRow数组,读取ds里面所有行
             _iappcategoryMgr = new AppcategoryMgr(mySqlConnectionString);
             if (dt.Rows.Count > 0)
             {
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
                     Appcategory appCategory = new Appcategory();
                     try
                     {
                         appCategory.brand_id = Convert.ToInt32(dt.Rows[i]["brand_id"]);
                         appCategory.brand_name = dt.Rows[i]["brand_name"].ToString();
                         appCategory.category = dt.Rows[i]["category"].ToString();
                         appCategory.category1 = dt.Rows[i]["category1"].ToString();
                         appCategory.category2 = dt.Rows[i]["category2"].ToString();
                         appCategory.category3 = dt.Rows[i]["category3"].ToString();
                         appCategory.product_id = Convert.ToInt32(dt.Rows[i]["product_id"]);
                         appCategory.property = dt.Rows[i]["property"].ToString();
                     }
                     catch (Exception ex)
                     {
                         str.Append(i + 2 + " ");
                         failcount++;
                         continue;
                     }
                     int results=  _iappcategoryMgr.AppcategorySave(appCategory);
                     if (results > 0)
                     {
                         successcount++;
                     }
                     else
                     {
                         str.Append(i + 2 + " ");
                         failcount++;
                     }
                 }
                 if (str.Length > 1)
                 {
                     str.Length -= 1;
                     json = "{success:true,total:" + successcount + ",fail:" + failcount + ",errorRow:\"" + str.ToString() + "\"}";
                 }
                 else
                 {
                     json = "{success:true,total:" + successcount + ",fail:" + failcount + "}";
                 }
             }
             else
             {
                 json = "{success:false,msg:\"" + "此表內沒有數據或數據有誤,請檢查后再次匯入!" + "\"}";
             }
           
         }
         else
         {
             json = "{success:false,msg:\"" + "請選擇要匯入的Excel表" + "\"}";
         }
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:false,msg:\"" + ex.ToString() + "\"}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
Пример #2
0
        /// <summary>
        /// 獲取表單的數據
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase GetAppCategoryList()
        {
            List<Appcategory> stores = new List<Appcategory>();

            string json = string.Empty;
            try
            {
                Appcategory query = new Appcategory();
                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量
                query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量
                if (!string.IsNullOrEmpty(Request.Form["category"]))//判斷館別是否為空
                {
                    query.category = Request.Form["category"];
                }
                if (!string.IsNullOrEmpty(Request.Form["category1"]))//判斷分類一是否為空
                {
                    query.category1 = Request.Form["category1"];
                }
                if (!string.IsNullOrEmpty(Request.Form["category2"]))
                {
                    query.category2 = Request.Form["category2"];
                }
                if (!string.IsNullOrEmpty(Request.Form["category3"]))
                {
                    query.category3 = Request.Form["category3"];
                }
                if (!string.IsNullOrEmpty(Request.Form["product_id"]))//判斷商品ID是否為空
                {
                    query.product_id = int.Parse(Request.Form["product_id"]);
                }
                _iappcategoryMgr = new AppcategoryMgr(mySqlConnectionString);
                int totalCount = 0;
                stores = _iappcategoryMgr.GetAppcategoryList(query, out totalCount);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                //listUser是准备转换的对象
                json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(stores, Formatting.Indented, timeConverter) + "}";
                //返回json數據
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:true,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Пример #3
0
 /// <summary>
 /// 刪除數據
 /// </summary>
 /// <returns></returns>
 public HttpResponseBase AppCategoryDelete()
 {
     string jsonStr = String.Empty;
     _iappcategoryMgr = new AppcategoryMgr(mySqlConnectionString);
     Appcategory query = new Appcategory();
     if (!String.IsNullOrEmpty(Request.Params["rowid"]))
     {
         try
         {
             foreach (string rid in Request.Params["rowid"].ToString().Split('|'))
             {
                 if (!string.IsNullOrEmpty(rid))
                 {
                     query.category_id = Convert.ToInt32(rid);
                     _iappcategoryMgr.AppcategoryDelete(query);
                 }
             }
             jsonStr = "{success:true}";
         }
         catch (Exception ex)
         {
             Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
             logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
             logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
             log.Error(logMessage);
             jsonStr = "{success:false}";
         }
     }
     this.Response.Clear();
     this.Response.Write(jsonStr);
     this.Response.End();
     return this.Response;
 }
Пример #4
0
 /// <summary>
 /// 查詢下拉框的參數數據
 /// </summary>
 /// <returns></returns>
 public string QueryPara()
 {
     Appcategory appQuery = new Appcategory();
     string json = string.Empty;
     try
     {
         if (!string.IsNullOrEmpty(Request.QueryString["paraType"]))
         {
             _iappcategoryMgr = new AppcategoryMgr(mySqlConnectionString);
             string para = Request.Params["paraType"].ToString();
             appQuery.category = Request.Params["selectCondition"];
             appQuery.category1 = Request.Params["select1Condition"];
             appQuery.category2 = Request.Params["select2Condition"];
             json = _iappcategoryMgr.GetParaList(para, appQuery);
         }
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:true,totalCount:0,data:[]}";
     }
     return json;
 }