Example #1
0
        private void btnExportDetail_Click(object sender, EventArgs e)
        {
            if (this.winGridView1.gridView1.RowCount == 0)
            {
                return;
            }

            #region 构造数据列表
            //HandNo,ItemNo,ItemName,MapNo,Specification,Material,ItemBigType,ItemType,Unit,Price,Quantity,Amount,Source,StoragePos,UsagePos,d.WareHouse,d.Dept
            string    columns  = "货单号,项目编号,项目名称,图号,规格型号,材质,备件属类,备件类别,单位,单价|decimal,数量|int,金额|decimal,来源,库位,使用位置,库房,部门";
            DataTable dtDetail = DataTableHelper.CreateTable(columns);

            for (int i = 0; i < winGridView1.gridView1.RowCount; i++)
            {
                string ID = winGridView1.gridView1.GetRowCellDisplayText(i, "ID");
                if (!string.IsNullOrEmpty(ID))
                {
                    DataTable dt = BLLFactory <PurchaseDetail> .Instance.GetPurchaseDetailReportByID(Convert.ToInt32(ID));

                    dt.Rows.Add(dt.NewRow());

                    //复制到中文列的表中
                    for (int k = 0; k < dt.Rows.Count; k++)
                    {
                        DataRow r = dtDetail.NewRow();
                        for (int j = 0; j < dt.Columns.Count; j++)
                        {
                            r[j] = dt.Rows[k][j];
                        }
                        dtDetail.Rows.Add(r);
                    }
                }
            }
            #endregion

            #region 导出数据操作
            SpecialDirectories sp         = new SpecialDirectories();
            string             fileToSave = FileDialogHelper.SaveExcel(string.Format("出库单明细({0})", DateTime.Now.ToString("yyyy-MM-dd")), sp.Desktop);
            if (string.IsNullOrEmpty(fileToSave))
            {
                return;
            }

            try
            {
                string fileName = fileToSave;
                string outError = "";
                AsposeExcelTools.DataTableToExcel2(dtDetail, fileName, out outError);
                if (!string.IsNullOrEmpty(outError))
                {
                    MessageDxUtil.ShowError(outError);
                    LogTextHelper.Error(outError);
                }
                else
                {
                    Process.Start(fileName);
                }
            }
            catch (Exception ex)
            {
                MessageDxUtil.ShowError(ex.Message);
                LogTextHelper.Error(ex);
            }
            #endregion
        }
Example #2
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            XlsDocument xls = new XlsDocument();

            //添加文件属性
            xls.SummaryInformation.Author          = "伍华聪"; //作者
            xls.SummaryInformation.Subject         = "测试Myxls的Excel文件生成";
            xls.DocumentSummaryInformation.Company = "http://www.iqidi.com 广州爱启迪技术有限公司";

            Worksheet sheet = xls.Workbook.Worksheets.Add("sheet1");//状态栏标题名称
            Cells     cells = sheet.Cells;

            XF xf = xls.NewXF();

            xf.HorizontalAlignment = HorizontalAlignments.Centered;
            xf.VerticalAlignment   = VerticalAlignments.Centered;
            xf.Pattern             = 1;
            xf.PatternColor        = Colors.Default30;
            xf.UseBorder           = true;
            xf.TopLineStyle        = 1;
            xf.TopLineColor        = Colors.Black;
            xf.BottomLineStyle     = 1;
            xf.BottomLineColor     = Colors.Black;
            xf.LeftLineStyle       = 1;
            xf.LeftLineColor       = Colors.Black;
            xf.RightLineStyle      = 1;
            xf.RightLineColor      = Colors.Black;
            xf.Font.Bold           = true;
            xf.Font.Height         = 11 * 20;
            xf.Font.ColorIndex     = 1;

            cells.Add(1, 1, "姓名", xf);
            cells.Add(1, 2, "年龄", xf);
            cells.Add(1, 3, "Email邮箱", xf);
            cells.Add(1, 4, "描述", xf);

            for (int i = 0; i < 500; i++)
            {
                Cell nameCell = cells.Add(i + 2, 1, RandomChinese.GetRandomChinese2(3));
                nameCell.Font.FontFamily = FontFamilies.Roman; //字体
                nameCell.Font.Bold       = true;               //字体为粗体

                cells.Add(i + 2, 2, new Random().Next(20, 50));
                cells.Add(i + 2, 3, "*****@*****.**");
                cells.Add(i + 2, 4, RandomChinese.GetRandomChinese2(50));
                Thread.Sleep(10);
            }

            string saveFile = FileDialogHelper.SaveExcel("wuhuacong.xls", "C:\\");

            if (!string.IsNullOrEmpty(saveFile))
            {
                xls.FileName = saveFile;
                xls.Save(true);

                if (MessageDxUtil.ShowYesNoAndTips("保存成功,是否打开文件?") == System.Windows.Forms.DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start(saveFile);
                }
            }
        }
