Пример #1
0
 private string savefile(string id, string format, string path, string dateformat, string pref)
 {
     try
     {
         if (string.IsNullOrEmpty(format))
         {
             format = "csv";
         }
         var F = new Finder();
         F.Account = "malkin";
         F.Mode    = "csv";
         F.start(id);
         char r = ';';
         if (format != "csv")
         {
             r = '\t';
         }
         string s        = F.ExportCSV(r);
         string filename = pref + DateTime.Now.ToString(dateformat) + "." + format;
         string filepath = Program.AppConfig[path];
         string ff       = filepath + @"\" + filename;
         System.IO.File.WriteAllText(ff, s, Encoding.GetEncoding(1251));
         return(ff);
     }
     catch (Exception err)
     {
         var    webRoot   = _env.WebRootPath;
         var    errorpath = webRoot + @"\..\netbu_error.log";
         string mes       = $"{err.Message}\r\n{err.StackTrace} - {DateTime.Now}\r\n\r\n";
         System.IO.File.AppendAllText(errorpath, mes);
         return("");
     }
 }
Пример #2
0
        public IActionResult CSV(string id, string Fc, string TextParams, string SQLParams, string format, string dateformat, string pref)
        {
            if (string.IsNullOrEmpty(format))
            {
                format = "csv";
            }

            var F = new Finder();

            F.Account = User.Identity.Name;
            if (string.IsNullOrEmpty(F.Account))
            {
                F.Account = "malkin";
            }

            F.Mode = "csv";
            if (!string.IsNullOrEmpty(Fc))
            {
                List <FinderField> Fcols = JsonConvert.DeserializeObject <List <FinderField> >(Fc);
                F.Fcols = Fcols;
            }

            if (!string.IsNullOrEmpty(TextParams))
            {
                F.TextParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(TextParams);
            }

            if (!string.IsNullOrEmpty(SQLParams))
            {
                F.SQLParams = JsonConvert.DeserializeObject <Dictionary <string, object> >(SQLParams);
                Dictionary <string, object> parseParam = new Dictionary <string, object>();
                foreach (string k in F.SQLParams.Keys)
                {
                    DateTime dval;
                    string   val = F.SQLParams[k].ToString();
                    if (DateTime.TryParse(val, out dval))
                    {
                        parseParam.Add(k, dval);
                    }
                    else
                    {
                        parseParam.Add(k, F.SQLParams[k]);
                    }
                }
                F.SQLParams = parseParam;
            }


            F.start(id);
            char r = ';';

            if (format != "csv")
            {
                r = '\t';
            }
            string s     = F.ExportCSV(r);
            string ctype = "application/octet-stream";

            byte[] buf      = Encoding.GetEncoding(1251).GetBytes(s);
            string filename = $"data_{id}.{format}";

            if (!string.IsNullOrEmpty(dateformat))
            {
                filename = pref + DateTime.Now.ToString(dateformat) + "." + format;
            }

            return(File(buf, ctype, filename));
        }