public string aj_FUpload(int id, string filekind, string fileName)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
            #region
            string tpl_File = string.Empty;
            try
            {
                //代表圖片
                if (filekind == "Photo1")
                    handleImageSave(fileName, id, ImageFileUpParm.NewsBasicSingle, filekind, "Activities", "ActivitiesDetail");

                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.FileName = fileName;
            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = ex.Message;
            }
            #endregion
            return defJSON(rAjaxResult);
        }
 public string aj_FSort(int id, string filekind, IList<JsonFileInfo> file_object)
 {
     ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
     rewriteJsonFile(id, filekind, "Banner", "Banner", file_object);
     rAjaxResult.result = true;
     return defJSON(rAjaxResult);
 }
 public string aj_FDelete(int id, string filekind, string filename)
 {
     ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
     DeleteSysFile(id, filekind, filename, ImageFileUpParm.NewsBasicSingle, "Activities", "ActivitiesDetail");
     rAjaxResult.result = true;
     return defJSON(rAjaxResult);
 }
        public string aj_FUpload(int id, string filekind, string fileName)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
            #region
            string tpl_File = string.Empty;
            try
            {
                //廣告圖 4張
                if (filekind == "Photo1")
                    handleImageSave(fileName, id, ImageFileUpParm.BannerRotator, filekind, "Banner", "Banner");

                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.FileName = fileName;
            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = ex.Message;
            }
            #endregion
            return defJSON(rAjaxResult);
        }
 public string aj_FDelete(int id, string filekind, string filename)
 {
     ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
     DeleteSysFile(id, filekind, filename, ImageFileUpParm.BannerRotator, "Banner", "Banner");
     rAjaxResult.result = true;
     return defJSON(rAjaxResult);
 }
