Exemplo n.º 1
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string result = "";

            if (this.txtUserUpload.PostedFile.FileName == "")
            {
                JscriptMsg("请选择上传文件", "", "Error");
                return;
            }
            DataSet ds   = new DataSet();
            string  path = "../../../upload/excel/";

            #region 解决360获取绝对路径导致出错的问题
            string   AbsolutePath = this.txtUserUpload.PostedFile.FileName;
            string[] pathList     = new string[] { };

            pathList     = AbsolutePath.Split('\\');
            AbsolutePath = pathList[pathList.Length - 1];
            #endregion

            string fileName = DateTime.Now.ToFileTime() + "_" + AbsolutePath;
            string FexName  = fileName.Substring(fileName.LastIndexOf(".") + 1);
            if (FexName != "xls" && FexName != "xlsx")
            {
                JscriptMsg("请上传Excel文件", "", "Error");
                return;
            }

            string filePath = Server.MapPath(path + fileName);

            this.txtUserUpload.SaveAs(filePath);
            int success = 0, error = 0;
            try
            {
                var excel = new Common.ExcelToData();
                ds     = excel.GetExcelData(filePath);
                result = ImportDataItem(ds, ref success, ref error);
            }
            catch (Exception ex)
            {
                LOGGER.Debug(ex.Message, ex);
                result = "导入发生异常情况,请联系客服";
            }
            string divinfo = "<div class=\"alert alert-block alert-info fade in\">";
            divinfo += "<button data-dismiss=\"alert\" class=\"close\" type=\"button\">×</button>";
            divinfo += "<h4 class=\"alert-heading\">导入结果</h4>";
            divinfo += "<p>";
            if (success != ds.Tables[0].DefaultView.Count)
            {
                divinfo += "部分导入成功!<br>";
            }
            else
            {
                divinfo += "全部导入成功!<br>";
            }
            divinfo += "*共有" + ds.Tables[0].DefaultView.Count + "条数据,成功" + success + "条,失败" + error + "条;<br/>";
            if (result != "")
            {
                divinfo += "详细信息如下:<br><font color='red'>" + result;
            }
            divinfo           += "</font></p>";
            divinfo           += "</div>";
            this.lblError.Text = divinfo;
            File.Delete(filePath);
        }
