Пример #1
0
        public HttpResponseBase UpdateConfig()
        {
            string json = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["Name"]))
                {
                    SiteConfig newConfig = new SiteConfig { Name = Request.Form["Name"], Value = Request.Form["Value"] ?? "" };
                    string path = Server.MapPath(xmlPath);
                    if (System.IO.File.Exists(path))
                    {
                        siteConfigMgr = new SiteConfigMgr(path);
                        if (siteConfigMgr.UpdateNode(newConfig))
                        {
                            json = "{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);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Пример #2
0
 public JsonResult QueryConfig()
 {
     List<SiteConfig> configs = new List<SiteConfig>();
     try
     {
         string path = Server.MapPath(xmlPath);
         if (System.IO.File.Exists(path))
         {
             siteConfigMgr = new SiteConfigMgr(path);
             configs = siteConfigMgr.Query();
         }
     }
     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);
     }
     return Json(configs);
 }
Пример #3
0
        public HttpResponseBase VendorBrandPreview()
        {
            _siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
            List<SiteConfig> configList = _siteConfigMgr.Query();
            string DomainName = configList.Where(m => m.Name.Equals("DoMain_Name")).FirstOrDefault().Value;
            string json = string.Empty;
            try
            {
                VendorBrandQuery query = new VendorBrandQuery();
                _vendorBrand = new VendorBrandMgr(connectionString);
                if (!string.IsNullOrEmpty(Request.Params["brand_id"]))
                {
                    query.Brand_Id = Convert.ToUInt32(Request.Params["brand_id"]);
                    int classify = _vendorBrand.GetClassify(query);
                    string result = string.Empty;
                    switch (classify)
                    {
                        case 10:
                            result += "http://" + DomainName + "/food/brand_food.php?b_id=" + query.Brand_Id;//商品預覽
                            break;
                        case 20:
                            result += "http://" + DomainName + "/stuff/brand_stuff.php?b_id=" + query.Brand_Id;//商品預覽
                            break;
                        default:
                            result += "http://" + DomainName + "/brand.php?b_id=" + query.Brand_Id;//商品預覽
                            break;
                        //www.gigade100.com/newweb/food/brand_food.php?b_id=332
                    }
                    json = result.ToString().ToLower();
                }

            }
            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 = "無預覽信息";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Пример #4
0
 public bool QueryStockPrerogative(string callid,string xmlPath)
 {
    siteConfigMgr = new SiteConfigMgr(xmlPath);
    string groupCode = siteConfigMgr.GetConfigByName("STOCK_PREROGATIVE").Value;
    return _fgDao.Query(callid, groupCode).Count() > 0;
 }
Пример #5
0
        public HttpResponseBase ExportCsv()
        {
            string filename = string.Empty;
            string json = "{success:false}";//json字符串
            userioMgr = new UserIOMgr(mySqlConnectionString);
            usersMgr = new UsersMgr(mySqlConnectionString);
            siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
            try
            {
                if (Request.Files["ImportCsvFile"] != null && Request.Files["ImportCsvFile"].ContentLength > 0)//判斷文件是否為空
                {
                    HttpPostedFileBase excelFile = Request.Files["ImportCsvFile"];//獲取文件流

                    FileManagement fileManagement = new FileManagement();//實例化 FileManagement

                    string fileLastName = excelFile.FileName.Substring((excelFile.FileName).LastIndexOf('.')).ToLower().Trim();
                    if (fileLastName.Equals(".csv"))
                    {

                        string newExcelName = Server.MapPath(excelPath) + "user_io" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名

                        System.Data.DataTable _dt = new DataTable();

                        excelFile.SaveAs(newExcelName);//上傳文件
                        //excelHelper = new NPOI4ExcelHelper(newExcelName);
                        _dt = CsvHelper.ReadCsvToDataTable(newExcelName, true);//獲取csv里的數據
                        Regex num = new System.Text.RegularExpressions.Regex("^[0-9]+$");

                        string sqlAdition = "";
                        for (int i = 0; i < _dt.Rows.Count; i++)
                        {
                            if (_dt.Rows[i][0].ToString() != "")
                            {
                                if (!num.IsMatch(_dt.Rows[i][0].ToString()))//判斷是否匹配正則表達式
                                {
                                    System.IO.File.Delete(newExcelName);//刪除上傳過的excle
                                    int rows = i + 2;
                                    int cloumns = 1;
                                    json = "{success:false,msg:\"" + "第" + rows + "條第" + cloumns + "列數據錯誤" + "\"}";
                                    this.Response.Clear();
                                    this.Response.Write(json);
                                    this.Response.End();
                                    return this.Response;
                                }
                                else
                                {
                                    if (i == 0)
                                    {
                                        sqlAdition = _dt.Rows[i][0].ToString();
                                    }
                                    else
                                    {
                                        sqlAdition += "," + Convert.ToUInt32(_dt.Rows[i][0].ToString());//獲取id,以,隔開id
                                    }
                                }

                            }
                        }

                        DataTable dtexcel = userioMgr.GetExcelTable(sqlAdition);//從數據庫里獲取csv里的id的數據

                        #region 讀取會員資料
                        json = string.Empty;
                        if (!System.IO.Directory.Exists(Server.MapPath(excelPath)))
                        {
                            System.IO.Directory.CreateDirectory(Server.MapPath(excelPath));
                        }
                        try
                        {
                            string[] colname = new string[dtexcel.Columns.Count];
                            filename = "user_io" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv";
                            string newExcelfilename = Server.MapPath(excelPath) + filename;
                            for (int i = 0; i < dtexcel.Columns.Count; i++)
                            {
                                colname[i] = dtexcel.Columns[i].ColumnName;
                            }
                            if (System.IO.File.Exists(newExcelfilename))
                            {
                                System.IO.File.Delete(newExcelfilename);
                            }
                            excelFile.SaveAs(newExcelfilename);//上傳文件
                            CsvHelper.ExportDataTableToCsv(dtexcel, newExcelfilename, colname, true);


                            IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                            timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                            json = "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);
                            json = "false,";
                        }

                        #endregion

                        #region ///更改前的內容
                        //string[] colname = new string[dtexcel.Columns.Count];//定義一個數組
                        //for (int i = 0; i < dtexcel.Columns.Count; i++)
                        //{
                        //    colname[i] = dtexcel.Columns[i].ColumnName;//獲取列名
                        //}
                        //CsvHelper.ExportDataTableToCsv(dtexcel, newExcelName, colname, true);

                        ////打開導出的Excel 文件
                        //System.Diagnostics.Process Excelopen = new System.Diagnostics.Process();
                        //Excelopen.StartInfo.FileName = newExcelName;
                        //Excelopen.Start();
                        #endregion

                        json = "{success:true,msg:\"" + filename + "\"}";
                    }
                    else
                    {
                        json = "{success:false,msg:\"" + "請匯入CSV格式檔案" + "\"}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;

                    }
                }

                else
                {
                    json = "{success:false,msg:\"" + "請匯入檔案" + "\"}";
                }
            }
            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);
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Пример #6
0
        public HttpResponseBase UsersList()
        {
            List<UsersListQuery> stores = new List<UsersListQuery>();
            List<SiteConfig> configs = new List<SiteConfig>();
            SiteConfig con = new SiteConfig();
            string json = string.Empty;
            try
            {
                string path = Server.MapPath(xmlPath);
                if (System.IO.File.Exists(path))
                {
                    siteConfigMgr = new SiteConfigMgr(path);
                    configs = siteConfigMgr.Query();
                }
                foreach (SiteConfig site in configs)
                {
                    if (site.Name == "DoMain_Name")
                    {
                        con = site;
                        break;
                    }
                }
                UsersListQuery query = new UsersListQuery();

                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量
                query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "20");//用於分頁的變量

                //todo:分页汇出会员信息,由于不能确定是按分页汇出还是汇出全部会员信息,暂且保留汇出全部会员信息
                //start = query.Start;
                //limit = query.Limit;
                if (!string.IsNullOrEmpty(Request.Params["serchs"]))
                {
                    query.serchtype = Request.Params["serchs"];
                }
                if (!string.IsNullOrEmpty(Request.Params["timestart"]))
                {

                    query.serchstart = Convert.ToDateTime(Request.Params["timestart"]);
                    query.serchstart = Convert.ToDateTime(query.serchstart.ToString("yyyy-MM-dd HH:mm:ss"));
                }
                if (!string.IsNullOrEmpty(Request.Params["timeend"]))
                {
                    query.serchend = Convert.ToDateTime(Request.Params["timeend"]);
                    query.serchend = Convert.ToDateTime(query.serchend.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                query.content = Request.Params["serchcontent"];
                query.types = Request.Params["bonus_type"];
                query.checks = Request.Params["checkbox1"];
                if (!string.IsNullOrEmpty(Request.Params["relation_id"]))//待回覆
                {
                    query.user_id = Convert.ToUInt32(Request.Params["relation_id"]);
                }
                _uslmpgr = new UsersListMgr(mySqlConnectionString);
                _paraMgr = new ParameterMgr(mySqlConnectionString);
                int totalCount = 0;
                stores = _uslmpgr.Query(query, out totalCount);
                Parametersrc pa = new Parametersrc();
                foreach (var item in stores)
                {
                    string[] url = con.Value.Split('/');
                    item.user_url = "http://" + url[0] + "/ecservice_jump.php";//?uid=" + item.user_id;
                    if (Convert.ToBoolean(Request.Params["isSecret"]))
                    {
                        if (!string.IsNullOrEmpty(item.user_name))
                        {
                            item.user_name = item.user_name.Substring(0, 1) + "**";
                        }
                        item.user_email = item.user_email.Split('@')[0] + "@***";
                        //if (!string.IsNullOrEmpty(item.user_mobile))
                        //{
                        //    if (item.user_phone.ToString().Length > 3)
                        //    {
                        //        item.user_phone = item.user_phone.Substring(0, 3) + "***";
                        //    }
                        //    else
                        //    {
                        //        item.user_phone = item.user_phone + "***";
                        //    }
                        //}
                        if (!string.IsNullOrEmpty(item.user_mobile))
                        {
                            item.user_mobile = UnSecretMobile(item);
                            if (item.user_mobile.ToString().Length > 3)
                            {
                                item.user_mobile = item.user_mobile.Substring(0, 3) + "***";
                            }
                            else
                            {
                                item.user_mobile = item.user_mobile + "***";
                            }

                        }
                        if (item.user_address.ToString().Length > 3)
                        {
                            item.user_address = item.user_address.Substring(0, 3) + "***";
                        }
                        else
                        {
                            item.user_address = item.user_address + "***";
                        }
                    }
                    else
                    {
                        if (item.user_mobile.Length == 48)
                        {
                            item.user_mobile = EncryptComputer.EncryptDecryptTextByApi(item.user_mobile, false);
                        }
                    }
                    //獲取時間
                    item.reg_date = CommonFunction.GetNetTime(item.user_reg_date);
                    item.sfirst_time = CommonFunction.GetNetTime(item.first_time);
                    item.slast_time = CommonFunction.GetNetTime(item.last_time);
                    item.sbe4_last_time = CommonFunction.GetNetTime(item.be4_last_time);

                    pa = _paraMgr.QueryUsed(new Parametersrc { Used = 1, ParameterCode = item.user_level.ToString(), ParameterType = "UserLevel" }).FirstOrDefault();
                    if (pa != null)
                    {
                        item.userLevel = pa.parameterName;
                    }
                    #region 購物金欄位修改 add by yafeng0715j 20150924
                    BonusMasterMgr bmMgr = new BonusMasterMgr(mySqlConnectionString);
                    BonusMasterQuery bmQuery = new BonusMasterQuery();
                    bmQuery.user_id = item.user_id;
                    bmQuery.bonus_type = 1;
                    DataTable table = bmMgr.GetBonusMasterList(bmQuery);
                    uint master_total = 0;
                    int master_balance = 0;
                    if (table.Rows[0][0].ToString() != "")
                    {
                        master_total = Convert.ToUInt32(table.Rows[0][0]);
                        master_balance = Convert.ToInt32(table.Rows[0][1]);
                    }
                    item.bonus_type = 1;
                    item.bonus_typename = string.Format("購物金(剩餘{0}/總{1})", master_balance, master_total);

                    master_total = 0;
                    master_balance = 0;
                    bmQuery.bonus_type = 2;
                    table = bmMgr.GetBonusMasterList(bmQuery);
                    if (table.Rows[0][0].ToString() != "")
                    {
                        master_total = Convert.ToUInt32(table.Rows[0][0]);
                        master_balance = Convert.ToInt32(table.Rows[0][1]);
                    }
                    item.bonus_type1 = 2;
                    item.bonus_typenamequan = string.Format("抵用券(剩餘{0}/總{1})", master_balance, master_total);
                    #endregion

                }
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                //listUser是准备转换的对象
                json = "{success:true,'msg':'user',totalCount:" + totalCount + ",start:" + query.Start + ",limit:" + query.Limit + ",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;
        }
Пример #7
0
        public ActionResult OrderImport()
        {
            if (!System.IO.Directory.Exists(Server.MapPath(excelPath)))
            {
                System.IO.Directory.CreateDirectory(Server.MapPath(excelPath));
            }
            if (!System.IO.Directory.Exists(Server.MapPath(pdfPath)))
            {
                System.IO.Directory.CreateDirectory(Server.MapPath(pdfPath));
            }

            siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
            SiteConfig excellConfig = siteConfigMgr.GetConfigByName("Excel_Extension_Filter");
            SiteConfig pdfConfig = siteConfigMgr.GetConfigByName("PDF_Extension_Filter");
            ViewBag.ExcelEx = string.IsNullOrEmpty(excellConfig.Value) ? excellConfig.DefaultValue : excellConfig.Value;
            ViewBag.PDFEx = string.IsNullOrEmpty(pdfConfig.Value) ? pdfConfig.DefaultValue : pdfConfig.Value;
            return View();
        }
Пример #8
0
        public ActionResult upLoadImg()
        {
            try
            {
                HttpPostedFileBase file = Request.Files["Filedata"];
                int type = Request["appOrexplain"] == null ? 0 : Convert.ToInt32(Request["appOrexplain"]);
                string nameType = Request.Params["nameType"];  // 將 nametype 提前 使其判斷傳入的圖片是否為商品主圖 edit by zhuoqin0830w 2015/01/29
                int prodCheck = file.FileName.LastIndexOf("prod_");  // 將 proCheck 提前 使其判斷批量上傳的圖片中是否存在商品主圖   edit by zhuoqin0830w 2015/01/30
                if (nameType == "spec")
                {
                    type = 5;
                }
                if (prodCheck == 0 && type == 0) //批量上傳時type才會 ==0,其他單獨上傳時是不需要根據prod處理圖片的
                {
                    type = 3;
                }
                int mobileCheck = file.FileName.LastIndexOf("mobile_");//批量上傳時type才會 ==0,其他單獨上傳時是不需要根據prod處理圖片的
                if (mobileCheck == 0 && type == 0)
                {
                    type = 4;
                }
                string path = Server.MapPath(xmlPath);
                siteConfigMgr = new SiteConfigMgr(path);
                SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format");
                SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue");
                SiteConfig maxValue_config = null;

                //判斷 批量上傳 或 單個上傳 的圖片是否為 商品主圖 或 手機商品圖  edit by zhuoqin0830w 2015/03/24
                switch (nameType)
                {
                    //如果  nameType == prod  則表示 是 單個上傳 商品主圖
                    case "prod":
                        maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max");
                        break;
                    //如果  nameType == mobile  則表示 是 單個上傳 手機商品圖 
                    case "mobile":
                        maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max");
                        break;
                    //如果  nameType == null  則表示 是 批量上傳
                    case null:
                        //如果  prodCheck == 0  則表示 是 批量上傳 中包含 商品主圖 
                        if (prodCheck == 0)
                        {
                            maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max");
                        }
                        //如果  mobileCheck == 0  則表示 是 批量上傳 中包含 手機商品圖 
                        else if (mobileCheck == 0)
                        {
                            maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max");
                        }
                        else
                        {
                            maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
                        }
                        break;
                    default:
                        maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
                        break;
                }

                string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value;
                string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value;
                string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value;


                if ((nameType == "mobile" && type == 4) || (mobileCheck == 0 && type == 4)) //add by wwei0216w 2015/4/1 添加原因:手機圖片要放在640*640路徑下
                {
                    prodPath = prodMobile640;
                }
                string localProdPath = imgLocalPath + prodPath;

                //string localProd50Path = imgLocalPath + prod50Path;
                //string localProd150Path = imgLocalPath + prod150Path;
                //string localProd280Path = imgLocalPath + prod280Path;

                string localSpecPath = imgLocalPath + specPath;
                //string localSpec100Path = imgLocalPath + spec100Path;
                //string localSpec280Path = imgLocalPath + spec280Path;

                string[] Mappath = new string[2];

                FileManagement fileLoad = new FileManagement();

                string fileName = string.Empty;
                string fileExtention = string.Empty;
                ViewBag.spec_id = -1;
                if (nameType != null)
                {
                    fileName = nameType + fileLoad.NewFileName(file.FileName);
                    fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                    fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower();

                }
                else
                {
                    #region 批次上傳圖片操作
                    //此處由批次上傳進入.
                    //判斷文件名格式是否正確
                    ViewBag.moreFileOneTime = true;
                    //int prodCheck = file.FileName.LastIndexOf("prod_");
                    int specCheck = file.FileName.LastIndexOf("spec_");
                    int descCheck = file.FileName.LastIndexOf("desc_");
                    int appCheck = file.FileName.LastIndexOf("app_");
                    string errorMsg = "ERROR/";
                    if (prodCheck == -1 && specCheck == -1 && descCheck == -1 && appCheck == -1 && mobileCheck == -1)
                    {
                        errorMsg += "[" + file.FileName + "] ";
                        errorMsg += Resources.Product.FILE_NAME_ERROR;
                        ViewBag.fileName = errorMsg;
                        return View("~/Views/Product/upLoad.cshtml");
                    }
                    else
                    {
                        nameType = file.FileName.Split('_')[0];
                        if (nameType == "app")
                        {
                            type = 2;
                        }
                        else if (nameType == "desc")
                        {
                            type = 1;
                        }
                        else if (nameType == "spec")
                        {
                            type = 5;
                        }
                        fileName = nameType + fileLoad.NewFileName(file.FileName);
                        fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                        fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.'));
                    }
                    if (specCheck == 0)
                    {
                        Caller _caller = (Session["caller"] as Caller);
                        string spec = file.FileName.Split('_')[1].Split('.')[0];
                        bool checkStatus = true;
                        if (!string.IsNullOrEmpty(Request.Params["product_id"].Split(';')[0].ToString()))
                        {
                            //product_spec
                            uint pid = uint.Parse(Request.Params["product_id"].Split(';')[0].ToString());

                            _specMgr = new ProductSpecMgr(connectionString);
                            List<ProductSpec> pSpecList = _specMgr.Query(new ProductSpec { product_id = pid, spec_type = 1 });
                            foreach (var item in pSpecList)
                            {
                                if (item.spec_name == spec)
                                {
                                    checkStatus = false;
                                    ViewBag.spec_id = item.spec_id;
                                }
                            }
                        }
                        else
                        {
                            //product_spec_temp
                            _specTempMgr = new ProductSpecTempMgr(connectionString);
                            List<ProductSpecTemp> pSpecTempList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, spec_type = 1 });
                            foreach (var item in pSpecTempList)
                            {
                                if (item.spec_name == spec)
                                {
                                    checkStatus = false;
                                    ViewBag.spec_id = item.spec_id;
                                }
                            }
                        }
                        if (checkStatus)//表示沒有要上傳圖片規格相同的規格一
                        {
                            errorMsg += "[" + file.FileName + "] " + Resources.Product.SPEC_NOT_FIND;
                            ViewBag.fileName = errorMsg;
                            return View("~/Views/Product/upLoad.cshtml");
                        }
                    }
                    #endregion
                }
                SetPath(type);//設定圖片路徑
                string localDescPath = imgLocalPath + descPath;
                //string localDesc400Path = imgLocalPath + desc400Path;
                string returnName = imgServerPath;

                bool result = false;
                string NewFileName = string.Empty;


                BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                NewFileName = hash.Md5Encrypt(fileName, "32");

                string firstFolder = NewFileName.Substring(0, 2) + "/";
                string secondFolder = NewFileName.Substring(2, 2) + "/";
                string ServerPath = string.Empty;

                if (nameType == "spec")
                {
                    Mappath[0] = firstFolder;
                    Mappath[1] = secondFolder;

                    CreateFolder(localSpecPath, Mappath);
                    //CreateFolder(localSpec100Path, Mappath);
                    //CreateFolder(localSpec280Path, Mappath);

                    localSpecPath += firstFolder + secondFolder;
                    //localSpec100Path += firstFolder + secondFolder;
                    //localSpec280Path += firstFolder + secondFolder;
                    specPath += firstFolder + secondFolder;

                    returnName += specPath + NewFileName + fileExtention;
                    //localSpec100Path += NewFileName + fileExtention;
                    //localSpec280Path += NewFileName + fileExtention;
                    NewFileName = localSpecPath + NewFileName + fileExtention;
                    ServerPath = Server.MapPath(imgLocalServerPath + specPath);

                }
                else if (nameType == "desc" || nameType == "app")
                {

                    Mappath[0] = firstFolder;
                    Mappath[1] = secondFolder;

                    CreateFolder(localDescPath, Mappath);
                    //CreateFolder(localDesc400Path, Mappath);

                    localDescPath += firstFolder + secondFolder;

                    //localDesc400Path += firstFolder + secondFolder;
                    descPath += firstFolder + secondFolder;

                    //localDesc400Path += NewFileName + fileExtention;
                    returnName += descPath + NewFileName + fileExtention;


                    NewFileName = localDescPath + NewFileName + fileExtention;

                    ServerPath = Server.MapPath(imgLocalServerPath + descPath);
                }
                else
                {
                    Mappath[0] = firstFolder;
                    Mappath[1] = secondFolder;
                    //Data:2014/06/26
                    //author:Castle
                    //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!!
                    CreateFolder(localProdPath, Mappath);
                    //CreateFolder(localProd50Path, Mappath);
                    //CreateFolder(localProd150Path, Mappath);
                    //CreateFolder(localProd280Path, Mappath);

                    localProdPath += firstFolder + secondFolder;
                    //localProd50Path += firstFolder + secondFolder;
                    //localProd150Path += firstFolder + secondFolder;
                    //localProd280Path += firstFolder + secondFolder;
                    prodPath += firstFolder + secondFolder;

                    //localProd50Path += NewFileName + fileExtention;
                    //localProd150Path += NewFileName + fileExtention;
                    //localProd280Path += NewFileName + fileExtention;
                    returnName += prodPath + NewFileName + fileExtention;
                    NewFileName = localProdPath + NewFileName + fileExtention;
                    ServerPath = Server.MapPath(imgLocalServerPath + prodPath);
                }
                string ErrorMsg = string.Empty;
                Resource.CoreMessage = new CoreResource("Product");

                //上傳圖片

                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                #region //
                //上傳對應大小圖片
                //压缩图片至其它规格

                //Data:2014/06/26
                //author:Castle
                //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!!
                //if (result)
                //{
                //    FTP ftp = null;
                //    string newFileName = NewFileName.Substring(NewFileName.LastIndexOf("/"));

                //    GigadeService.TransImageClient transImg = new GigadeService.TransImageClient();
                //    if (nameType == "spec")
                //    {
                //        string sourceImgPath = Server.MapPath(imgLocalServerPath + specPath + NewFileName.Substring(NewFileName.LastIndexOf("/")));
                //        ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + spec100Path + firstFolder + secondFolder), newFileName, 100, 100, admin_userName.Value, admin_passwd.Value);
                //        if (string.IsNullOrWhiteSpace(ErrorMsg))
                //        {
                //            file.SaveAs(Server.MapPath(imgLocalServerPath + spec100Path + firstFolder + secondFolder + newFileName));
                //            ftp = new FTP(localSpec100Path, ftpuser, ftppwd);
                //            ftp.UploadFile(Server.MapPath(imgLocalServerPath + spec100Path + firstFolder + secondFolder + newFileName));
                //        }

                //        if (!Directory.Exists(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder)))
                //            Directory.CreateDirectory(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder));
                //        ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder), newFileName, 280, 280, admin_userName.Value, admin_passwd.Value);
                //        if (string.IsNullOrWhiteSpace(ErrorMsg))
                //        {
                //            file.SaveAs(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder + newFileName));
                //            ftp = new FTP(localSpec100Path, ftpuser, ftppwd);
                //            ftp.UploadFile(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder + newFileName));
                //        }
                //    }
                //    else if (nameType == "desc")
                //    {
                //        string sourceImgPath = Server.MapPath(imgLocalServerPath + descPath + NewFileName.Substring(NewFileName.LastIndexOf("/")));
                //        ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + desc400Path + firstFolder + secondFolder), newFileName, 400, 400, admin_userName.Value, admin_passwd.Value);
                //        if (string.IsNullOrWhiteSpace(ErrorMsg))
                //        {
                //            file.SaveAs(Server.MapPath(imgLocalServerPath + desc400Path + firstFolder + secondFolder + newFileName));
                //            ftp = new FTP(localSpec100Path, ftpuser, ftppwd);
                //            ftp.UploadFile(Server.MapPath(imgLocalServerPath + desc400Path + firstFolder + secondFolder + newFileName));
                //        }
                //    }
                //    else
                //    {
                //        //string sourceImgPath = Server.MapPath(imgLocalServerPath + prodPath + NewFileName.Substring(NewFileName.LastIndexOf("/")));
                //        //ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + prod50Path + firstFolder + secondFolder), newFileName, 50, 50, admin_userName.Value, admin_passwd.Value);
                //        //if (string.IsNullOrWhiteSpace(ErrorMsg))
                //        //{
                //        //    file.SaveAs(Server.MapPath(imgLocalServerPath + prod50Path + firstFolder + secondFolder + newFileName));
                //        //    ftp = new FTP(localProd50Path, ftpuser, ftppwd);
                //        //    ftp.UploadFile(Server.MapPath(imgLocalServerPath + prod50Path + firstFolder + secondFolder + newFileName));
                //        //}

                //        //ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + prod150Path + firstFolder + secondFolder), newFileName, 150, 150, admin_userName.Value, admin_passwd.Value);
                //        //if (string.IsNullOrWhiteSpace(ErrorMsg))
                //        //{
                //        //    file.SaveAs(Server.MapPath(imgLocalServerPath + prod150Path + firstFolder + secondFolder + newFileName));
                //        //    ftp = new FTP(localProd150Path, ftpuser, ftppwd);
                //        //    ftp.UploadFile(Server.MapPath(imgLocalServerPath + prod150Path + firstFolder + secondFolder + newFileName));
                //        //}

                //        ////if (!Directory.Exists(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder)))
                //        ////    Directory.CreateDirectory(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder));
                //        ////ImageClass iC280 = new ImageClass(sourceImgPath);
                //        //////iC280.ImageMagick(sourceImgPath, Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + NewFileName.Substring(NewFileName.LastIndexOf("/"))), 280, 280, ref error);
                //        ////iC150.MakeThumbnail(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + NewFileName.Substring(NewFileName.LastIndexOf("/"))), 280, 280, ref error);
                //        //ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder), newFileName, 280, 280, admin_userName.Value, admin_passwd.Value);
                //        //if (string.IsNullOrWhiteSpace(ErrorMsg))
                //        //{
                //        //    file.SaveAs(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + newFileName));
                //        //    ftp = new FTP(localProd280Path, ftpuser, ftppwd);
                //        //    ftp.UploadFile(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + newFileName));
                //        //}
                //    }
                //}
                #endregion
                if (string.IsNullOrEmpty(ErrorMsg))
                {
                    ViewBag.fileName = returnName;
                    ViewBag.Type = type;

                    //獲取文件長度 add by zhuoqin0830w 2015/01/29
                    string[] strFile = file.FileName.Split('_');
                    //判斷文件名的長度是否大於 1 如果大於 1 則再次進行判斷是否為數字 如果不是則進行強制轉換  
                    int image_sort = 0;
                    int.TryParse(strFile.Length > 1 ? strFile[1] : "0", out image_sort);
                    ViewBag.image_sort = image_sort;
                }
                else
                {
                    // 判斷 批量上傳中 是否存在 商品圖 或 手機商品圖  edit by zhuoqin0830w 2015/03/24
                    if (prodCheck == 0 || mobileCheck == 0)
                    { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; }
                    else { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; }

                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                    logMessage.Content = "ERROR/" + ErrorMsg;
                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    log.Error(logMessage);
                }
            }
            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);
            }

            return View("~/Views/Product/upLoad.cshtml");
        }
