public Get_OutExport Export(string data) { Get_OutExport json = new Get_OutExport(); try { Get_InExport input = Newtonsoft.Json.JsonConvert.DeserializeObject <Get_InExport>(data); DBDayPlan db = new DBDayPlan(); List <PlanItemGroups> LLeftpgs = new List <PlanItemGroups>(); List <PlanItemGroups> LRightpgs = new List <PlanItemGroups>(); List <PlanItemGroup> LLeftPlanItemGroup = db.QueryLeftGroupListByID(input.BeginDate, input.EndDate, input.DayPlanID); foreach (PlanItemGroup pig in LLeftPlanItemGroup) { PlanItemGroups Leftpgs = new PlanItemGroups(); Leftpgs.PlanArray = new List <DayPlan>(); Leftpgs.PlanItemGroup = pig; List <DayPlan> dp = db.QueryDayPlanInfoListByGroupID(input.BeginDate, input.EndDate, pig.nID); Leftpgs.PlanArray = dp; LLeftpgs.Add(Leftpgs); } List <PlanItemGroup> LRightPlanItemGroup = db.QueryRightGroupListByID(input.BeginDate, input.EndDate, input.DayPlanID); foreach (PlanItemGroup pig in LRightPlanItemGroup) { PlanItemGroups rightpgs = new PlanItemGroups(); rightpgs.PlanItemGroup = pig; List <DayPlan> dp = db.QueryDayPlanInfoListByGroupID(input.BeginDate, input.EndDate, pig.nID); rightpgs.PlanArray = dp; LRightpgs.Add(rightpgs); } ExportDatas ed = new ExportDatas(); ed.leftGroups = LLeftpgs; ed.rightGroups = LRightpgs; datas d = new datas(); d.ExportData = ed; json.data = d; json.result = "0"; json.resultStr = "返回成功"; } catch (Exception ex) { json.result = "1"; json.resultStr = "提交失败:" + ex.Message; } return(json); }
//------------------------------------------------------------------------------------------------------------------------------- public DataSet GetExportForDisplay(string keyExport, string strLibelle, string strDescription) { AspectizeUser aspectizeUser = ExecutingContext.CurrentUser; IEntityManager em = EntityManager.FromDataSet(DataSetHelper.Create()); if (aspectizeUser.IsAuthenticated) { int nTimosSessionId = (int)aspectizeUser[CUserTimosWebApp.c_champSessionId]; ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize)); CResultAErreur result = serviceClientAspectize.GetSession(nTimosSessionId); if (!result) { throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter"); } try { IFileService fs = ExecutingContext.GetService <IFileService>("TimosFileService"); string relativePath = keyExport + ".json"; string fullPath = fs.GetFileUrl(relativePath); fullPath = fullPath.Substring(16); if (File.Exists(fullPath)) { byte[] buffer = fs.ReadBytes(relativePath); string jsonLecture = Encoding.ASCII.GetString(buffer); DataSet dsExport = JsonConvert.DeserializeObject <DataSet>(jsonLecture); if (dsExport != null && dsExport.Tables.Count > 0) { Export export = em.CreateInstance <Export>(); export.Id = keyExport; export.Libelle = strLibelle; export.Description = strDescription; export.DataDate = File.GetLastWriteTime(fullPath); // Extraction des données du DataSet DataTable tableExport = dsExport.Tables[0]; // On traite uniquement la première table int nIndexCol = 1; // Les 10 premières colonnes uniquement foreach (DataColumn col in tableExport.Columns) { export.data["COL" + nIndexCol] = col.ColumnName; nIndexCol++; if (nIndexCol > 10) { break; } } // Traitement des données (lignes) int nIndexRow = 0; foreach (DataRow row in tableExport.Rows) { string strIdCompose = keyExport + "#" + nIndexRow++; ExportDatas expData = em.GetInstance <ExportDatas>(strIdCompose); if (expData == null) { expData = em.CreateInstance <ExportDatas>(); expData.Id = strIdCompose; em.AssociateInstance <RelationExportDatas>(export, expData); } for (int i = 0; i < tableExport.Columns.Count && i < 10; i++) { if (row[i] == DBNull.Value) { expData.data[i + 1] = ""; } else { expData.data[i + 1] = row[i]; } } } } } } catch (Exception ex) { throw new SmartException(1010, "Erreur GetExportForDisplay(nTimosSessionId = " + nTimosSessionId + ", keyExport = " + keyExport + ")" + Environment.NewLine + ex.Message); } } else { throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter"); } em.Data.AcceptChanges(); return(em.Data); }