protected void Page_LoadComplete(object sender, EventArgs e)
        {
            string SaveFile="";
            cuser = new CurrentUser();
            cuser.userName = "******";
            cuser.Load();
            lkup_tier tier = new lkup_tier(cuser);
            List<IntelWebObject> Tiers = tier.Load();
            this.ltrTiers.Text = string.Join("", Tiers.Cast<lkup_tier>().Select(x => "<option value=\"" + HttpUtility.HtmlEncode(x.tier_code) + "\">" + HttpUtility.HtmlEncode(x.tier_code) + "</option>").ToArray());

            if (IsPostBack)
            {
                bool createJob = false;
                if (Request.Files.Count > 0)
                {
                    HttpPostedFile File1 = Request.Files[0];
                    if (File1.ContentLength > 0)
                    {
                        SaveFile = System.IO.Path.GetFileName(File1.FileName);
                        if (System.IO.Path.GetExtension(SaveFile).Equals(".xls", StringComparison.InvariantCultureIgnoreCase))
                        {
                            string SaveLocation = Server.MapPath("Data") + "\\" + SaveFile;
                            try
                            {
                                File1.SaveAs(SaveLocation);
                                createJob = true;
                            }
                            catch (Exception ex)
                            {
                                ltrMessage.Text = "<div style=\"border:1px solid #FF0000;\">Error: " + HttpUtility.HtmlEncode(ex.Message) + "</div>";
                            }
                        }
                        else
                        {
                            ltrMessage.Text = "<div style=\"border:1px solid #FFFF00;\">Impoter support's only Excel files.</div>";
                        }
                    }
                    else
                    {
                        string xlsText = Request.Form["xlsTextArea"];
                        if (!string.IsNullOrEmpty(xlsText))
                        {
                            SaveFile = randomFile() + ".txt";
                            StreamWriter outfile = new StreamWriter(Server.MapPath("Data") + "\\" + SaveFile);
                            outfile.Write(xlsText);
                            outfile.Close();
                            createJob = true;
                        }
                    }
                }
                if (createJob)
                {
                    JobQ job = new JobQ(cuser);
                    job.jobType = "Import";
                    job.jobStatus = "active";
                    job.tiername = Request.Form["tiername"];
                    job.filename = SaveFile;
                    if (job.save())
                    {
                        ltrMessage.Text = "<div style=\"border:1px solid #00FF00;\">The file has been uploaded.</div>";
                    }
                    else
                    {
                        ltrMessage.Text = "<div style=\"border:1px solid #FF0000;\">Error: " + HttpUtility.HtmlEncode(job.saveErrorText) + "</div>";
                    }
                }
            }

            ltrJobStatus.Text = JobStatusHTML();
        }
Пример #2
0
 private void CheckJobQ(object state)
 {
     JobQ tempJob = new JobQ(cuser);
     tempJob.jobStatus = "active";
     tempJob.LoadSingle();
     Console.Write("{1} Checking Job Queue...{0} Jobs Found.\n", (tempJob.isNew ? 0 : 1), DateTime.Now);
     if (!tempJob.isNew)
     {
         tempJob.jobStatus = "running";
         tempJob.starttime = DateTime.Now;
         tempJob.save();
         Importer objImp = new Importer();
         objImp.CJobQ = tempJob;
         Thread oThread = new Thread(new ThreadStart(objImp.doImport));
         oThread.Start();
     }
 }