Example #3
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            try
            {
                if (dt == null || dt.Rows.Count == 0)
                {
                    MessageDxUtil.ShowTips("没有数据需要导出!");
                    return;
                }

                string saveDocFile = FileDialogHelper.SaveExcel(string.Format("{0}.xls", ReportTitle), "C:\\");
                if (!string.IsNullOrEmpty(saveDocFile))
                {
                    Workbook  workbook  = new Workbook();
                    Worksheet worksheet = workbook.Worksheets[0];
                    worksheet.PageSetup.Orientation = PageOrientationType.Landscape; //横向打印
                    worksheet.PageSetup.Zoom        = 100;                           //以100%的缩放模式打开
                    worksheet.PageSetup.PaperSize   = PaperSizeType.PaperA4;

                    #region 表头及说明信息
                    Range range; Cell cell; string content;
                    int   colSpan = 10;
                    range = worksheet.Cells.CreateRange(0, 0, 1, colSpan);
                    range.Merge();
                    range.RowHeight = 20;
                    range.SetStyle(CreateTitleStyle(workbook));
                    cell = range[0, 0];
                    cell.PutValue(ReportTitle);

                    range = worksheet.Cells.CreateRange(1, 0, 1, colSpan);
                    range.Merge();
                    range.RowHeight = 15;
                    cell            = range[0, 0];
                    content         = string.Format("所选查询条件内,总计有{0}个统计项,详细列表如下:", dt.Rows.Count);
                    cell.PutValue(content);

                    #endregion

                    #region 生成报表头部表格
                    Style headStyle   = CreateStyle(workbook, true);
                    Style normalStyle = CreateStyle(workbook, false);
                    int   startRow    = 2;
                    int   startCol    = 0;
                    range = worksheet.Cells.CreateRange(startRow, 0, 2, 1);
                    range.Merge();
                    range.SetStyle(headStyle);
                    cell = range[0, 0];
                    cell.PutValue("序号");
                    cell.SetStyle(headStyle);

                    range = worksheet.Cells.CreateRange(startRow, 1, 2, 1);
                    range.Merge();
                    range.SetStyle(headStyle);
                    range.ColumnWidth = 40;
                    cell = range[0, 0];
                    cell.PutValue("统计项目");
                    cell.SetStyle(headStyle);

                    range = worksheet.Cells.CreateRange(startRow, 2, 2, 1);
                    range.Merge();
                    range.SetStyle(headStyle);
                    range.ColumnWidth = 40;
                    cell = range[0, 0];
                    cell.PutValue("统计值");
                    cell.SetStyle(headStyle);

                    #endregion

                    //写入数据到Excel
                    startRow = startRow + 2;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //添加序号
                        cell = worksheet.Cells[startRow, 0];
                        cell.PutValue(i + 1);
                        cell.SetStyle(normalStyle);

                        startCol = 1;
                        for (int j = 0; j < dt.Columns.Count; j++)
                        {
                            DataRow dr = dt.Rows[i];
                            cell = worksheet.Cells[startRow, startCol];
                            cell.PutValue(dr[j]);
                            cell.SetStyle(normalStyle);

                            startCol++;
                        }
                        startRow++;
                    }

                    //写入图注
                    startRow += 1;//跳过1行
                    range     = worksheet.Cells.CreateRange(startRow++, 0, 1, colSpan);
                    range.Merge();
                    range.RowHeight = 15;
                    cell            = range[0, 0];
                    cell.PutValue("以饼图展示如下:");

                    //插入图片到Excel里面
                    using (MemoryStream stream = new MemoryStream())
                    {
                        stream.Position = 0;
                        ChartControl chart = (ChartControl)chartPie.Clone();
                        chart.Size = new Size(600, 400);

                        chart.ExportToImage(stream, ImageFormat.Jpeg);
                        worksheet.Pictures.Add(startRow, 0, stream);
                    }

                    //写入图注
                    startRow += 25;//跳过20行
                    range     = worksheet.Cells.CreateRange(startRow++, 0, 1, colSpan);
                    range.Merge();
                    range.RowHeight = 15;
                    cell            = range[0, 0];
                    cell.PutValue("以柱状图展示如下:");

                    //插入图片到Excel里面
                    using (MemoryStream stream = new MemoryStream())
                    {
                        stream.Position = 0;
                        ChartControl chart = (ChartControl)chartBar.Clone();
                        chart.Size = new Size(800, 300);

                        chart.ExportToImage(stream, ImageFormat.Jpeg);
                        worksheet.Pictures.Add(startRow, 0, stream);
                    }

                    workbook.Save(saveDocFile);
                    if (MessageUtil.ShowYesNoAndTips("保存成功,是否打开文件?") == System.Windows.Forms.DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(saveDocFile);
                    }
                }
            }
            catch (Exception ex)
            {
                LogTextHelper.Error(ex);
                MessageUtil.ShowError(ex.Message);
                return;
            }
        }
        private void DownloadOrViewFile(string id, string name)
        {
            try
            {
                FileUploadInfo fileInfo = BLLFactory <FileUpload> .Instance.Download(id);

                if (fileInfo != null && fileInfo.FileData != null)
                {
                    string extension = fileInfo.FileExtend.ToLower();
                    bool   isImage   = MyHelper.IsImageFile(extension);
                    if (isImage)
                    {
                        FrmPicturePreview frm    = new FrmPicturePreview();
                        Bitmap            bitmap = ImageHelper.BitmapFromBytes(fileInfo.FileData);
                        frm.ImageObj = bitmap;
                        frm.ShowDialog();
                    }
                    else
                    {
                        if (extension.Contains(".pdf"))
                        {
                            FrmPDFView dlg = new FrmPDFView();
                            dlg.Extension = extension;
                            dlg.Stream    = FileUtil.BytesToStream(fileInfo.FileData);
                            dlg.ShowDialog();
                        }
                        else if (extension.Contains(".xls") || extension.Contains(".xlsx") || extension.Contains(".csv"))
                        {
                            FrmExcelView dlg = new FrmExcelView();
                            dlg.Extension = extension;
                            dlg.Stream    = FileUtil.BytesToStream(fileInfo.FileData);
                            dlg.ShowDialog();
                        }
                        else if (extension.Contains(".doc") || extension.Contains(".docx") || extension.Contains(".rtf"))
                        {
                            FrmWordView dlg = new FrmWordView();
                            dlg.Extension = extension;
                            dlg.Stream    = FileUtil.BytesToStream(fileInfo.FileData);
                            dlg.ShowDialog();
                        }
                        else
                        {
                            #region 非图片文件下载到本地
                            string saveFile = FileDialogHelper.SaveFile(name);
                            if (!string.IsNullOrEmpty(saveFile))
                            {
                                FileUtil.CreateFile(saveFile, fileInfo.FileData);
                                if (File.Exists(saveFile))
                                {
                                    if (MessageDxUtil.ShowYesNoAndTips("文件下载成功,是否打开文件?") == System.Windows.Forms.DialogResult.Yes)
                                    {
                                        System.Diagnostics.Process.Start(saveFile);
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogTextHelper.Error(ex);
                MessageDxUtil.ShowError("保存文件出现错误。具体如下:\r\n" + ex.Message);
            }
        }
        public AddWalletPageViewModel(
            WalletManagerViewModel walletManagerViewModel,
            BitcoinStore store)
        {
            Title         = "Add Wallet";
            SelectionMode = NavBarItemSelectionMode.Button;
            var walletManager = walletManagerViewModel.WalletManager;
            var network       = walletManager.Network;

            var enableBack = default(IDisposable);

            this.WhenAnyValue(x => x.CurrentTarget)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x =>
            {
                enableBack?.Dispose();
                enableBack = Navigate()
                             .WhenAnyValue(y => y.CanNavigateBack)
                             .Subscribe(y => EnableBack = y);
            });

            this.WhenAnyValue(x => x.WalletName)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Select(x => !string.IsNullOrWhiteSpace(x))
            .Subscribe(x => OptionsEnabled = x && !Validations.Any);

            RecoverWalletCommand = ReactiveCommand.Create(
                () => Navigate().To(new RecoverWalletViewModel(WalletName, walletManagerViewModel)));

            ImportWalletCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    var filePath = await FileDialogHelper.ShowOpenFileDialogAsync("Import wallet file", new[] { "json" });

                    if (filePath is null)
                    {
                        return;
                    }

                    var keyManager = await ImportWalletHelper.ImportWalletAsync(walletManager, WalletName, filePath);

                    // TODO: get the type from the wallet file
                    Navigate().To(new AddedWalletPageViewModel(walletManager, keyManager));
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    await ShowErrorAsync(Title, ex.ToUserFriendlyString(), "The wallet file was not valid or compatible with Wasabi.");
                }
            });

            ConnectHardwareWalletCommand = ReactiveCommand.Create(() => Navigate().To(new ConnectHardwareWalletViewModel(WalletName, walletManagerViewModel)));

            CreateWalletCommand = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var dialogResult = await NavigateDialog(
                    new CreatePasswordDialogViewModel("Type the password of the wallet and click Continue."));

                if (dialogResult.Result is { } password)
                {
                    var(km, mnemonic) = await Task.Run(
                        () =>
                    {
                        var walletGenerator = new WalletGenerator(
                            walletManager.WalletDirectories.WalletsDir,
                            network)
                        {
                            TipHeight = store.SmartHeaderChain.TipHeight
                        };
                        return(walletGenerator.GenerateWallet(WalletName, password));
                    });

                    Navigate().To(new RecoveryWordsViewModel(km, mnemonic, walletManager));
                }
            });

            this.ValidateProperty(x => x.WalletName, errors => ValidateWalletName(errors, walletManager, WalletName));

            EnableAutoBusyOn(CreateWalletCommand);
        }