Пример #9
0
        /// <summary>
        /// 暫時不能確定
        /// </summary>
        /// <returns>返回一個xml的字符串</returns>
        public HttpResponseBase ProductItemUpdateNotice()
        {
            string msg = string.Empty;
            try
            {
                _paraMgr = new ParameterMgr(connectionString);
                _siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));

                string from = string.Empty, to = string.Empty, sendtime = string.Empty, status = string.Empty, host = string.Empty, username = string.Empty, userpasswd = string.Empty, mailport = string.Empty;

                List<SiteConfig> configList = _siteConfigMgr.Query();
                if (configList.Count() > 0)
                {
                    from = configList.Where(m => m.Name.Equals("Mail_From")).FirstOrDefault().Value;
                    host = configList.Where(m => m.Name.Equals("Mail_Host")).FirstOrDefault().Value;
                    username = configList.Where(m => m.Name.Equals("Mail_UserName")).FirstOrDefault().Value;
                    userpasswd = configList.Where(m => m.Name.Equals("Mail_UserPasswd")).FirstOrDefault().Value;
                    mailport = configList.Where(m => m.Name.Equals("Mail_Port")).FirstOrDefault().Value;
                }

                string subject = Resources.VendorProduct.PRODUCT_UPDATE_MAIL_SUBJECT_CHANAL;//外站商品對照異動通知 add by hufeng0813w 2014/07/07
                string body = QueryHistory(1);//為商品對照異動.根據商品對照表中存在的就發送沒有的就不發送
                if (body == "") status = "2";
                StringBuilder strXml = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?><mail>");
                strXml.AppendFormat("<status>{0}</status>", status);//0 關閉 ,1 正常, 2 無資料,3 服務器異常
                strXml.AppendFormat("<mailfrom>{0}</mailfrom>", from);
                strXml.AppendFormat("<mailsubject>{0}</mailsubject>", subject);
                strXml.AppendFormat("<mailhost>{0}</mailhost>", host);
                strXml.AppendFormat("<mailusername>{0}</mailusername>", username);
                strXml.AppendFormat("<mailuserpasswd>{0}</mailuserpasswd>", userpasswd);
                strXml.AppendFormat("<mailport>{0}</mailport>", mailport);
                strXml.AppendFormat("<mailbody>{0}</mailbody>", HttpUtility.HtmlEncode(body));
                strXml.Append("</mail>");
                msg = strXml.ToString();
            }
            catch (Exception)
            {
                msg = "<mail><status>3</status></mail>";
            }
            this.Response.Clear();
            this.Response.Write(msg);
            this.Response.End();
            return this.Response;
        }
        public ActionResult UpLoadImg()
        {
            string path = Server.MapPath(xmlPath);
            siteConfigMgr = new SiteConfigMgr(path);
            SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format");
            SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue");
            SiteConfig maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
            SiteConfig admin_userName = siteConfigMgr.GetConfigByName("ADMIN_USERNAME");
            SiteConfig admin_passwd = siteConfigMgr.GetConfigByName("ADMIN_PASSWD");
            string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value;
            string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value;
            string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value;

            string elementPath = ConfigurationManager.AppSettings["elementPath"];
            FileManagement fileLoad = new FileManagement();
            HttpPostedFileBase file = Request.Files["Filedata"];
            string fileName = string.Empty;
            string fileExtention = string.Empty;
            string[] Mappath = new string[2];
            fileName = fileLoad.NewFileName(file.FileName);
            fileName = fileName.Substring(0, fileName.LastIndexOf("."));
            fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower();
            string localElePath = imgLocalPath + elementPath;
            string returnName = imgServerPath;////"http://192.168.71.159:8080"
            bool result = false;
            string NewFileName = string.Empty;
            BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
            NewFileName = hash.Md5Encrypt(fileName, "32");
            string firstFolder = NewFileName.Substring(0, 2) + "/";
            string secondFolder = NewFileName.Substring(2, 2) + "/";
            string ServerPath = string.Empty;
            Mappath[0] = firstFolder;
            Mappath[1] = secondFolder;
            //CreateFolder(localElePath, Mappath);
            //   localElePath += firstFolder + secondFolder;
            //  elementPath += firstFolder + secondFolder;
            returnName += elementPath + NewFileName + fileExtention;
            NewFileName = localElePath + NewFileName + fileExtention;
            ServerPath = Server.MapPath(imgLocalServerPath + elementPath);
            string ErrorMsg = string.Empty;
            try
            {
                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
            }
            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);
            }
            if (string.IsNullOrEmpty(ErrorMsg))
            {
                ViewBag.fileName = returnName;
                ViewBag.Type = "pic";
            }
            else
            {
                ViewBag.fileName = "ERROR/" + ErrorMsg;
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = "ERROR/" + ErrorMsg;
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);

            }
            return View("~/Views/PromotionsAmountTrial/upLoad.cshtml");
        }
