Beispiel #1
0
        /// <summary>
        /// 提示信息
        /// </summary>
        /// <param name="tips"></param>
        /// <param name="showBox">是否显示弹窗</param>
        public static void ShowTips(string tips, bool isShowMessageBox)
        {
            AppCurrent.Tip.Tips += string.Format("{0} {1}\r\n", DateTime.Now.ToString("HH:mm:ss"), tips);
            var log = new OperationLog
            {
                User     = AppCurrent.User,
                DateTime = DateTime.Now,
                Content  = tips
            };

            Context.OperationContext.Operations.Add(log);
            Context.OperationContext.SaveChanges();
            if (isShowMessageBox)
            {
                Tip.Alert(tips);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 导出Excel方法
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="DefaultFileName">默认文件名</param>
        /// <param name="SheetName">Excel表名</param>
        public static void Export(DataTable dt, string DefaultFileName, string SheetName)
        {
            if (dt == null || dt.Rows.Count < 1)
            {
                Tip.Alert("尚无数据!");
                return;
            }

            SaveFileDialog kk = new SaveFileDialog();

            kk.Title       = "保存EXECL文件";
            kk.Filter      = "EXECL文件(*.xlsx) |*.xlsx |所有文件(*.*) |*.*";
            kk.FilterIndex = 1;
            //默认文件名
            kk.FileName = DefaultFileName;

            if (kk.ShowDialog() == true)
            {
                string FileName = kk.FileName;
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                try
                {
                    using (ExcelHelper excelHelper = new ExcelHelper(FileName))
                    {
                        int count = excelHelper.DataTableToExcel(dt, SheetName, true);
                        if (count > 0)
                        {
                            Tip.Alert("导出为Excel成功!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Tip.Alert("导出Excel出现异常: \r\n" + ex.Message);
                }
            }
        }