Example #6
0
        private void simpleButton4_Click(object sender, EventArgs e)
        {
            string path = FileDialogHelper.OpenDir();

            string recordFileName = "\\" + "缺少文件.txt";

            if (FileUtil.FileIsExist(path + recordFileName))
            {
                FileUtil.DeleteFile(path + recordFileName);
            }
            FileUtil.CreateFile(path + recordFileName);


            if (!string.IsNullOrEmpty(path))
            {
                string[] dirs = DirectoryUtil.GetDirectories(path);

                Dictionary <string, bool> a = new Dictionary <string, bool>();
                // 判断是否是子目录
                foreach (var d in dirs)
                {
                    string[] subdirs = DirectoryUtil.GetDirectories(d, "*", true);

                    string[] tmpdsname = d.Split('\\');
                    string   dsname    = tmpdsname[tmpdsname.Length - 1].Split('$')[0];

                    foreach (var dir in subdirs)
                    {
                        string[] tmpdirsname = dir.Split('\\');
                        string   dirname     = tmpdirsname[tmpdirsname.Length - 1].Split('$')[0];

                        a[dsname + dirname] = false;

                        if (dirname.Substring(0, 1) == "第" && dirname.Substring(dirname.Length - 1, 1) == "章")
                        {
                            continue;
                        }

                        Int32 readCount = 0;
                        foreach (var dir2 in subdirs)
                        {
                            string[] tmpdir2sname = dir2.Split('\\');
                            string   dir2name     = tmpdir2sname[tmpdir2sname.Length - 1].Split('$')[0];

                            if (dir2name != dirname && dirname.Contains(dir2name) && dirname.IndexOf(dir2name) == 0)
                            {
                                a[dsname + dirname] = true;
                                break;
                            }

                            if (dir2name != dirname && dir2name.Contains(dirname) && dir2name.IndexOf(dirname) == 0)
                            {
                                a[dsname + dirname] = false;
                                break;
                            }

                            // 已经遍历玩了,则还没有找到就是没有子目录
                            readCount++;
                            if (subdirs.Length == readCount)
                            {
                                a[dsname + dirname] = true;
                                break;
                            }
                        }
                    }
                }

                foreach (var d in dirs)
                {
                    string[] subdirs = DirectoryUtil.GetDirectories(d, "*", true);

                    string[] tmpdsname = d.Split('\\');
                    string   dsname    = tmpdsname[tmpdsname.Length - 1].Split('$')[0];

                    foreach (var dir in subdirs)
                    {
                        string[] tmpdirsname = dir.Split('\\');
                        string   dirname     = tmpdirsname[tmpdirsname.Length - 1].Split('$')[0];

                        if (dirname.Substring(0, 1) == "第" && dirname.Substring(dirname.Length - 1, 1) == "章")
                        {
                            continue;
                        }
                        // 是子目录
                        if (a[dsname + dirname])
                        {
                            if (dir.Length > 250)
                            {
                                MessageDxUtil.ShowTips("目录超过限制长度[" + dir + "]");
                                continue;
                            }

                            if (DirectoryUtil.IsEmptyDirectory(dir))
                            {
                                FileUtil.AppendText(path + recordFileName, string.Format("{0}\r\n", dir), Encoding.UTF8);
                            }
                        }
                    }
                }

                MessageDxUtil.ShowTips("操作完成");
            }
        }