Пример #11
0
 public HttpResponseBase OrderTemplate()
 {
     siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
     SiteConfig config = siteConfigMgr.GetConfigByName("Template_OrderImport_Path");
     if (config != null)
     {
         string template = Server.MapPath(string.IsNullOrEmpty(config.Value) ? config.DefaultValue : config.Value);
         if (System.IO.File.Exists(template))
         {
             this.Response.Clear();
             this.Response.ContentType = "application/ms-excel";
             this.Response.AppendHeader("Content-Disposition", "attachment;filename=t_orders.xlsx");
             this.Response.WriteFile(template);
             this.Response.End();
         }
     }
     return this.Response;
 }
Пример #12
0
        public JsonResult ReadExcelFile()
        {
            List<OrdersImport> orders = new List<OrdersImport>();
            Session["import"] = null;
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["Files"]) && !string.IsNullOrEmpty(Request.Form["ImportType"]) && !string.IsNullOrEmpty(Request.Form["Channel"]))
                {
                    string improtType = Request.Form["ImportType"];
                    int channel = Convert.ToInt32(Request.Form["Channel"]);
                    string excelFile = Server.MapPath(excelPath) + Request.Form["Files"].Split('|')[0];

                    Resource.CoreMessage = new CoreResource("OrderImport");
                    orderImport = OrderImportFactory.InitOrderImport(channel);

                    siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
                    SiteConfig config = siteConfigMgr.GetConfigByName("Template_OrderImport_Path");
                    if (orderImport != null && config != null)
                    {
                        string template = Server.MapPath(string.IsNullOrEmpty(config.Value) ? config.DefaultValue : config.Value);
                        if (System.IO.File.Exists(template))
                        {
                            orders = orderImport.ReadExcel2Page(excelFile, template, orderImport.CurChannel.model_in);
                            Session["import"] = orders;
                        }
                    }
                }
            }
            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);
            }
            return Json(orders);
        }