示例#6
0
        public string aj_FList(int id, string filekind)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();

            rAjaxResult.filesObject = listDocFiles(id, filekind, "DocManage", "DocManage");
            rAjaxResult.result = true;
            return defJSON(rAjaxResult);
        }
        public string aj_FList(int id, string filekind)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();

            rAjaxResult.filesObject = listImgFiles(id, filekind, "Banner", "Banner");
            rAjaxResult.result = true;
            return defJSON(rAjaxResult);
        }
        public string aj_FList(int id, string filekind)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();

            rAjaxResult.filesObject = ListSysFiles(id, filekind, true, "Activities", "ActivitiesDetail");
            rAjaxResult.result = true;
            return defJSON(rAjaxResult);
        }
 public String aj_FDelete(int id, String FileKind, String FileName)
 {
     ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
     //if (FileKind == "TypeImg")
     //{
     //    DeleteSysFile(id, FileKind, FileName, ImageFileUpParm.NewsBasicSingle, "PT");
     //}
     //else
     //{
     //    DeleteSysFile(id, FileKind, FileName, ImageFileUpParm.NewsBasicSingle);
     //}
     DeleteSysFile(id, FileKind, FileName, ImageFileUpParm.NewsBasicSingle);
     rAjaxResult.result = true;
     return defJSON(rAjaxResult);
 }
        public String aj_FList(int id, String FileKind)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
            //if (FileKind == "TypeImg")
            //{
            //    rAjaxResult.filesObject = ListSysFiles(id, FileKind, "PT");

            //}
            //else
            //{
            //    rAjaxResult.filesObject = ListSysFiles(id, FileKind);
            //}
            rAjaxResult.filesObject = ListSysFiles(id, FileKind);
            rAjaxResult.result = true;
            return defJSON(rAjaxResult);
        }
        public string aj_ApplyfileUpload(HttpPostedFileBase file)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();

            #region
            try
            {
                string FN = file.FileName;
                int id = GetNewId(ProcCore.Business.CodeTable.Apply);
                string filePath = Server.MapPath("~/_Code/SysUpFiles/ApplyData/" + id);
                if (Directory.Exists(filePath))
                {
                    Directory.Delete(filePath, true);
                    Directory.CreateDirectory(filePath);
                }
                else
                {
                    Directory.CreateDirectory(filePath);
                }

                var path = Path.Combine(filePath, FN);
                file.SaveAs(path);

                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.id = id;
                rAjaxResult.FileName = FN;

            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = ex.Message;
            }
            #endregion
            return defJSON(rAjaxResult);
        }
        public string ajax_delFile(int y, string fname, string userid)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
            string uid = string.Empty;
            if (this.LoginUserFlag == "Y")
            {
                uid = this.UserId;
            }
            else
            {
                uid = userid;
            }

            try
            {
                string pathTpl = string.Format("~/_Code/SysUpFiles/Apply.Loading/{0}/{1}", y, uid);
                string serverPath = Server.MapPath(pathTpl);
                if (System.IO.File.Exists(Path.Combine(serverPath, fname)))
                {
                    System.IO.File.Delete(Path.Combine(serverPath, fname));
                }
                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.FileName = fname;
            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = ex.Message;
            }
            return defJSON(rAjaxResult);
        }
        public String aj_FUpload(Int32 id, String FilesKind, HttpPostedFileBase file)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();

            #region
            String tpl_File = String.Empty;
            try
            {
                //代表圖片
                if (FilesKind == "SingleImg")
                    ImageFile(file, id, ImageFileUpParm.NewsBasicSingle, FilesKind);
                //多張圖片
                if (FilesKind == "DoubleImg")
                    ImageFile(file, id, ImageFileUpParm.NewsBasicDouble, FilesKind);

                //if (FilesKind == "TypeImg")
                //    ImageFile(file, id, ImageFileUpParm.NewsBasicSingle, FilesKind, "PT");

                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.FileName = file.FileName;

            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = ex.Message;
            }
            #endregion
            return defJSON(rAjaxResult);
        }
        public string aj_excelEvaporateApplyUploadForTest(HttpPostedFileBase file)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();

            #region
            string tpl_File = string.Empty;

            HSSFWorkbook wbXLS;

            try
            {
                db0 = getDB0();
                wbXLS = new HSSFWorkbook(file.InputStream);
                ISheet getSheet = wbXLS.GetSheet("年度申報表");

                var getUserId = GetCellValueString(getSheet, "G3");

                if (getUserId != this.UserId)
                {
                    rAjaxResult.result = false;
                    rAjaxResult.message = "User Id驗證不符";
                    return defJSON(rAjaxResult);
                }

                double getYear = GetCellValueInt(getSheet, "C4");

                if (getYear > allowApplyYear)
                {
                    rAjaxResult.message = string.Format("{0}年度不充許申報!", getYear);
                    rAjaxResult.result = false;
                    return defJSON(rAjaxResult);
                }

                var isExist = db0.Apply.Any(x => x.y == getYear && x.userid == this.UserId);

                int startRow = 7;
                int getLastRow = getSheet.LastRowNum;
                int apply_id = 0;
                Apply apply = new Apply();
                if (!isExist)//如果申報表不存在就新增
                {
                    //Apply apply = new Apply();
                    apply.apply_id = GetNewId(ProcCore.Business.CodeTable.Apply);
                    apply.doc_date = DateTime.Now;
                    apply_id = apply.apply_id;//取得id

                    var getLast_1 = getSheet.GetRow(getLastRow - 1);
                    apply.doc_name = getLast_1.Cells[1].StringCellValue;
                    apply.doc_gender = true;
                    apply.doc_rank = getLast_1.Cells[3].StringCellValue; ;
                    apply.doc_tel = getLast_1.Cells[5].StringCellValue; ;

                    var getLast_2 = getSheet.GetRow(getLastRow);
                    apply.mng_name = getLast_2.Cells[1].StringCellValue;
                    apply.mng_gender = true;
                    apply.mng_rank = getLast_2.Cells[3].StringCellValue;
                    apply.mng_tel = getLast_2.Cells[5].StringCellValue;

                    apply.y = Convert.ToInt16(getYear);
                    apply.start_date = DateTime.Parse(getYear + "/01/01");
                    apply.end_date = DateTime.Parse(getYear + "/12/31");
                    apply.i_InsertDateTime = DateTime.Now;
                    apply.userid = this.UserId;
                    apply.Apply_Detail_Condenser = new List<Apply_Detail_Condenser>();
                    apply.Apply_Detail_Evaporate = new List<Apply_Detail_Evaporate>();

                }
                else
                {//存在就修改資料 
                    apply_id = db0.Apply.SingleOrDefault(x => x.y == getYear && x.userid == this.UserId).apply_id;//取得id
                    //apply = await db0.Apply.FindAsync(apply_id);

                    var getLast_1 = getSheet.GetRow(getLastRow - 1);
                    apply.doc_name = getLast_1.Cells[1].StringCellValue;
                    apply.doc_gender = true;
                    apply.doc_rank = getLast_1.Cells[3].StringCellValue; ;
                    apply.doc_tel = getLast_1.Cells[5].StringCellValue; ;

                    var getLast_2 = getSheet.GetRow(getLastRow);
                    apply.mng_name = getLast_2.Cells[1].StringCellValue;
                    apply.mng_gender = true;
                    apply.mng_rank = getLast_2.Cells[3].StringCellValue;
                    apply.mng_tel = getLast_2.Cells[5].StringCellValue;

                    apply.i_UpdateDateTime = DateTime.Now;
                }

                int equiCount = db0.Equipment_Chiller.Where(x => x.USERID == this.UserId).Count();//計算該廠商有幾筆設備
                for (int i = 0; i < equiCount; i++)
                {
                    //int monthstart = 0;//起始一月行數
                    IRow getRow = getSheet.GetRow(startRow);
                    ICell getCell = getRow.Cells[0];

                    //取得設備編號
                    string getEquipmentSN = getRow.Cells[0].StringCellValue;
                    var checkEquip = db0.Equipment_Chiller.Where(x => x.equipment_sn == getEquipmentSN && x.USERID == this.UserId).Select(x => new { x.equipment_chiller_id, x.equipment_sn }).FirstOrDefault();
                    if (checkEquip == null)
                    {
                        rAjaxResult.result = false;
                        rAjaxResult.message = "此設備編號不存在:" + getEquipmentSN;
                        return defJSON(rAjaxResult);
                    }
                    //判斷設備是否已申請過
                    int getEquid = checkEquip.equipment_chiller_id;//取得設備id
                    Boolean checkDetail = db0.Apply_Detail_Evaporate.Any(x => x.equipment_id == getEquid && x.y == getYear && x.userid == this.UserId);
                    if (checkDetail)
                    {
                        rAjaxResult.result = false;
                        rAjaxResult.message = "此設備編號已存在:" + getEquipmentSN + ",請點選刪除後再重新上傳";
                        return defJSON(rAjaxResult);
                    }
                    decimal get設計值 = (decimal)getRow.Cells[1].NumericCellValue;

                    string[] getAbnormal = new string[12];//異常狀況陣列
                    decimal[] getTd_value = new decimal[12];

                    //每月資料填入
                    for (int j = 0; j < 12; j++)
                    {
                        getRow = getSheet.GetRow(startRow);

                        getTd_value[j] = (decimal)getRow.Cells[3].NumericCellValue;
                        getAbnormal[j] = getRow.Cells[4].StringCellValue;

                        startRow += 1;
                    }

                    Apply_Detail_Evaporate makeEvaporateDetail = new Apply_Detail_Evaporate()
                    {
                        apply_detail_evaporate_id = GetNewId(ProcCore.Business.CodeTable.Apply_Detail_Evaporate),
                        apply_id = apply_id,
                        equipment_id = checkEquip.equipment_chiller_id,
                        equipment_sn = checkEquip.equipment_sn,
                        td_set = get設計值,
                        abnormal_01 = getAbnormal[0],
                        abnormal_02 = getAbnormal[1],
                        abnormal_03 = getAbnormal[2],
                        abnormal_04 = getAbnormal[3],
                        abnormal_05 = getAbnormal[4],
                        abnormal_06 = getAbnormal[5],
                        abnormal_07 = getAbnormal[6],
                        abnormal_08 = getAbnormal[7],
                        abnormal_09 = getAbnormal[8],
                        abnormal_10 = getAbnormal[9],
                        abnormal_11 = getAbnormal[10],
                        abnormal_12 = getAbnormal[11],

                        td_value_01 = getTd_value[0],
                        td_value_02 = getTd_value[1],
                        td_value_03 = getTd_value[2],
                        td_value_04 = getTd_value[3],
                        td_value_05 = getTd_value[4],
                        td_value_06 = getTd_value[5],
                        td_value_07 = getTd_value[6],
                        td_value_08 = getTd_value[7],
                        td_value_09 = getTd_value[8],
                        td_value_10 = getTd_value[9],
                        td_value_11 = getTd_value[10],
                        td_value_12 = getTd_value[11],

                        i_InsertDateTime = DateTime.Now,
                        y = Convert.ToInt16(getYear),
                        userid = this.UserId
                    };

                    apply.Apply_Detail_Evaporate.Add(makeEvaporateDetail);
                }

                if (!isExist)
                {
                    db0.Apply.Add(apply);
                }
                // await db0.SaveChangesAsync();

                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.FileName = file.FileName;

            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.message = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.message = ex.Message + ex.StackTrace;
            }
            finally
            {
                db0.Dispose();
            }
            #endregion
            return defJSON(rAjaxResult);
        }
        public string aj_excelEquipmentUploadForTest(HttpPostedFileBase file)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
            dicEquipmentIsNew = new Dictionary<string, bool>();

            dicEquipmentIsNew.Add("即設", false);
            dicEquipmentIsNew.Add("新設", true);

            #region
            string tpl_File = string.Empty;

            HSSFWorkbook wbXLS;

            try
            {
                db0 = getDB0();
                wbXLS = new HSSFWorkbook(file.InputStream);
                ISheet getSheet = wbXLS.GetSheet("設備表");

                var getUserId = GetCellValueString(getSheet, "E3");

                if (getUserId != this.UserId)
                {
                    rAjaxResult.result = false;
                    rAjaxResult.message = "User Id驗證不符";
                    return defJSON(rAjaxResult);
                }

                int startRow = 5;
                int getLastRow = getSheet.LastRowNum;

                var getEquipments = db0.Equipment_Chiller.Where(x => x.USERID == this.UserId).ToList();

                //匯入之前要先移除設備資料 已在申報中的不移除
                foreach (var equip in getEquipments)
                {
                    var checkCIsExist = db0.Apply_Detail_Condenser.Any(x => x.equipment_id == equip.equipment_chiller_id);
                    var checkEIsExist = db0.Apply_Detail_Evaporate.Any(x => x.equipment_id == equip.equipment_chiller_id);
                    if (!checkCIsExist && !checkEIsExist)
                    {
                        db0.Equipment_Chiller.Remove(equip);
                    }
                }
                //await db0.SaveChangesAsync();
                for (var i = startRow; i <= getLastRow; i++)
                {
                    IRow getRow = getSheet.GetRow(i);
                    Equipment_Chiller getImportData = SetEquipmentImportData(getRow);
                    if (getImportData != null)
                    {
                        var isExist = db0.Equipment_Chiller.Any(x => x.equipment_sn == getImportData.equipment_sn);
                        if (!isExist)
                        {
                            db0.Equipment_Chiller.Add(getImportData);
                        }
                    }
                }
                //await db0.SaveChangesAsync();

                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.FileName = file.FileName;

            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.message = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.message = ex.Message + ex.StackTrace;
            }
            finally
            {
                db0.Dispose();
            }
            #endregion
            return defJSON(rAjaxResult);
        }
        public async Task<string> aj_excelEquipmentUpload(HttpPostedFileBase file)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();
            dicEquipmentIsNew = new Dictionary<string, bool>();

            dicEquipmentIsNew.Add("即設", false);
            dicEquipmentIsNew.Add("新設", true);

            var fileName = "Manager-" + this.UserId + "-設備-" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xls";
            var path = Path.Combine(Server.MapPath("~/_Code/SysUpFiles/ExcelUpLoadData/Equi"), fileName);
            file.SaveAs(path);

            string successMessage = string.Empty;
            int countSuccessImport = 0;
            List<Equipment_Chiller> excelEquipment = new List<Equipment_Chiller>();

            #region
            string tpl_File = string.Empty;

            HSSFWorkbook wbXLS;

            try
            {
                db0 = getDB0();
                wbXLS = new HSSFWorkbook(file.InputStream);
                ISheet getSheet = wbXLS.GetSheet("設備表");

                var getUserId = GetCellValueString(getSheet, "E3");
                if (getUserId != this.UserId)
                {
                    rAjaxResult.result = false;
                    rAjaxResult.message = "User Id驗證不符";
                    return defJSON(rAjaxResult);
                }

                int startRow = 5;
                int getLastRow = getSheet.LastRowNum;

                var getEquipments = db0.Equipment_Chiller.Where(x => x.USERID == this.UserId).ToList();
                #region 刪除設備功能(目前不使用)
                //匯入之前要先移除設備資料 已在申報中的不移除
                //foreach (var equip in getEquipments)
                //{
                //    var checkCIsExist = db0.Apply_Detail_Condenser.Any(x => x.equipment_id == equip.equipment_chiller_id);
                //    var checkEIsExist = db0.Apply_Detail_Evaporate.Any(x => x.equipment_id == equip.equipment_chiller_id);
                //    if (!checkCIsExist && !checkEIsExist)
                //    {
                //        db0.Equipment_Chiller.Remove(equip);
                //    }
                //}
                //await db0.SaveChangesAsync();
                #endregion
                for (var i = startRow; i <= getLastRow; i++)
                {
                    IRow getRow = getSheet.GetRow(i);
                    Equipment_Chiller getImportData = null;
                    try
                    {
                        if (getCellValue(getRow, 1) == "" &&
                           getCellValue(getRow, 2) == "" &&
                           getCellValue(getRow, 3) == "" &&
                           getCellValue(getRow, 4) == "")
                        {//欄位都空白就略過 
                        }
                        else if (getCellValue(getRow, 1) == "" ||
                                 getCellValue(getRow, 2) == "" ||
                                 getCellValue(getRow, 3) == "" ||
                                 getCellValue(getRow, 4) == "")
                        {//其中一個直空白不匯入,彈出錯誤訊息告知他資料填寫不完整
                            rAjaxResult.result = false;
                            rAjaxResult.message = "Excel檔案第" + (i + 1) + "列設備資料填寫不完整!";
                            return defJSON(rAjaxResult);
                        }
                        getImportData = SetEquipmentImportData(getRow);
                    }
                    catch
                    {
                        rAjaxResult.result = false;
                        rAjaxResult.success = false;
                        rAjaxResult.message = "Excel檔案第" + (i + 1) + "列資料型態錯誤!";
                        return defJSON(rAjaxResult);
                    }
                    if (getImportData != null)
                    {
                        var isExist = db0.Equipment_Chiller.Any(x => x.equipment_sn == getImportData.equipment_sn && x.USERID == getImportData.USERID);
                        var isExcelExist = excelEquipment.Any(x => x.equipment_sn == getImportData.equipment_sn && x.USERID == getImportData.USERID);
                        if (!isExist && !isExcelExist)
                        {
                            if (getImportData.equipment_sn.Length > 20)
                            {
                                rAjaxResult.result = false;
                                rAjaxResult.success = false;
                                rAjaxResult.message = "Excel檔案第" + (i + 1) + "列設備編號長度超過20字!";
                                return defJSON(rAjaxResult);
                            }
                            db0.Equipment_Chiller.Add(getImportData);
                            excelEquipment.Add(getImportData);
                            countSuccessImport += 1;
                        }
                        else
                        {
                            if (isExist)
                            {
                                rAjaxResult.message = "Excel檔案第" + (i + 1) + "列設備編號已存在,請勿重複匯入!";
                            }
                            else
                            {
                                rAjaxResult.message = "Excel檔案第" + (i + 1) + "列,在Excel檔內與其他設備編號重複!";
                            }
                            rAjaxResult.result = false;
                            return defJSON(rAjaxResult);
                        }
                    }
                }
                await db0.SaveChangesAsync();

                successMessage = successMessage + "共" + countSuccessImport + "筆資料匯入成功!";

                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.FileName = file.FileName;
                rAjaxResult.message = successMessage;
            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                //rAjaxResult.message = getRecMessage(ex.Message);
                rAjaxResult.message = getRecMessage("excel檔案格式錯誤");
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                //rAjaxResult.message = ex.Message + ex.StackTrace;
                rAjaxResult.message = getRecMessage("excel檔案格式錯誤");
            }
            finally
            {
                db0.Dispose();
            }
            #endregion
            return defJSON(rAjaxResult);
        }
        public async Task<string> aj_excelEquipmentDelete(q_Equipment_Chiller q)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();

            #region
            try
            {
                db0 = getDB0();
                if (q.user_id == null)
                {
                    rAjaxResult.result = false;
                    rAjaxResult.message = "未選擇userid";
                    return defJSON(rAjaxResult);
                }
                var getEquipments = db0.Equipment_Chiller.Where(x => x.USERID == this.UserId).ToList();
                #region 刪除設備功能
                //已在申報中的不移除
                foreach (var equip in getEquipments)
                {
                    var checkCIsExist = db0.Apply_Detail_Condenser.Any(x => x.equipment_id == equip.equipment_chiller_id);
                    var checkEIsExist = db0.Apply_Detail_Evaporate.Any(x => x.equipment_id == equip.equipment_chiller_id);
                    if (!checkCIsExist && !checkEIsExist)
                    {
                        db0.Equipment_Chiller.Remove(equip);
                    }
                }
                await db0.SaveChangesAsync();
                #endregion
                rAjaxResult.result = true;
                rAjaxResult.success = true;

            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.message = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.message = ex.Message + ex.StackTrace;
            }
            finally
            {
                db0.Dispose();
            }
            #endregion
            return defJSON(rAjaxResult);
        }
        public async Task<string> aj_excelMonthUpload(HttpPostedFileBase file)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();

            #region
            string tpl_File = string.Empty;

            HSSFWorkbook wbXLS;

            try
            {
                #region MyRegion
                db0 = getDB0();
                wbXLS = new HSSFWorkbook(file.InputStream);
                ISheet getSheet = wbXLS.GetSheet("每月監控平均值");

                var getUserId = GetCellValueString(getSheet, "E3");
                if (getUserId != this.UserId)
                {
                    rAjaxResult.result = false;
                    rAjaxResult.message = "User Id驗證不符";
                    return defJSON(rAjaxResult);
                }

                double getYear = GetCellValueInt(getSheet, "C4");

                if (getYear > allowApplyYear)
                {
                    rAjaxResult.message = string.Format("{0}年度不充許申報!", getYear);
                    rAjaxResult.result = false;
                    return defJSON(rAjaxResult);
                }


                var isExist = db0.Apply_Detail_Condenser.Any(x => x.y == getYear);
                if (isExist)
                {
                    rAjaxResult.message = string.Format("{0}年度資料已存在無法新增!", getYear);
                    rAjaxResult.result = false;
                    return defJSON(rAjaxResult);
                }

                int startRow = 7;
                int getLastRow = getSheet.LastRowNum;
                var getEquipments = db0.Equipment_Chiller.Where(x => x.USERID == this.UserId).ToList();

                for (int i = startRow; i < getLastRow; i++)
                {
                    #region MyRegion
                    var getRow = getSheet.GetRow(i);
                    var getEquip = getRow.Cells[1];

                    if (getEquip.StringCellValue != "")
                    {
                        var getEquipment = getEquipments.Where(x => x.equipment_sn == getEquip.StringCellValue).FirstOrDefault();

                        if (getEquipment != null)
                        {
                            var md = new Apply_Detail_Condenser()
                            {
                                y = Convert.ToInt16(getYear),
                                userid = this.UserId,
                                apply_detail_condenser_id = GetNewId(ProcCore.Business.CodeTable.Apply_MonthAverage),
                                equipment_id = getEquipment.equipment_chiller_id,
                                td_value_01 = (decimal)getRow.Cells[3].NumericCellValue,
                                td_value_02 = (decimal)getRow.Cells[4].NumericCellValue,
                                td_value_03 = (decimal)getRow.Cells[5].NumericCellValue,
                                td_value_04 = (decimal)getRow.Cells[6].NumericCellValue,
                                td_value_05 = (decimal)getRow.Cells[7].NumericCellValue,
                                td_value_06 = (decimal)getRow.Cells[8].NumericCellValue,
                                td_value_07 = (decimal)getRow.Cells[9].NumericCellValue,
                                td_value_08 = (decimal)getRow.Cells[10].NumericCellValue,
                                td_value_09 = (decimal)getRow.Cells[11].NumericCellValue,
                                td_value_10 = (decimal)getRow.Cells[12].NumericCellValue,
                                td_value_11 = (decimal)getRow.Cells[13].NumericCellValue,
                                td_value_12 = (decimal)getRow.Cells[14].NumericCellValue,
                                abnormal_01 = getRow.Cells[16].StringCellValue,
                                abnormal_02 = getRow.Cells[17].StringCellValue,
                                abnormal_03 = getRow.Cells[18].StringCellValue,
                                abnormal_04 = getRow.Cells[19].StringCellValue,
                                abnormal_05 = getRow.Cells[20].StringCellValue,
                                abnormal_06 = getRow.Cells[21].StringCellValue,
                                abnormal_07 = getRow.Cells[22].StringCellValue,
                                abnormal_08 = getRow.Cells[23].StringCellValue,
                                abnormal_09 = getRow.Cells[24].StringCellValue,
                                abnormal_10 = getRow.Cells[25].StringCellValue,
                                abnormal_11 = getRow.Cells[26].StringCellValue,
                                abnormal_12 = getRow.Cells[27].StringCellValue,

                                i_InsertDateTime = DateTime.Now
                            };

                            db0.Apply_Detail_Condenser.Add(md);
                        }
                    }
                    #endregion
                }
                #endregion

                await db0.SaveChangesAsync();

                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.FileName = file.FileName;

            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.message = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.message = ex.Message + ex.StackTrace;
            }
            finally
            {
                db0.Dispose();
            }
            #endregion
            return defJSON(rAjaxResult);
        }
        public string aj_loadingFileUpload(string userid, int y, HttpPostedFileBase file)
        {
            ReturnAjaxFiles rAjaxResult = new ReturnAjaxFiles();

            #region
            try
            {
                if (file.ContentLength > (5 * 1024 * 1024))
                {
                    rAjaxResult.result = false;
                    rAjaxResult.success = false;
                    rAjaxResult.error = "檔案超過5MB";
                }
                string uid = string.Empty;
                if (this.UserId != null && this.UserId != "")
                {
                    uid = this.UserId;
                }
                else
                {
                    uid = userid;
                }

                string fileName = uid + "-冰水機負載調控申報-" + DateTime.Now.ToString("yyyyMMddHHmm") + "-" + file.FileName;
                string pathTpl = string.Format("~/_Code/SysUpFiles/Apply.Loading/{0}/{1}", y, uid);
                string serverPath = Server.MapPath(pathTpl);
                if (!Directory.Exists(serverPath))
                    Directory.CreateDirectory(serverPath);

                string path = Path.Combine(serverPath, fileName);
                //只能有一筆 所先刪除
                string[] filePaths = Directory.GetFiles(serverPath);
                foreach (string filePath in filePaths)
                    System.IO.File.Delete(filePath);

                file.SaveAs(path);

                rAjaxResult.result = true;
                rAjaxResult.success = true;
                rAjaxResult.FileName = file.FileName;

            }
            catch (LogicError ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = getRecMessage(ex.Message);
            }
            catch (Exception ex)
            {
                rAjaxResult.result = false;
                rAjaxResult.success = false;
                rAjaxResult.error = ex.Message;
            }
            #endregion
            return defJSON(rAjaxResult);
        }