Example #7
0
        private void simpleButton1_Click(object sender, System.EventArgs e)
        {
            string path = FileDialogHelper.OpenDir();

            if (!string.IsNullOrEmpty(path))
            {
                string[] dirs = DirectoryUtil.GetDirectories(path);

                Dictionary <string, bool> a = new Dictionary <string, bool>();
                // 判断是否是子目录
                foreach (var d in dirs)
                {
                    string[] subdirs = DirectoryUtil.GetDirectories(d, "*", true);

                    string[] tmpdsname = d.Split('\\');
                    string   dsname    = tmpdsname[tmpdsname.Length - 1].Split('$')[0];

                    foreach (var dir in subdirs)
                    {
                        string[] tmpdirsname = dir.Split('\\');
                        string   dirname     = tmpdirsname[tmpdirsname.Length - 1].Split('$')[0];

                        a[dsname + dirname] = false;

                        if (dirname.Substring(0, 1) == "第" && dirname.Substring(dirname.Length - 1, 1) == "章")
                        {
                            continue;
                        }

                        Int32 readCount = 0;
                        foreach (var dir2 in subdirs)
                        {
                            string[] tmpdir2sname = dir2.Split('\\');
                            string   dir2name     = tmpdir2sname[tmpdir2sname.Length - 1].Split('$')[0];

                            if (dir2name != dirname && dirname.Contains(dir2name) && dirname.IndexOf(dir2name) == 0)
                            {
                                a[dsname + dirname] = true;
                                break;
                            }

                            if (dir2name != dirname && dir2name.Contains(dirname) && dir2name.IndexOf(dirname) == 0)
                            {
                                a[dsname + dirname] = false;
                                break;
                            }
                            // 已经遍历玩了,则还没有找到就是没有子目录
                            readCount++;
                            if (subdirs.Length == readCount)
                            {
                                a[dsname + dirname] = true;
                                break;
                            }
                        }
                    }
                }

                foreach (var d in dirs)
                {
                    string[] subdirs = DirectoryUtil.GetDirectories(d, "*", true);

                    string[] tmpdsname = d.Split('\\');
                    string   dsname    = tmpdsname[tmpdsname.Length - 1].Split('$')[0];

                    foreach (var dir in subdirs)
                    {
                        string[] tmpdirsname = dir.Split('\\');
                        string   dirname     = tmpdirsname[tmpdirsname.Length - 1].Split('$')[0];

                        if (dirname.Substring(0, 1) == "第" && dirname.Substring(dirname.Length - 1, 1) == "章")
                        {
                            continue;
                        }
                        // 是子目录
                        if (a[dsname + dirname])
                        {
                            if (dir.Length > 250)
                            {
                                MessageDxUtil.ShowTips("目录超过限制长度[" + dir + "]");
                                continue;
                            }

                            if ((dir + "\\" + tmpdirsname[tmpdirsname.Length - 1].Split('$')[1] + ".txt").Length > 250)
                            {
                                FileUtil.WriteText(dir + "\\1.txt", tmpdirsname[tmpdirsname.Length - 1].Split('$')[1], Encoding.UTF8);
                            }
                            else
                            {
                                FileUtil.WriteText(dir + "\\" + tmpdirsname[tmpdirsname.Length - 1].Split('$')[1] + ".txt", tmpdirsname[tmpdirsname.Length - 1].Split('$')[1], Encoding.UTF8);
                            }
                        }
                    }
                }

                MessageDxUtil.ShowTips("操作完成");
            }
        }