Пример #13
0
        public HttpResponseBase SaveImportFile()
        {
            Session["import"] = null;
            string json = "{success:false}";
            siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
            try
            {
                if (Request.Files["channelFile"] != null && Request.Files["channelFile"].ContentLength > 0)
                {
                    HttpPostedFileBase excelFile = Request.Files["channelFile"];

                    FileManagement fileManagement = new FileManagement();
                    string newExcelName = fileManagement.NewFileName(excelFile.FileName);
                    string oldExcelName = excelFile.FileName.Split('\\').LastOrDefault();

                    #region Excel文件限制

                    SiteConfig excellConfig = siteConfigMgr.GetConfigByName("Excel_Extension_Filter");
                    string excelEx = string.IsNullOrEmpty(excellConfig.Value) ? excellConfig.DefaultValue : excellConfig.Value;

                    SiteConfig minConfig = siteConfigMgr.GetConfigByName("Excel_Length_Min");
                    SiteConfig maxConfig = siteConfigMgr.GetConfigByName("Excel_Length_Max");
                    int excelMin = Convert.ToInt32(DataCheck.IsNumeric(minConfig.Value) ? minConfig.Value : minConfig.DefaultValue);
                    int excelMax = Convert.ToInt32(DataCheck.IsNumeric(maxConfig.Value) ? maxConfig.Value : maxConfig.DefaultValue);
                    #endregion
                    Resource.CoreMessage = new CoreResource("Product");
                    if (fileManagement.UpLoadFile(excelFile, Server.MapPath(excelPath) + "/" + newExcelName, excelEx, excelMax, excelMin))//保存導入訂單excel文件
                    {
                        if (!string.IsNullOrEmpty(Request.Form["importType"]) && Request.Form["importType"] == "2")
                        {
                            if (Request.Files["dispatch"] != null && Request.Files["dispatch"].ContentLength > 0)
                            {
                                HttpPostedFileBase dispatchFile = Request.Files["dispatch"];

                                string newPDFName = fileManagement.NewFileName(dispatchFile.FileName);

                                #region PDF文件限制

                                SiteConfig pdfConfig = siteConfigMgr.GetConfigByName("PDF_Extension_Filter");
                                string pdfEx = string.IsNullOrEmpty(pdfConfig.Value) ? pdfConfig.DefaultValue : pdfConfig.Value;

                                minConfig = siteConfigMgr.GetConfigByName("PDF_Length_Min");
                                maxConfig = siteConfigMgr.GetConfigByName("PDF_Length_Max");
                                int pdfMin = Convert.ToInt32(DataCheck.IsNumeric(minConfig.Value) ? minConfig.Value : minConfig.DefaultValue);
                                int pdfMax = Convert.ToInt32(DataCheck.IsNumeric(maxConfig.Value) ? maxConfig.Value : maxConfig.DefaultValue);
                                #endregion

                                if (fileManagement.UpLoadFile(dispatchFile, Server.MapPath(pdfPath) + "/" + newPDFName, pdfEx, pdfMax, pdfMin))//保存選擇 ‘超商取貨’ 時需上傳的取貨單文件
                                {
                                    json = "{success:true,msg:\"" + newExcelName + "|" + oldExcelName + "|" + newPDFName + "\"}";
                                }
                            }
                        }
                        else
                        {
                            json = "{success:true,msg:\"" + newExcelName + "|" + oldExcelName + "\"}";
                        }
                    }
                }
            }
            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);
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
 public HttpResponseBase ProductPreview()
 {
     _siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
     _pMaster = new PriceMasterMgr(connectionString);
     List<SiteConfig> configList = _siteConfigMgr.Query();
     PriceMaster Pm = new PriceMaster();
     BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
     string DomainName = configList.Where(m => m.Name.Equals("DoMain_Name")).FirstOrDefault().Value;
     string json = string.Empty;
     try
     {
         if (!string.IsNullOrEmpty(Request.Form["Product_Id"]))//商品ID
         {
             string type = Request.Form["Type"];
             string product_id = Request.Form["Product_Id"].ToString();
             string site_id = Request.Form["Site_Id"] == null ? "" : Request.Form["Site_Id"].ToString();
             string user_level = Request.Form["Level"] == null ? "" : Request.Form["Level"].ToString();
             string user_id = Request.Form["Master_User_Id"] == null ? "" : Request.Form["Master_User_Id"].ToString();
             string result = "";
             if (type == "0")
             {
                 result += "http://" + DomainName + "/product.php?pid=" + product_id + "&view=" + DateTime.Now.ToString("yyyyMMdd");//商品預覽
             }
             if (type == "1")
             {
                 //商品預覽+價格頁面
                 result += "http://" + DomainName + "/product.php?pid=" + product_id + "&view=" + DateTime.Now.ToString("yyyyMMdd") + "&sid=" + site_id + "&ulv=" + user_level + "&uid=" + user_id + "&view=" + DateTime.Now.ToString("yyyyMMdd");
                 result += "|";
                 result += "http://" + DomainName + "/product.php?pid=" + product_id + "&sid=" + site_id + "&code=" + hash.Md5Encrypt(product_id + "&sid=" + site_id, "32");//商品隱賣連結: + "&ulv=" + user_level
             }
             json = result.ToString().ToLower();
         }
     }
     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 = "無預覽信息";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
Пример #15
0
        public ActionResult upLoadImg()
        {
            BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];//獲取當前登入的供應商
            int writerID = (int)vendorModel.vendor_id;

            string path = Server.MapPath(xmlPath);
            siteConfigMgr = new SiteConfigMgr(path);
            ViewBag.moreFileOneTime = false;
            SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format");
            SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue");
            SiteConfig maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
            SiteConfig admin_userName = siteConfigMgr.GetConfigByName("ADMIN_USERNAME");
            SiteConfig admin_passwd = siteConfigMgr.GetConfigByName("ADMIN_PASSWD");

            string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value;
            string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value;
            string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value;

            string localProdPath = imgLocalPath + prodPath;
            //string localProd50Path = imgLocalPath + prod50Path;
            //string localProd150Path = imgLocalPath + prod150Path;
            //string localProd280Path = imgLocalPath + prod280Path;

            string localSpecPath = imgLocalPath + specPath;
            //string localSpec100Path = imgLocalPath + spec100Path;
            //string localSpec280Path = imgLocalPath + spec280Path;


            string localDescPath = imgLocalPath + descPath;
            //string localDesc400Path = imgLocalPath + desc400Path;
            string[] Mappath = new string[2];

            FileManagement fileLoad = new FileManagement();

            HttpPostedFileBase file = Request.Files["Filedata"];
            string nameType = Request.Params["nameType"];
            string fileName = string.Empty;
            string fileExtention = string.Empty;
            ViewBag.spec_id = -1;
            if (nameType != null)
            {
                fileName = nameType + fileLoad.NewFileName(file.FileName);
                fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower();

            }
            else
            {
                #region 批次上傳圖片操作
                //此處由批次上傳進入.
                //判斷文件名格式是否正確
                ViewBag.moreFileOneTime = true;
                int prodCheck = file.FileName.LastIndexOf("prod_");
                int specCheck = file.FileName.LastIndexOf("spec_");
                int descCheck = file.FileName.LastIndexOf("desc_");
                string errorMsg = "ERROR/";
                if (prodCheck == -1 && specCheck == -1 && descCheck == -1)
                {
                    errorMsg += "[" + file.FileName + "] ";
                    errorMsg += Resources.VendorProduct.FILE_NAME_ERROR;

                    ViewBag.fileName = errorMsg;
                    return View("~/Views/VendorProduct/upLoad.cshtml");
                }
                else
                {
                    nameType = file.FileName.Split('_')[0];
                    fileName = nameType + fileLoad.NewFileName(file.FileName);
                    fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                    fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.'));
                }
                if (specCheck == 0)
                {
                    //Caller _caller = (Session["caller"] as Caller);
                    ProductSpecTemp proSpecTemp = new ProductSpecTemp();
                    string spec = file.FileName.Split('_')[1].Split('.')[0];
                    bool checkStatus = true;
                    if (!string.IsNullOrEmpty(Request.Params["product_id"].Split(';')[0].ToString()))
                    {
                        //product_spec
                        proSpecTemp.product_id = Request.Params["product_id"].Split(';')[0].ToString();
                    }
                    //product_spec_temp
                    _specTempMgr = new ProductSpecTempMgr(connectionString);

                    List<ProductSpecTemp> pSpecTempList = _specTempMgr.VendorQuery(new ProductSpecTemp { Writer_Id = writerID, spec_type = 1 });
                    foreach (var item in pSpecTempList)
                    {
                        if (item.spec_name == spec)
                        {
                            checkStatus = false;
                            ViewBag.spec_id = item.spec_id;
                        }
                    }
                    if (checkStatus)//表示沒有要上傳圖片規格相同的規格一
                    {
                        errorMsg += "[" + file.FileName + "] " + Resources.VendorProduct.SPEC_NOT_FIND;
                        ViewBag.fileName = errorMsg;
                        return View("~/Views/VendorProduct/upLoad.cshtml");
                    }
                }
                #endregion
            }

            string returnName = imgServerPath;


            bool result = false;
            string NewFileName = string.Empty;


            BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
            NewFileName = hash.Md5Encrypt(fileName, "32");

            string firstFolder = NewFileName.Substring(0, 2) + "/";
            string secondFolder = NewFileName.Substring(2, 2) + "/";
            string ServerPath = string.Empty;

            if (nameType == "spec")
            {
                Mappath[0] = firstFolder;
                Mappath[1] = secondFolder;

                CreateFolder(localSpecPath, Mappath);
                //CreateFolder(localSpec100Path, Mappath);
                //CreateFolder(localSpec280Path, Mappath);

                localSpecPath += firstFolder + secondFolder;
                //localSpec100Path += firstFolder + secondFolder;
                //localSpec280Path += firstFolder + secondFolder;
                specPath += firstFolder + secondFolder;

                returnName += specPath + NewFileName + fileExtention;
                //localSpec100Path += NewFileName + fileExtention;
                //localSpec280Path += NewFileName + fileExtention;
                NewFileName = localSpecPath + NewFileName + fileExtention;
                ServerPath = Server.MapPath(imgLocalServerPath + specPath);

            }
            else if (nameType == "desc")
            {

                Mappath[0] = firstFolder;
                Mappath[1] = secondFolder;

                CreateFolder(localDescPath, Mappath);
                //CreateFolder(localDesc400Path, Mappath);

                localDescPath += firstFolder + secondFolder;
                //localDesc400Path += firstFolder + secondFolder;
                descPath += firstFolder + secondFolder;

                //localDesc400Path += NewFileName + fileExtention;
                returnName += descPath + NewFileName + fileExtention;
                NewFileName = localDescPath + NewFileName + fileExtention;
                ServerPath = Server.MapPath(imgLocalServerPath + descPath);
            }
            else
            {
                Mappath[0] = firstFolder;
                Mappath[1] = secondFolder;
                //Data:2014/06/26
                //author:Castle
                //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!!
                CreateFolder(localProdPath, Mappath);
                //CreateFolder(localProd50Path, Mappath);
                //CreateFolder(localProd150Path, Mappath);
                //CreateFolder(localProd280Path, Mappath);

                localProdPath += firstFolder + secondFolder;
                //localProd50Path += firstFolder + secondFolder;
                //localProd150Path += firstFolder + secondFolder;
                //localProd280Path += firstFolder + secondFolder;
                prodPath += firstFolder + secondFolder;
                //localProd50Path += NewFileName + fileExtention;
                //localProd150Path += NewFileName + fileExtention;
                //localProd280Path += NewFileName + fileExtention;
                returnName += prodPath + NewFileName + fileExtention;

                NewFileName = localProdPath + NewFileName + fileExtention;
                ServerPath = Server.MapPath(imgLocalServerPath + prodPath);
            }
            string ErrorMsg = string.Empty;
            Resource.CoreMessage = new CoreResource("VendorProduct");
            try
            {
                //上傳圖片

                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                //上傳對應大小圖片
                //压缩图片至其它规格
            }
            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);
            }
            if (string.IsNullOrEmpty(ErrorMsg))
            {
                ViewBag.fileName = returnName;
            }
            else
            {
                ViewBag.fileName = "ERROR/" + ErrorMsg;
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = "ERROR/" + ErrorMsg;
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);

            }
            return View("~/Views/VendorProduct/upLoad.cshtml");
        }