Exemplo n.º 2
0
        public override ActionOutcome Go(TVRenameStats stats)
        {
            // read NTFS permissions (if any)
            FileSecurity security = null;

            try
            {
                security = From.GetAccessControl();
            }
            catch
            {
                // ignored
            }

            try
            {
                //we use a temp name just in case we are interrupted or some other problem occurs
                string tempName = TempFor(To);

                // If both full filenames are the same then we want to move it away and back
                //This deals with an issue on some systems (XP?) that case insensitive moves did not occur
                if (IsMoveRename() || FileHelper.Same(From, To))
                {
                    // This step could be slow, so report progress
                    CopyMoveResult moveResult = File.Move(From.FullName, tempName, MoveOptions.CopyAllowed | MoveOptions.ReplaceExisting, CopyProgressCallback, null);
                    if (moveResult.ErrorCode != 0)
                    {
                        throw new ActionFailedException(moveResult.ErrorMessage);
                    }
                }
                else
                {
                    //we are copying
                    Debug.Assert(Operation == Op.copy);

                    // This step could be slow, so report progress
                    CopyMoveResult copyResult = File.Copy(From.FullName, tempName, CopyOptions.None, true, CopyProgressCallback, null);
                    if (copyResult.ErrorCode != 0)
                    {
                        throw new ActionFailedException(copyResult.ErrorMessage);
                    }
                }

                // Copying the temp file into the correct name is very quick, so no progress reporting
                File.Move(tempName, To.FullName, MoveOptions.ReplaceExisting);
                LOGGER.Info($"{Name} completed: {From.FullName} to {To.FullName } ");

                UpdateStats(stats);

                if (To.IsMovieFile())
                {
                    //File is correct name
                    LOGGER.Debug($"Just copied {To.FullName} to the right place. Marking it as 'seen'.");

                    if (Episode != null)
                    {
                        //Record this episode as seen
                        TVSettings.Instance.PreviouslySeenEpisodes.EnsureAdded(SourceEpisode);

                        if (TVSettings.Instance.IgnorePreviouslySeen)
                        {
                            doc.SetDirty();
                        }
                    }

                    if (Movie != null)
                    {
                        //Record this movie as seen
                        TVSettings.Instance.PreviouslySeenMovies.EnsureAdded(Movie);

                        if (TVSettings.Instance.IgnorePreviouslySeenMovies)
                        {
                            doc.SetDirty();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LOGGER.Warn(e, $"Error occurred while {Name}: {From.FullName} to {To.FullName } ");
                return(new ActionOutcome(e));
            }

            // set NTFS permissions
            try
            {
                if (security != null)
                {
                    To.SetAccessControl(security);
                }
            }
            catch
            {
                // ignored
            }

            try
            {
                if (Operation == Op.move && Tidyup != null && Tidyup.DeleteEmpty)
                {
                    LOGGER.Info($"Testing {From.Directory.FullName} to see whether it should be tidied up");
                    DoTidyup(From.Directory);
                }
            }
            catch (Exception e)
            {
                return(new ActionOutcome(e));
            }

            return(ActionOutcome.Success());
        }
        public void WriteXls()
        {
            bool        res   = true;
            Application excel = new Application();

            try
            {
                excel.Workbooks.Add(true);
                excel.Visible = false;
                int col = 1;
                SetCol("学号", 1, "", col++, excel);
                SetCol("姓名", 1, "", col++, excel);
                SetCol("专业代码", 0, "男|女", col++, excel);
                SetCol("行政班", 1, "", col++, excel);
                SetCol("毕业设计题目", 1, "", col++, excel);
                SetCol("题目类型", 0, "", col++, excel);
                SetCol("题目性质", 0, "", col++, excel);
                SetCol("题目来源", 0, "", col++, excel);
                SetCol("指导教师", 1, "", col++, excel);
                SetCol("辅助指导教师", 0, "", col++, excel);
                SetCol("职称", 1, "讲师|副教授|教授|实验师|研究员", col++, excel);
                SetCol("年龄", 0, "", col++, excel);
                SetCol("成绩", 0, "", col++, excel);
                SetCol("状态", 0, "", col++, excel);
                SetCol("题目详情", 1, "", col++, excel);
                SetCol("周志情况", 0, "", col++, excel);
                SetCol("场所", 0, "", col++, excel);
                SetCol("任务书", 0, "", col++, excel);
                string xlsName = "一键导入模板";
                xlsName = xlsName + ".xlsx";
                string serverUrl = Server.MapPath("~/");//serverUrl + xlsName
                //excel.ActiveWorkbook.SaveAs(serverUrl + xlsName,Excel.XlFileFormat.xlExcel8);
                excel.ActiveWorkbook.SaveCopyAs(serverUrl + xlsName);
                FileStream myFileStream = new FileStream(serverUrl + xlsName, FileMode.Open);

                long   fileSize = myFileStream.Length;
                byte[] buffer   = new byte[(int)fileSize];
                myFileStream.Read(buffer, 0, (int)fileSize);
                myFileStream.Close();
                HttpResponse response = System.Web.HttpContext.Current.Response;
                response.Clear();
                response.Charset     = "UTF-8";
                response.ContentType = "application/vnd.ms-excel";

                response.AppendHeader("Content-Disposition", string.Format("attachment; filename=" + HttpUtility.UrlEncode(xlsName, Encoding.UTF8).ToString()));
                response.BinaryWrite(buffer);
                response.Flush();
                response.End();

                File.Delete(serverUrl + xlsName);
            }
            catch (Exception ex)
            {
                LOGGER.Debug(ex.Message, ex);
                res = false;
            }
            finally
            {
                excel.DisplayAlerts = false;
                excel.ActiveWorkbook.Application.DisplayAlerts = false;
                excel.Quit();
                excel = null;//这一句是非常重要的,否则Excel对象不能从内存中退出
            }
            if (!res)
            {
                string msbox = "parent.f_errorTab(\"错误提示\", \"对不起,导出出错,请重新打开重试!\");";
                Response.Write("<script type=\"text/javascript\">" + msbox + "</script>");
                Response.End();
            }
        }
        private void CheckMovieFolder(MovieConfiguration si, DirFilesCache dfc, TVDoc.ScanSettings settings, string folder)
        {
            if (settings.Token.IsCancellationRequested)
            {
                return;
            }

            FileInfo[] files = dfc.GetFiles(folder);

            bool renCheck = TVSettings.Instance.RenameCheck && si.DoRename && Directory.Exists(folder); // renaming check needs the folder to exist

            bool missCheck = TVSettings.Instance.MissingCheck && si.DoMissingCheck;

            if (!renCheck && !missCheck)
            {
                return;
            }

            FileInfo[] movieFiles = files.Where(f => f.IsMovieFile()).ToArray();

            if (movieFiles.Length == 0)
            {
                FileIsMissing(si, folder, missCheck);
                return;
            }

            if (settings.Token.IsCancellationRequested)
            {
                return;
            }

            List <string> bases   = movieFiles.Select(GetBase).Distinct().ToList();
            string        newBase = TVSettings.Instance.FilenameFriendly(si.ProposedFilename);

            if (bases.Count == 1 && bases[0].Equals(newBase))
            {
                //All Seems OK

                //This is the code that will iterate over the DownloadIdentifiers and ask each to ensure that
                //it has all the required files for that show
                Doc.TheActionList.Add(downloadIdentifiers.ProcessMovie(si, movieFiles.First(m => m.Name.StartsWith(newBase, StringComparison.Ordinal))));

                return;
            }

            if (renCheck && bases.Count == 1 && !bases[0].Equals(newBase, StringComparison.CurrentCultureIgnoreCase))
            {
                foreach (FileInfo fi in files)
                {
                    if (settings.Token.IsCancellationRequested)
                    {
                        return;
                    }
                    string baseString = bases[0];

                    if (fi.Name.StartsWith(baseString, StringComparison.CurrentCultureIgnoreCase))
                    {
                        string   newName = (baseString.HasValue()) ? fi.Name.Replace(baseString, newBase) : newBase + fi.Extension;
                        FileInfo newFile = FileHelper.FileInFolder(folder, newName); // rename updates the filename

                        if (newFile.IsMovieFile())
                        {
                            //This is the code that will iterate over the DownloadIdentifiers and ask each to ensure that
                            //it has all the required files for that show
                            Doc.TheActionList.Add(downloadIdentifiers.ProcessMovie(si, newFile));
                        }

                        if (newFile.FullName != fi.FullName)
                        {
                            //Check that the file does not already exist
                            //if (FileHelper.FileExistsCaseSensitive(newFile.FullName))
                            if (FileHelper.FileExistsCaseSensitive(files, newFile))
                            {
                                LOGGER.Warn(
                                    $"Identified that {fi.FullName} should be renamed to {newName}, but it already exists.");
                            }
                            else
                            {
                                LOGGER.Info($"Identified that {fi.FullName} should be renamed to {newName}.");
                                Doc.TheActionList.Add(new ActionCopyMoveRename(ActionCopyMoveRename.Op.rename, fi,
                                                                               newFile, si, false, null, Doc));

                                //The following section informs the DownloadIdentifers that we already plan to
                                //copy a file in the appropriate place and they do not need to worry about downloading
                                //one for that purpose
                                downloadIdentifiers.NotifyComplete(newFile);
                            }
                        }
                        else
                        {
                            if (fi.IsMovieFile())
                            {
                                //File is correct name
                                LOGGER.Debug($"Identified that {fi.FullName} is in the right place. Marking it as 'seen'.");
                                //Record this movie as seen

                                TVSettings.Instance.PreviouslySeenMovies.EnsureAdded(si);
                                if (TVSettings.Instance.IgnorePreviouslySeenMovies)
                                {
                                    Doc.SetDirty();
                                }
                            }
                        }
                    }
                } // foreach file in folder
            }
            else
            {
                if (movieFiles.First().IsMovieFile())
                {
                    //File is correct name
                    LOGGER.Debug($"Identified that {movieFiles.First().FullName} is in the right place. Marking it as 'seen'.");
                    //Record this movie as seen

                    TVSettings.Instance.PreviouslySeenMovies.EnsureAdded(si);
                    if (TVSettings.Instance.IgnorePreviouslySeenMovies)
                    {
                        Doc.SetDirty();
                    }
                }
            }
        }
Exemplo n.º 5
0
 /**
  * @see com.itextpdf.text.pdf.mc.MCParser.PdfOperator#process(com.itextpdf.text.pdf.mc.MCParser, com.itextpdf.text.pdf.PdfLiteral, java.util.List)
  */
 virtual public void Process(MCParser parser, PdfLiteral opr, IList <PdfObject> operands)
 {
     LOGGER.Debug("ET: end text block");
     parser.SetInText(false);
     parser.PrintOperator(opr, operands);
 }
Exemplo n.º 6
0
 /**
  * @see com.itextpdf.text.pdf.mc.MCParser.PdfOperator#process(com.itextpdf.text.pdf.mc.MCParser, com.itextpdf.text.pdf.PdfLiteral, java.util.List)
  */
 virtual public void Process(MCParser parser, PdfLiteral opr, IList <PdfObject> operands)
 {
     LOGGER.Debug("BT: begin text on hold");
     parser.SetInText(true);
 }