Example #8
0
        private void btnExportBill_Click(object sender, EventArgs e)
        {
            #region 准备数据
            string    columns = @"流水号,备注,供货商,操作员,库房名称,备件编号(pm码),备件名称,图号,规格型号,材质,备件属类,备件类别,单位,最新单价(元),出库数量,总价,出库日期,来源,库位,部门,使用位置";
            DataTable dt      = DataTableHelper.CreateTable(columns);
            DataRow   row     = null;
            for (int i = 0; i < this.lvwDetail.gridView1.RowCount; i++)
            {
                PurchaseDetailInfo info = lvwDetail.gridView1.GetRow(i) as PurchaseDetailInfo;
                if (info != null)
                {
                    row = dt.NewRow();

                    /*row["流水号"] = this.txtHandNo.Text;
                     * row["备注"] = this.txtNote.Text;
                     * row["供货商"] = this.txtPickingPeople.Text;
                     * row["操作员"] = this.txtCreator.Text;
                     * row["出库日期"] = this.txtCreateDate.DateTime.ToString();
                     * row["库房名称"] = info.WareHouse;
                     * row["备件编号(pm码)"] = info.ItemNo;
                     * row["备件名称"] = info.ItemName;
                     * row["图号"] = info.MapNo;
                     * row["规格型号"] = info.Specification;
                     * row["材质"] = info.Material;
                     * row["备件属类"] = info.ItemBigType;
                     * row["备件类别"] = info.ItemType;
                     * row["单位"] = info.Unit;
                     * row["最新单价(元)"] = info.Price.ToString("C2");
                     * row["出库数量"] = info.Quantity.ToString();
                     * row["总价"] = info.Amount.ToString("C2");
                     * row["来源"] = info.Source;
                     * row["库位"] = info.StoragePos;
                     * row["部门"] = info.Dept;
                     * row["使用位置"] = info.UsagePos;*/
                    dt.Rows.Add(row);
                }
            }
            #endregion

            #region 导出数据
            try
            {
                SpecialDirectories sp       = new SpecialDirectories();
                string             fileName = FileDialogHelper.SaveExcel(string.Format("出库单({0})", DateTimeHelper.GetServerDate()), sp.Desktop);
                if (string.IsNullOrEmpty(fileName))
                {
                    return;
                }
                string outError = "";
                AsposeExcelTools.DataTableToExcel2(dt, fileName, out outError);
                if (!string.IsNullOrEmpty(outError))
                {
                    LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, outError, typeof(FrmPurchase));
                    MessageDxUtil.ShowError(outError);
                }
                else
                {
                    Process.Start(fileName);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmPurchase));
                MessageDxUtil.ShowError(ex.Message);
            }
            #endregion
        }