Пример #16
0
        public HttpResponseBase CheckStockAlarm()
        {
            _viewAlarmMgr = new ViewCheckAlarmMgr(connectionString);
            _paraMgr = new ParameterMgr(connectionString);
            _siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
            string msg = string.Empty;
            try
            {
                string from = string.Empty, status = string.Empty, host = string.Empty, username = string.Empty, userpasswd = string.Empty, mailport = string.Empty;

                //讀取XML中有關通知參數
                List<SiteConfig> configList = _siteConfigMgr.Query();
                if (configList.Count() > 0)
                {
                    from = configList.Where(m => m.Name.Equals("Mail_From")).FirstOrDefault().Value;
                    host = configList.Where(m => m.Name.Equals("Mail_Host")).FirstOrDefault().Value;
                    username = configList.Where(m => m.Name.Equals("Mail_UserName")).FirstOrDefault().Value;
                    userpasswd = configList.Where(m => m.Name.Equals("Mail_UserPasswd")).FirstOrDefault().Value;
                    mailport = configList.Where(m => m.Name.Equals("Mail_Port")).FirstOrDefault().Value;
                }


                string subject = Resources.VendorProduct.MAIL_SUBJECT;
                string body = _viewAlarmMgr.QueryStockAlarm();
                if (body == "") status = "2";
                StringBuilder strXml = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?><mail>");
                strXml.AppendFormat("<status>{0}</status>", status);//0 關閉,1 正常, 2 無資料,3 服務器異常
                strXml.AppendFormat("<mailfrom>{0}</mailfrom>", from);
                strXml.AppendFormat("<mailsubject>{0}</mailsubject>", subject);
                strXml.AppendFormat("<mailhost>{0}</mailhost>", host);
                strXml.AppendFormat("<mailusername>{0}</mailusername>", username);
                strXml.AppendFormat("<mailuserpasswd>{0}</mailuserpasswd>", userpasswd);
                strXml.AppendFormat("<mailport>{0}</mailport>", mailport);
                strXml.AppendFormat("<mailbody>{0}</mailbody>", HttpUtility.HtmlEncode(body));
                strXml.Append("</mail>");
                msg = strXml.ToString();
            }
            catch (Exception)
            {
                msg = "<mail><status>3</status></mail>";
            }

            this.Response.Clear();
            this.Response.Write(msg);
            this.Response.End();
            return this.Response;
        }
