Beispiel #1
0
        // GET api/Xml_ExportOracle/5
        public HttpResponseMessage Get(string idrandom)
        {
            general gn             = new general();
            var     dicAppSet      = gn.ReadAppseting();
            var     lst            = JObject.Parse(_dicPara_xml["StrColumnNames" + idrandom]).SelectToken("kq").ToString();
            var     LstColumnNames = JsonConvert.DeserializeObject <List <ListColumnExport> >(lst);

            // lay du lieu
            gnOracle or = new gnOracle();

            if (dicAppSet == null || dicAppSet.Count == 0)
            {
                return(null);
            }

            var dicPara   = gn.ParaConvertDicPara(_dicPara_xml["StrPara" + idrandom]);
            var dicConfig = gn.ConfigConvertToDicConfig(_dicPara_xml["StrConfig" + idrandom]);

            if (dicPara == null && dicConfig == null)
            {
                return(null);
            }
            _dicPara_xml.Remove("StrPara" + idrandom);
            _dicPara_xml.Remove("StrConfig" + idrandom);
            _dicPara_xml.Remove("StrColumnNames" + idrandom);

            var dsParaOnSql = or.DecodeProceduePara_New(dicConfig, dicAppSet);
            var paraOk      = or.dicParaToOraclePara_New(dsParaOnSql, dicPara);

            var ds = or.ExcuteReturnDataSet(dicConfig["namesql"], paraOk.ToList(), CommandType.StoredProcedure, dicAppSet[dicConfig["connstr"].ToLower()]);

            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                return(null);
            }
            var ds1 = gn.convertDatasetToLower(ds);

            string filePath = dicAppSet["path_saveonserver"] + dicConfig["namefile"] + ".xml";

            System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(filePath);
            ds1.WriteXml(xmlSW, XmlWriteMode.WriteSchema);
            xmlSW.Close();

            var        response   = new HttpResponseMessage();
            FileStream fileStream = File.Open(filePath, FileMode.Open);

            response.Content = new StreamContent(fileStream);
            response.Content.Headers.ContentDisposition
                = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentDisposition.FileName = dicConfig["namefile"] + ".xml";
            response.Content.Headers.ContentType
                = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

            response.Content.Headers.ContentLength
                = fileStream.Length;
            return(response);

            //return System.Web.Mvc.Controller.(filePath, MimeMapping.GetMimeMapping(filePath));
        }
        // GET api/ExcelExportOracle/5
        public string Get(string idrandom)
        {
            general gn             = new general();
            var     dicAppSet      = gn.ReadAppseting();
            var     lst            = JObject.Parse(_dicPara_exoracle["StrColumnNames" + idrandom]).SelectToken("kq").ToString();
            var     LstColumnNames = JsonConvert.DeserializeObject <List <ListColumnExport> >(lst);

            // lay du lieu
            gnOracle or = new gnOracle();

            if (dicAppSet == null || dicAppSet.Count == 0)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Đọc appsetting lỗi\"}]}");
            }

            var dicPara   = gn.ParaConvertDicPara(_dicPara_exoracle["StrPara" + idrandom]);
            var dicConfig = gn.ConfigConvertToDicConfig(_dicPara_exoracle["StrConfig" + idrandom]);

            _dicPara_exoracle.Remove("StrPara" + idrandom);
            _dicPara_exoracle.Remove("StrConfig" + idrandom);
            _dicPara_exoracle.Remove("StrColumnNames" + idrandom);

            if (dicPara == null && dicConfig == null)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
            }

            var dsParaOnSql = or.DecodeProceduePara_New(dicConfig, dicAppSet);
            var paraOk      = or.dicParaToOraclePara_New(dsParaOnSql, dicPara);

            var ds = or.ExcuteReturnDataSet(dicConfig["namesql"], paraOk.ToList(), CommandType.StoredProcedure, dicAppSet[dicConfig["connstr"].ToLower()]);

            if (ds == null || ds.Tables.Count == 0)
            {
                return("");
            }
            var ds1 = gn.convertDatasetToLower(ds);

            gnExcel exx = new gnExcel();

            var idtable = 0;

            if (dicConfig.ContainsKey("exporttable"))
            {
                idtable = Convert.ToInt32(dicConfig["exporttable"]);
            }

            exx.ExporttoExcel(new List <string>(), ds1.Tables[idtable], LstColumnNames, dicConfig.ContainsKey("namefile") ? dicConfig["namefile"] : "" + DateTime.Now.ToString("dd-MM-yyyy"), 1, false, true);
            return("");
        }