Ejemplo n.º 1
0
        private void selectFileBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Multiselect = true;
            fileDialog.Title       = "请选择文件";
            //fileDialog.Filter = "所有文件(*xls*)|*.xls*"; //设置要选择的文件的类型
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                PFWinFormHelper.GridClear(fileDGView);
                foreach (var path in fileDialog.FileNames)
                {
                    var fileName = Path.GetFileName(path);
                    var i        = fileDGView.Rows.Add();
                    TxtFileEncoder.PFEncoding encode = TxtFileEncoder.GetPFEncoding((Stream) new FileStream(path, FileMode.Open));
                    fileDGView.Rows[i].Cells["FileName"].Value   = path;
                    fileDGView.Rows[i].Cells["FileEncode"].Value = encode;

                    //TxtFileEncoder.GetEncoding(i);
                    ////Encoding encode = TxtFileEncoder.GetEncoding(i);
                    //Encoding encode = TxtFileEncoder.GetEncoding((Stream)new FileStream(i, FileMode.Open));
                    //string s = PFDataHelper.ReadFileToString(i, encode);
                    //PFDataHelper.SaveStringToFile(s,Path.Combine(PFDataHelper.BaseDirectory,"OutFile",Path.GetFileName(i)));
                }
                //System.Diagnostics.Process.Start(Path.Combine(PFDataHelper.BaseDirectory, "OutFile"));
            }
        }
        //private void selectSrcBtn_Click(object sender, EventArgs e)
        //{
        //    FolderBrowserDialog fileDialog = new FolderBrowserDialog();
        //    //fileDialog.Multiselect = true;
        //    fileDialog.Description = "请选择src文件夹";
        //    //fileDialog.Filter = "所有文件(*xls*)|*.xls*"; //设置要选择的文件的类型
        //    if (fileDialog.ShowDialog() == DialogResult.OK)
        //    {
        //        srcTBox.Text = fileDialog.SelectedPath;
        //    }
        //}

        //private void selectDstBtn_Click(object sender, EventArgs e)
        //{
        //    FolderBrowserDialog fileDialog = new FolderBrowserDialog();
        //    //fileDialog.Multiselect = true;
        //    fileDialog.Description = "请选择dst文件夹";
        //    //fileDialog.Filter = "所有文件(*xls*)|*.xls*"; //设置要选择的文件的类型
        //    if (fileDialog.ShowDialog() == DialogResult.OK)
        //    {
        //        dstTBox.Text = fileDialog.SelectedPath;
        //    }
        //}
        #endregion

        private void compareBtn_Click(object sender, EventArgs e)
        {
            PFWinFormHelper.GridClear(compareDGView);
            var srcFiles = Directory.GetFiles(srcTBox.Text);
            var dstFiles = Directory.GetFiles(dstTBox.Text);
            var srcList  = srcFiles.Select(a => new CompareModel {
                SrcFileName = Path.GetFileNameWithoutExtension(a)
            }).ToList();
            var dstList = dstFiles.Select(a => new CompareModel {
                DstFileName = Path.GetFileNameWithoutExtension(a)
            }).ToList();
            var leftData = (from first in srcList
                            join last in dstList on first.SrcFileName equals last.DstFileName into temp  //last有可能空
                            from last in temp.DefaultIfEmpty(new CompareModel {
                SrcFileName = first.SrcFileName, DstFileName = default(string)
            })                                                                                                                                   //或 from item in billTypeList.DefaultIfEmpty() //这行的last和第一行的first可在select时取到值
                            select new CompareModel
            {
                SrcFileName = first.SrcFileName,
                DstFileName = last.DstFileName,                   //StockQty = item != null ? item.StockQty : 0, //判断空
            });
            var rightRemainingData = (from r in dstList
                                      where !(from a in leftData select a.SrcFileName).Contains(r.DstFileName)
                                      select new CompareModel
            {
                SrcFileName = default(string),
                DstFileName = r.DstFileName
            });
            var fullOuterjoinData = leftData.Concat(rightRemainingData).ToList();

            //var fullOuterjoinData = PFDataHelper.ListFullJoin<CompareModel, CompareModel,string, CompareModel>(srcList,dstList,
            //    l=>l.SrcFileName,r=>r.DstFileName,lr=> lr.SrcFileName,
            //    (l)=> new CompareModel { SrcFileName = l.SrcFileName, DstFileName = default(string) },
            //    //(r) => new CompareModel { SrcFileName = l.SrcFileName, DstFileName = default(string) },
            //    (l,r) => new CompareModel { SrcFileName = l.SrcFileName, DstFileName = r.DstFileName },
            //    (r) => new CompareModel { SrcFileName = default(string), DstFileName = r.DstFileName }
            //    );


            foreach (var i in fullOuterjoinData)
            {
                var row = compareDGView.Rows.Add();
                compareDGView.Rows[row].Cells["SrcFileName"].Value = i.SrcFileName;
                compareDGView.Rows[row].Cells["DstFileName"].Value = i.DstFileName;
            }
        }
Ejemplo n.º 3
0
        private void packZipBtn_Click(object sender, EventArgs e)
        {
            PFWinFormHelper.GetGridSelectedRows(pathDGView, rows => {
                //var targetPath = "D:\\wxj\\pf_project";
                var targetPath = ConfigurationManager.AppSettings["ZipTargetPath"];
                PFDataHelper.CreateDirectory(targetPath);

                PFWinFormHelper.MultiFuncLoadingFlag = true;        //flag 为false时候,退出执行耗时操作

                MultiFuncLoading loadingfrm = new MultiFuncLoading(this);
                // 将Loaing窗口,注入到 SplashScreenManager 来管理
                SplashScreenManager loading = new SplashScreenManager(loadingfrm);
                loading.ShowLoading();
                // 设置loadingfrm操作必须在调用ShowLoading之后执行
                loadingfrm.SetTxt("多功能Loaidng界面", "拼命加载中...客官耐心等待", "Please Waitting...");

                // try catch 包起来,防止出错
                try
                {
                    int i     = 0;
                    int total = rows.Count;
                    foreach (var row in rows)
                    {
                        i++;
                        ZipUtility zip       = new ZipUtility();
                        var path             = row.Cells["FolderPath"].Value.ToString();
                        var fileName         = row.Cells["FolderName"].Value.ToString();
                        var excludeFolderArr = row.Cells["excludeFolder"].Value == null ? null : row.Cells["excludeFolder"].Value.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        loadingfrm.SetJD("当前:正在打包", "当前进度:" + fileName + "(" + i + "/" + total + ")");

                        zip.ZipFileFromDirectory(path, Path.Combine(targetPath, fileName + "_" + DateTime.Now.ToString("yyyyMMdd") + "_" + ConfigurationManager.AppSettings["FromWhere"] + ".zip"), 4, excludeFolderArr);
                    }
                }
                catch (Exception) { /*可选处理异常*/ }
                finally { loading.CloseWaitForm(); }


                System.Diagnostics.Process.Start(targetPath); //如果是本地访问就直接打开文件夹
            });
        }