Пример #17
0
        //  [HttpPost]
        public HttpResponseBase SaveVipUserGroup()
        {
            NameValueCollection param = Request.Params;
            VipUserGroup userGroup = new VipUserGroup();
            string json = string.Empty;
            bool size = true;
            Serial serial = new Serial();
            _userGroupMgr = new VipUserGroupMgr(mySqlConnectionString);
            _ISerImplMgr = new SerialMgr(mySqlConnectionString);
            serial = _ISerImplMgr.GetSerialById(72);
            string path = Server.MapPath(xmlPath);
            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
            SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format");
            SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MinValue");
            SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
            SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME");
            SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD");
            //擴展名、最小值、最大值
            string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value;
            string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value;
            string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value;
            string localPromoPath = imgLocalPath + promoPath;//圖片存儲地址
            Random rand = new Random();
            int newRand = rand.Next(1000, 9999);

            string NewName = string.Empty;//當前文件名
            string fileExtention = string.Empty;//當前文件的擴展名
            string NewFileName = string.Empty;
            FileManagement fileLoad = new FileManagement();
            try
            {
                #region 新增
                if (String.IsNullOrEmpty(param["group_id"]))
                {
                    if (!string.IsNullOrEmpty(Request.Form["group_name"]))
                    {
                        userGroup.group_name = Request.Form["group_name"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["tax_id"]))
                    {
                        userGroup.tax_id = Request.Form["tax_id"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["eng_name"]))
                    {
                        userGroup.eng_name = Request.Form["eng_name"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["gift_bonus"]))
                    {
                        userGroup.gift_bonus = Convert.ToUInt32(Request.Form["gift_bonus"]);
                    }
                    if (!string.IsNullOrEmpty(Request.Form["group_category"]))
                    {
                        userGroup.group_category = Convert.ToUInt32(Request.Form["group_category"]);
                    }

                    siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
                    try
                    {
                        if (Request.Files["image_name"] != null && Request.Files["image_name"].ContentLength > 0)
                        {
                            HttpPostedFileBase file = Request.Files["image_name"];
                            if (file.ContentLength > int.Parse(minValue) * 1024 && file.ContentLength < int.Parse(maxValue) * 1024)
                            {
                                NewName = Path.GetFileName(file.FileName);
                                bool result = false;
                                //獲得文件的後綴名
                                fileExtention = NewName.Substring(NewName.LastIndexOf(".")).ToLower();
                                //新的文件名是隨機數字
                                BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                                NewFileName = hash.Md5Encrypt(newRand.ToString(), "32") + fileExtention;
                                NewName = NewFileName;
                                string ServerPath = string.Empty;
                                //判斷目錄是否存在,不存在則創建
                                string[] mapPath = new string[1];
                                mapPath[0] = promoPath.Substring(1, promoPath.Length - 2);
                                string jian = localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1);
                                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), mapPath);
                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                string ErrorMsg = string.Empty;
                                //上傳
                                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                if (result)
                                {
                                    userGroup.image_name = NewName;
                                }

                            }
                            else
                            {
                                size = false;
                            }
                        }

                    }

                    catch (Exception)
                    {
                        userGroup.image_name = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["check_iden"]))
                    {
                        userGroup.check_iden = int.Parse(Request.Params["check_iden"]);
                    }
                    userGroup.createdate = (uint)CommonFunction.GetPHPTime(DateTime.Now.ToString());
                    userGroup.group_id = uint.Parse((serial.Serial_Value + 1).ToString());
                    if (_userGroupMgr.Insert(userGroup) > 0)
                    {
                        serial.Serial_Value = serial.Serial_Value + 1;/*所在操作表的列增加*/
                        _ISerImplMgr.Update(serial);/*修改所在的表的列對應的值*/
                        if (size)
                        {
                            json = "{success:true,msg:\"" + "" + "\"}";
                        }
                        else
                        {
                            json = "{success:true,msg:\"" + " 文件大小應大於1KB小於100KB!" + "\"}";
                        }
                    }
                    else
                    {
                        json = "{success:false,msg:\"" + "新增失敗!" + "\"}";
                    }

                }
                #endregion
                #region 編輯
                else
                {
                    _userGroupMgr = new VipUserGroupMgr(mySqlConnectionString);
                    userGroup.group_id = Convert.ToUInt32(param["group_id"]);
                    VipUserGroup oldUserGroup = _userGroupMgr.GetModelById(userGroup.group_id);
                    if (!string.IsNullOrEmpty(Request.Form["group_name"]))
                    {
                        userGroup.group_name = Request.Form["group_name"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["tax_id"]))
                    {
                        userGroup.tax_id = Request.Form["tax_id"].ToString();
                    }

                    if (!string.IsNullOrEmpty(Request.Form["eng_name"]))
                    {
                        userGroup.eng_name = Request.Form["eng_name"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["gift_bonus"]))
                    {
                        userGroup.gift_bonus = Convert.ToUInt32(Request.Form["gift_bonus"]);
                    }
                    if (!string.IsNullOrEmpty(Request.Form["group_category"]))
                    {
                        userGroup.group_category = Convert.ToUInt32(Request.Form["group_category"]);
                    }
                    try
                    {
                        //如果圖片沒有改變
                        if (Request.Form["image_name"] == oldUserGroup.image_name)
                        {
                            userGroup.image_name = Request.Form["image_name"];
                        }
                        else
                        {
                            //圖片改變了
                            if (Request.Files["image_name"] != null && Request.Files["image_name"].ContentLength > 0)
                            {
                                HttpPostedFileBase file = Request.Files["image_name"];
                                if (file.ContentLength > int.Parse(minValue) * 1024 && file.ContentLength < int.Parse(maxValue) * 1024)
                                {
                                    NewName = Path.GetFileName(file.FileName);
                                    bool result = false;

                                    //獲得文件的後綴名
                                    fileExtention = NewName.Substring(NewName.LastIndexOf(".")).ToLower();
                                    //新的文件名是隨機數字
                                    BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                                    NewFileName = hash.Md5Encrypt(newRand.ToString(), "32") + fileExtention;
                                    NewName = NewFileName;
                                    string ServerPath = string.Empty;
                                    //判斷目錄是否存在,不存在則創建
                                    string[] mapPath = new string[1];
                                    mapPath[0] = promoPath.Substring(1, promoPath.Length - 2);
                                    string jian = localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1);
                                    CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), mapPath);
                                    //  returnName += promoPath + NewFileName;
                                    NewFileName = localPromoPath + NewFileName;//絕對路徑
                                    ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                    string ErrorMsg = string.Empty;
                                    //上傳之前刪除已有的圖片
                                    string oldFileName = oldUserGroup.image_name;
                                    //FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                                    //List<string> tem = ftp.GetFileList();
                                    //上傳
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)
                                    {
                                        userGroup.image_name = NewName;

                                        if (System.IO.File.Exists(ServerPath + oldFileName))
                                        {
                                            FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd);
                                            if (System.IO.File.Exists(localPromoPath + oldFileName))
                                            {
                                                ftps.DeleteFile(localPromoPath + oldFileName);//刪除ftp:71.159上的舊圖片
                                            }
                                            DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                        }
                                    }
                                    else
                                    {
                                        userGroup.image_name = oldUserGroup.image_name;
                                    }
                                }
                                else
                                {
                                    size = false;
                                    userGroup.image_name = oldUserGroup.image_name;
                                }
                            }
                        }
                    }

                    catch (Exception)
                    {
                        userGroup.image_name = oldUserGroup.image_name;
                    }
                    try
                    {
                        userGroup.check_iden = int.Parse(Request.Params["check_iden"]);
                    }
                    catch (Exception)
                    {
                        userGroup.check_iden = 0;
                    }
                    if (_userGroupMgr.Update(userGroup) > 0)
                    {
                        if (size)
                        {
                            json = "{success:true,msg:\"" + "" + "\"}";
                        }
                        else
                        {
                            json = "{success:true,msg:\"" + " 文件大小應大於1KB小於100KB!" + "\"}";
                        }
                    }
                    else
                    {
                        json = "{success:false,msg:\"" + "修改失敗!" + "\"}";
                    }

                }
                #endregion
            }
            catch (Exception ex)
            {
                json = "{success:false,msg:\"" + "異常" + "\"}";
                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);

            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;

        }
