Exemplo 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;
            }
        }