Example #9
0
        /// <summary>
        /// 导出Excel的操作
        /// </summary>
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (!HasFunction("User/export"))
            {
                MessageDxUtil.ShowError(Const.NoAuthMsg);
                return;
            }

            string file = FileDialogHelper.SaveExcel(string.Format("{0}.xls", moduleName));

            if (!string.IsNullOrEmpty(file))
            {
                List <UserInfo> list = new List <UserInfo>();

                TreeNode selectedNode = this.treeRole.SelectedNode;
                if (isUseRoleSearch && selectedNode != null && selectedNode.Tag != null)
                {
                    string roleId = selectedNode.Tag.ToString();
                    if (!string.IsNullOrEmpty(roleId))
                    {
                        list = BLLFactory <User> .Instance.GetUsersByRole(roleId.ToInt32());
                    }
                }
                else
                {
                    string where = GetConditionSql();
                    list         = BLLFactory <User> .Instance.Find(where);
                }

                DataTable dtNew = DataTableHelper.CreateTable("序号|int,用户编码,用户名/登录名,用户全名,用户呢称,是否过期,职务头衔,身份证号码,移动电话,办公电话,家庭电话,邮件地址,住址,办公地址,性别,出生日期,QQ号码,个性签名,审核状态,备注,自定义字段,默认部门名称,所属公司名称,排序码");
                DataRow   dr;
                int       j         = 1;
                DateTime  dtDefault = Convert.ToDateTime("1900-01-01");
                for (int i = 0; i < list.Count; i++)
                {
                    dr            = dtNew.NewRow();
                    dr["序号"]      = j++;
                    dr["用户编码"]    = list[i].HandNo;
                    dr["用户名/登录名"] = list[i].Name;
                    dr["用户全名"]    = list[i].FullName;
                    dr["用户呢称"]    = list[i].Nickname;
                    dr["是否过期"]    = list[i].IsExpire ? "1" : "0";
                    dr["职务头衔"]    = list[i].Title;
                    dr["身份证号码"]   = list[i].IdentityCard;
                    dr["移动电话"]    = list[i].MobilePhone;
                    dr["办公电话"]    = list[i].OfficePhone;
                    dr["家庭电话"]    = list[i].HomePhone;
                    dr["邮件地址"]    = list[i].Email;
                    dr["住址"]      = list[i].Address;
                    dr["办公地址"]    = list[i].WorkAddr;
                    dr["性别"]      = list[i].Gender;
                    if (list[i].Birthday > dtDefault)
                    {
                        dr["出生日期"] = list[i].Birthday;
                    }
                    dr["QQ号码"]   = list[i].QQ;
                    dr["个性签名"]   = list[i].Signature;
                    dr["审核状态"]   = list[i].AuditStatus;
                    dr["备注"]     = list[i].Note;
                    dr["自定义字段"]  = list[i].CustomField;
                    dr["默认部门名称"] = list[i].DeptName;
                    dr["所属公司名称"] = list[i].CompanyName;
                    dr["排序码"]    = list[i].Seq;
                    dtNew.Rows.Add(dr);
                }

                try
                {
                    string error = "";
                    AsposeExcelTools.DataTableToExcel2(dtNew, file, out error);
                    if (!string.IsNullOrEmpty(error))
                    {
                        MessageDxUtil.ShowError(string.Format("导出Excel出现错误:{0}", error));
                    }
                    else
                    {
                        if (MessageDxUtil.ShowYesNoAndTips("导出成功,是否打开文件?") == System.Windows.Forms.DialogResult.Yes)
                        {
                            System.Diagnostics.Process.Start(file);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmUser));
                    MessageDxUtil.ShowError(ex.Message);
                }
            }
        }