Пример #18
0
        /// <summary>
        /// 記得在這裡加上xml請求時 必須去 Admin.gigade\Module\ActionFilter.cs 文件中加上判斷不然每次都會提示登錄過期
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase GetXmlInfo()
        {
            string msg = string.Empty;
            try
            {
                //公共的
                _paraMgr = new ParameterMgr(connectionString);
                _siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
                List<Parametersrc> listP = _paraMgr.QueryType("");
                string to = string.Empty, sendtime = string.Empty, status = string.Empty, HttpPath = string.Empty;
                //根據parameterType數量來循環
                if (listP.Count > 0)
                {
                    string getHttp = "http://" + HttpContext.Request.Url.Authority.ToString() + "/Notification/";
                    StringBuilder strXml = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
                    for (int i = 0, j = listP.Count; i < j; i++)
                    {
                        string type = listP[i].ParameterType;
                        //讀取數據庫中收件人與通知狀態
                        List<Parametersrc> pList = _paraMgr.QueryUsed(new Parametersrc { ParameterType = type });
                        switch (type)
                        {
                            #region 根據不同的type來處理
                            case "warn_stock":
                                to = pList.Where(rec => rec.parameterName == "sendTo").FirstOrDefault().ParameterCode;
                                to = to.Replace("\n", "");
                                sendtime = pList.Where(rec => rec.parameterName == "sendTime").FirstOrDefault().ParameterCode;
                                sendtime = sendtime.Replace("\n", "");
                                status = pList.Where(rec => rec.parameterName == "switch").FirstOrDefault().ParameterCode;
                                HttpPath = "CheckStockAlarm";

                                strXml.Append("<mail>");
                                strXml.AppendFormat("<status>{0}</status>", status);//0 關閉,1 正常, 2 無資料,3 服務器異常
                                strXml.AppendFormat("<mailto>{0}</mailto>", to);
                                strXml.AppendFormat("<sendTime>{0}</sendTime>", sendtime);
                                strXml.AppendFormat("<getHttp>{0}</getHttp>", getHttp);//網站的IP地址+controller
                                strXml.AppendFormat("<HttpPath>{0}</HttpPath>", HttpPath);//function
                                strXml.Append("</mail>");
                                break;
                            case "warn_product":
                                to = pList.Where(rec => rec.parameterName == "sendTo").FirstOrDefault().ParameterCode;
                                to = to.Replace("\n", "");
                                sendtime = pList.Where(rec => rec.parameterName == "sendTime").FirstOrDefault().ParameterCode;
                                sendtime = sendtime.Replace("\n", "");
                                status = pList.Where(rec => rec.parameterName == "switch").FirstOrDefault().ParameterCode;
                                HttpPath = "ProductUpdateNotice";

                                strXml.Append("<mail>");
                                strXml.AppendFormat("<status>{0}</status>", status);//0 關閉,1 正常, 2 無資料,3 服務器異常
                                strXml.AppendFormat("<mailto>{0}</mailto>", to);
                                strXml.AppendFormat("<sendTime>{0}</sendTime>", sendtime);
                                strXml.AppendFormat("<getHttp>{0}</getHttp>", getHttp);//網站的IP地址+controller
                                strXml.AppendFormat("<HttpPath>{0}</HttpPath>", HttpPath);//function
                                strXml.Append("</mail>");
                                break;
                            case "warn_productMap":
                                to = pList.Where(rec => rec.parameterName == "sendTo").FirstOrDefault().ParameterCode;
                                to = to.Replace("\n", "");
                                sendtime = pList.Where(rec => rec.parameterName == "sendTime").FirstOrDefault().ParameterCode;
                                sendtime = sendtime.Replace("\n", "");
                                status = pList.Where(rec => rec.parameterName == "switch").FirstOrDefault().ParameterCode;
                                HttpPath = "ProductItemUpdateNotice";

                                strXml.Append("<mail>");
                                strXml.AppendFormat("<status>{0}</status>", status);//0 關閉,1 正常, 2 無資料,3 服務器異常
                                strXml.AppendFormat("<mailto>{0}</mailto>", to);
                                strXml.AppendFormat("<sendTime>{0}</sendTime>", sendtime);
                                strXml.AppendFormat("<getHttp>{0}</getHttp>", getHttp);//網站的IP地址+controller
                                strXml.AppendFormat("<HttpPath>{0}</HttpPath>", HttpPath);//function
                                strXml.Append("</mail>");
                                break;
                            #endregion
                        }
                    }
                    strXml.Append("</root>");
                    msg = strXml.ToString();
                }
                else
                {
                    msg = "<mail><status>3</status><msg>paras are not set.</msg></mail>";
                }
            }
            catch
            {
                msg = "<mail><status>3</status></mail>";
            }
            this.Response.Clear();
            this.Response.Write(msg);
            this.Response.End();
            return this.Response;
        }
Пример #19
0
        public HttpResponseBase ImportCsv()
        {
            string json = "";
            string errorMsg = "";
            string repeatMsg = "";
            _userGroupMgr = new VipUserGroupMgr(mySqlConnectionString);
            string sqlwhere = string.Empty;
            VipUser query = new VipUser();

            int add = 0;
            int repeat = 0;
            int error = 0;
            string newCSVName = string.Empty;
            string check_iden = string.Empty;
            List<string> emp_id = new List<string>();
            if (!string.IsNullOrEmpty(Request.Params["group_id"]))
            {
                query.group_id = Convert.ToUInt32(Request.Params["group_id"]);
            }
            if (!string.IsNullOrEmpty(Request.Params["check_iden"]))
            {
                check_iden = Request.Params["check_iden"];
            }

            siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
            try
            {
                if (Request.Files["ImportCsvFile"] != null && Request.Files["ImportCsvFile"].ContentLength > 0)
                {
                    //一些文件的方法,包括获取文件的类型、长度、保存
                    HttpPostedFileBase excelFile = Request.Files["ImportCsvFile"];
                    //自定义的类,其中包括一些文件的处理方法
                    FileManagement fileManagement = new FileManagement();

                    //文件重命名,然後設置存儲的路徑
                    newCSVName = Server.MapPath(excelPath) + "user_io" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名
                    System.Data.DataTable _dt = new DataTable();
                    excelFile.SaveAs(newCSVName);//
                    _dt = CsvHelper.ReadCsvToDataTable(newCSVName, true);
                    //匯入員工編號
                    DataTable btopEmp = _userGroupMgr.BtobEmp(query.group_id.ToString());
                    for (int k = 0; k < btopEmp.Rows.Count; k++)
                    {
                        if (!string.IsNullOrEmpty(btopEmp.Rows[k]["emp_id"].ToString()))
                        {
                            emp_id.Add(btopEmp.Rows[k]["emp_id"].ToString());
                        }
                    }

                    //郵箱的格式
                    Regex num = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        //只讀第一列,其餘列忽略 
                        for (int j = 0; j < 1; j++)
                        {
                            //匯入員工編號
                            if (!string.IsNullOrEmpty(check_iden))
                            {
                                int u1 = _userGroupMgr.UpdateEmp(query.group_id.ToString(), _dt.Rows[i][j].ToString(), 1);
                                if (emp_id.Contains(_dt.Rows[i][j].ToString()))
                                {
                                    int u2 = _userGroupMgr.UpdateEmp(query.group_id.ToString(), _dt.Rows[i][j].ToString(), 2);
                                    json = "{success:true,msg:\"" + "上傳成功!" + "\"}";
                                }
                                else
                                {
                                    int h = _userGroupMgr.InsertEmp(query.group_id.ToString(), _dt.Rows[i][j].ToString());
                                    json = "{success:true,msg:\"" + "上傳成功!" + "\"}";
                                }
                            }
                            //匯入郵箱
                            else
                            {
                                //郵箱的格式驗證
                                if (!num.IsMatch(_dt.Rows[i][j].ToString()))
                                {
                                    errorMsg += "<br/>第" + (i + 1) + "條第" + (j + 1) + "列數據錯誤";
                                    error++;
                                }
                                else
                                {
                                    sqlwhere = _dt.Rows[i][j].ToString();
                                    DataTable dtUser = _userGroupMgr.GetUser(sqlwhere);
                                    //判斷郵箱是否是存在于users表中
                                    if (dtUser.Rows.Count > 0)
                                    {
                                        query.user_email = _dt.Rows[i][j].ToString();
                                        DataTable VipUserExist = _userGroupMgr.GetVipUser(query);
                                        //根據郵箱和group_id來判斷vip_user表中是否存在此數據,若不存在,就添加,若存在,就不添加
                                        if (VipUserExist.Rows.Count == 0)
                                        {
                                            query.vuser_email = _dt.Rows[i][j].ToString();
                                            query.createdate = (uint)CommonFunction.GetPHPTime(DateTime.Now.ToString());
                                            if (!string.IsNullOrEmpty(dtUser.Rows[0][0].ToString()))
                                            {
                                                query.User_Id = Convert.ToUInt32(dtUser.Rows[0][0]);
                                            }
                                            int k = _userGroupMgr.InsertVipUser(query);
                                            if (k > 0)
                                            {
                                                add++;
                                            }
                                        }
                                        else
                                        {
                                            //json = "{success:false,msg:\"" + "第" + i + 1 + "條第" + j + "列數據重複" + "\"}";
                                            repeatMsg += "<br/>第" + (i + 1) + "條第" + (j + 1) + "列數據重複";
                                            repeat++;
                                        }
                                    }
                                    else
                                    {
                                        //json = "{success:false,msg:\"" + "第" + i + 1 + "條第" + j + "列數據錯誤" + "\"}";
                                        errorMsg += "<br/>第" + (i + 1) + "條第" + (j + 1) + "列數據錯誤";
                                        error++;
                                    }


                                }
                            }
                        }
                    }

                    //string[] colname = new string[_dt.Columns.Count];
                    //for (int i = 0; i < _dt.Columns.Count; i++)
                    //{
                    //    colname[i] = _dt.Columns[i].ColumnName;
                    //}
                    //CsvHelper.ExportDataTableToCsv(_dt, newExcelName, colname, true);


                    json = "{success:true,msg:\"" + errorMsg + repeatMsg + "<br/>" + "上傳成功!<br/>新增:" + add + "<br/>重複:" + repeat + "<br/>錯誤:" + error + "<br/>總計:" + _dt.Rows.Count + "\"}";

                }

                else
                {
                    json = "{success:false,msg:\"" + "請匯入檔案" + "\"}";
                }
            }
            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);
                //出現異常后,刪除上傳的文件
                if (System.IO.File.Exists(newCSVName))
                {
                    //設置文件的屬性,以防刪除文件的時候因為文件的屬性造成無法刪除
                    System.IO.File.SetAttributes(newCSVName, FileAttributes.Normal);
                    System.IO.File.Delete(newCSVName);
                }
                json = "{success:false,msg:\"" + errorMsg + repeatMsg + "上傳失敗!" + "\"}";
            }

            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Пример #20
0
        public ActionResult upLoadImg()
        {
            HttpPostedFileBase file = Request.Files["Filedata"];
            int type = Request["appOrexplain"] == null ? 0 : Convert.ToInt32(Request["appOrexplain"]);
            string nameType = Request.Params["nameType"];// 將 nametype 提前 使其判斷傳入的圖片是否為商品主圖 edit by zhuoqin0830w 2015/01/29
            int prodCheck = file.FileName.LastIndexOf("prod_");// 將 proCheck 提前 使其判斷批量上傳的圖片中是否存在商品主圖   edit by zhuoqin0830w 2015/01/30
            if (prodCheck == 0 && type == 0)
            {
                type = 3;
            }
            int mobileCheck = file.FileName.LastIndexOf("mobile_");
            if (mobileCheck == 0 && type == 0)
            {
                type = 4;
            }
            string path = Server.MapPath(xmlPath);
            siteConfigMgr = new SiteConfigMgr(path);
            ViewBag.moreFileOneTime = false;
            SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format");
            SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue");
            SiteConfig maxValue_config = null;
            //判斷 批量上傳 或 單個上傳 的圖片是否為 商品主圖 或 手機商品圖  edit by zhuoqin0830w 2015/03/24
            switch (nameType)
            {
                //如果  nameType == prod  則表示 是 單個上傳 商品主圖
                case "prod":
                    maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max");
                    break;
                //如果  nameType == mobile  則表示 是 單個上傳 手機商品圖 
                case "mobile":
                    maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max");
                    break;
                //如果  nameType == null  則表示 是 批量上傳
                case null:
                    //如果  prodCheck == 0  則表示 是 單個上傳 商品主圖 
                    if (prodCheck == 0)
                    {
                        maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max");
                    }
                    //如果  mobileCheck == 0  則表示 是 單個上傳 手機商品圖 
                    else if (mobileCheck == 0)
                    {
                        maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max");
                    }
                    else
                    {
                        maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
                    }
                    break;
                default:
                    maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
                    break;
            }

            SiteConfig admin_userName = siteConfigMgr.GetConfigByName("ADMIN_USERNAME");
            SiteConfig admin_passwd = siteConfigMgr.GetConfigByName("ADMIN_PASSWD");

            string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value;
            string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value;
            string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value;

            if ((nameType == "mobile" && type == 4) || (mobileCheck == 0 && type == 4)) //add by wwei0216w 2015/4/1 添加原因:手機圖片要放在640*640路徑下
            {
                prodPath = prodMobile640;
            }

            string localProdPath = imgLocalPath + prodPath;
            //string localProd50Path = imgLocalPath + prod50Path;
            //string localProd150Path = imgLocalPath + prod150Path;
            //string localProd280Path = imgLocalPath + prod280Path;

            string localSpecPath = imgLocalPath + specPath;
            //string localSpec100Path = imgLocalPath + spec100Path;
            //string localSpec280Path = imgLocalPath + spec280Path;

            string[] Mappath = new string[2];

            FileManagement fileLoad = new FileManagement();

            string fileName = string.Empty;
            string fileExtention = string.Empty;
            ViewBag.spec_id = -1;
            if (nameType != null)
            {
                fileName = nameType + fileLoad.NewFileName(file.FileName);
                fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower();

            }
            else
            {
                #region 批次上傳圖片操作
                //此處由批次上傳進入.
                //判斷文件名格式是否正確
                ViewBag.moreFileOneTime = true;
                //int prodCheck = file.FileName.LastIndexOf("prod_");
                //int specCheck = file.FileName.LastIndexOf("spec_");
                int descCheck = file.FileName.LastIndexOf("desc_");
                int appCheck = file.FileName.LastIndexOf("app_");
                string errorMsg = "ERROR/";
                if (prodCheck == -1 && descCheck == -1 && appCheck == -1 && mobileCheck == -1)
                {
                    errorMsg += "[" + file.FileName + "] ";
                    errorMsg += Resources.Product.FILE_NAME_ERROR;
                    ViewBag.fileName = errorMsg;
                    return View("~/Views/Product/upLoad.cshtml");
                }
                else
                {
                    nameType = file.FileName.Split('_')[0];

                    if (nameType == "app")
                    {
                        type = 2;
                    }
                    else if (nameType == "desc")
                    {
                        type = 1;
                    }
                    fileName = nameType + fileLoad.NewFileName(file.FileName);
                    fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                    fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.'));
                }
                #endregion
            }
            SetPath(type);//設定圖片路徑
            string localDescPath = imgLocalPath + descPath;
            //string localDesc400Path = imgLocalPath + desc400Path;
            string returnName = imgServerPath;

            bool result = false;
            string NewFileName = string.Empty;


            BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
            NewFileName = hash.Md5Encrypt(fileName, "32");

            string firstFolder = NewFileName.Substring(0, 2) + "/";
            string secondFolder = NewFileName.Substring(2, 2) + "/";
            string ServerPath = string.Empty;

            if (nameType == "desc" || nameType == "app")
            {

                Mappath[0] = firstFolder;
                Mappath[1] = secondFolder;

                CreateFolder(localDescPath, Mappath);
                //CreateFolder(localDesc400Path, Mappath);

                localDescPath += firstFolder + secondFolder;

                //localDesc400Path += firstFolder + secondFolder;
                descPath += firstFolder + secondFolder;

                //localDesc400Path += NewFileName + fileExtention;
                returnName += descPath + NewFileName + fileExtention;


                NewFileName = localDescPath + NewFileName + fileExtention;

                ServerPath = Server.MapPath(imgLocalServerPath + descPath);
            }
            else
            {
                Mappath[0] = firstFolder;
                Mappath[1] = secondFolder;
                //Data:2014/06/26
                //author:Castle
                //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!!
                CreateFolder(localProdPath, Mappath);

                localProdPath += firstFolder + secondFolder;

                prodPath += firstFolder + secondFolder;

                returnName += prodPath + NewFileName + fileExtention;
                NewFileName = localProdPath + NewFileName + fileExtention;
                ServerPath = Server.MapPath(imgLocalServerPath + prodPath);
            }
            string ErrorMsg = string.Empty;
            Resource.CoreMessage = new CoreResource("Product");
            try
            {
                //上傳圖片
                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                //上傳對應大小圖片
                //压缩图片至其它规格
            }
            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);
            }
            if (string.IsNullOrEmpty(ErrorMsg))
            {
                ViewBag.fileName = returnName;
                ViewBag.Type = type;

                //獲取文件長度 add by zhuoqin0830w 2015/01/29
                string[] strFile = file.FileName.Split('_');
                //判斷文件名的長度是否大於 1 如果大於 1 則再次進行判斷是否為數字 如果不是則進行強制轉換  
                int image_sort = 0;
                int.TryParse(strFile.Length > 1 ? strFile[1] : "0", out image_sort);
                ViewBag.image_sort = image_sort;
            }
            else
            {
                // 判斷 批量上傳中 是否存在 商品圖 或 手機商品圖  edit by zhuoqin0830w 2015/03/24
                if (prodCheck == 0 || mobileCheck == 0)
                { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; }
                else { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; }

                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = "ERROR/" + ErrorMsg;
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);

            }
            return View("~/Views/Product/upLoad.cshtml");
        }
Пример #21
0
        public bool UpLoadFile(HttpPostedFileBase file, string excelPath, ref string filePath)
        {
            Resource.CoreMessage = new CoreResource("Product");
            siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
            FileManagement fileManagement = new FileManagement();
            string newExcelName = fileManagement.NewFileName(file.FileName);
            string oldExcelName = file.FileName.Split('\\').LastOrDefault();

            #region Excel文件限制
            SiteConfig excellConfig = siteConfigMgr.GetConfigByName("Excel_Extension_Filter");
            string excelEx = string.IsNullOrEmpty(excellConfig.Value) ? excellConfig.DefaultValue : excellConfig.Value;

            SiteConfig minConfig = siteConfigMgr.GetConfigByName("Excel_Length_Min");
            int excelMin = Convert.ToInt32(DataCheck.IsNumeric(minConfig.Value) ? minConfig.Value : minConfig.DefaultValue);

            SiteConfig maxConfig = siteConfigMgr.GetConfigByName("Excel_Length_Max");
            int excelMax = Convert.ToInt32(DataCheck.IsNumeric(maxConfig.Value) ? maxConfig.Value : maxConfig.DefaultValue);
            filePath = Server.MapPath(excelPath) + "/" + newExcelName;
            #endregion
            return fileManagement.UpLoadFile(file, filePath, excelEx, excelMax, 0);//保存導入訂單excel文件
        }