Exemplo n.º 1
0
 /// <summary>
 /// 导出文件
 /// </summary>
 /// <param name="fileUrl">保存位置</param>
 /// <param name="files">文件类型</param>
 public bool ExportFile(string fileUrl, string files)
 {
     if (dt == null && dt.Rows.Count > 0)
     {
         MessageCommon.ShowErr("结果集不能为空!");
     }
     if (files == FileEnum.JsonFiles)
     {
         JsonUtilities jsonUtilities = new JsonUtilities();
         return(jsonUtilities.SaveJson(dt, fileUrl));
     }
     else if (files == FileEnum.ExcelFiles)
     {
         ExcelUtilities excelUtilities = new ExcelUtilities();
         return(excelUtilities.ToExcel(dt, fileUrl));
     }
     else if (files == FileEnum.XMLFiles)
     {
         XmlUtilities xmlUtilities = new XmlUtilities();
         string       xml          = xmlUtilities.ConvertDataTableToXML(dt);
         return(xmlUtilities.SaveXml(xml, fileUrl));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        private void 导出_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(数据模式_保存位置.Text))
            {
                MessageCommon.ShowErr("保存路径不能为空!");
                return;
            }
            string files = string.Empty;

            // 获取用户选择控件
            foreach (Control c in 数据模式_文件类型.Controls)
            {
                if (c is RadioButton && ((RadioButton)c).Checked == true)
                {
                    files = ((RadioButton)c).Name;
                }
            }
            if (sqlData.ExportFile(数据模式_保存位置.Text, files))
            {
                MessageCommon.ShowInf("导出成功!");
            }
            else
            {
                MessageCommon.ShowInf("导出失败!");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Xml转Excel操作
        /// </summary>
        private void XmlToExcels()
        {
            XmlUtilities xmlUtilities = new XmlUtilities();
            var          data         = xmlUtilities.ConvertXMLToDataSet(文件路径.Text);

            if (data != null && data.Rows.Count > 0)
            {
                ExcelUtilities excelUtilities = new ExcelUtilities();
                if (excelUtilities.ToExcel(data, 文件夹路径.Text))
                {
                    MessageCommon.ShowInf("转换成功");
                }
                else
                {
                    MessageCommon.ShowErr("转换失败");
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// json转Excel操作
        /// </summary>
        private void JsonToExcels()
        {
            JsonUtilities jsonUtilities = new JsonUtilities();
            var           dataTale      = jsonUtilities.JsonToData(文件路径.Text);

            if (dataTale != null && dataTale.Rows.Count > 0)
            {
                ExcelUtilities excelUtilities = new ExcelUtilities();
                if (excelUtilities.ToExcel(dataTale, 文件夹路径.Text))
                {
                    MessageCommon.ShowInf("转换成功");
                }
                else
                {
                    MessageCommon.ShowErr("转换失败");
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 打开文件
        /// </summary>
        /// <returns></returns>
        private string OpenFileDialog()
        {
            //初始化一个OpenFileDialog类
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";                      //默认打开路径
            //openFileDialog.Filter = "文本文件|*.txt|word文件|*.doc;*.docx|所有文件|*.*";//过滤文件格式
            openFileDialog.Filter           = GetFilter(FileClass).Filter; //过滤文件格式
            openFileDialog.FilterIndex      = 2;                           //格式索引
            openFileDialog.RestoreDirectory = false;                       //每次打卡文件是否恢复默认路径

            //判断用户是否正确的选择了文件
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //fileDialog.FileName:文件的全路径,如“C:\Users\lenovo\Desktop\新建文件夹\微信图片_20190401154431.jpg”
                //fileDialog.SafeFileName:文件的名称,如“微信图片_20190401154431.jpg”
                //----------------此处和openFileDialog1.Filter写一个即可
                //获取用户选择文件的后缀名
                string extension = Path.GetExtension(openFileDialog.FileName);
                //声明允许的后缀名
                //string[] str = new string[] { ".gif", ".jpge", ".jpg" };
                string[] str = GetFilter(FileClass).Extension;
                if (!((IList)str).Contains(extension))
                {
                    MessageCommon.ShowErr("请上传正确的文件类型!");
                }
                else
                {
                    //获取用户选择的文件,并判断文件大小不能超过20K,fileInfo.Length是以字节为单位的
                    //FileInfo fileInfo = new FileInfo(fileDialog.FileName);
                    //if (fileInfo.Length > 20480)
                    //{
                    //    MessageBox.Show("上传的图片不能大于20K");
                    //}
                    //else
                    //{
                    //    //在这里就可以写获取到正确文件后的代码了
                    //}
                    return(openFileDialog.FileName);
                }
            }
            return(string.Empty);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Excel转Json操作
        /// </summary>
        private void ExcelToXmls()
        {
            ExcelUtilities excelUtilities = new ExcelUtilities();
            var            data           = excelUtilities.ExcelToDataTable(文件路径.Text);

            if (data != null && data.Rows.Count > 0)
            {
                XmlUtilities xmlUtilities = new XmlUtilities();
                string       xml          = xmlUtilities.ConvertDataTableToXML(data);
                if (xmlUtilities.SaveXml(xml, 文件夹路径.Text))
                {
                    MessageCommon.ShowInf("转换成功");
                }
                else
                {
                    MessageCommon.ShowErr("转换失败");
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Excel转Json操作
        /// </summary>
        private void ExcelToJsons()
        {
            ExcelUtilities excelUtilities = new ExcelUtilities();
            var            data           = excelUtilities.ExcelToDataTable(文件路径.Text);

            if (data != null && data.Rows.Count > 0)
            {
                JsonUtilities jsonUtilities = new JsonUtilities();
                jsonUtilities.SaveJson(data, 文件夹路径.Text);
                if (jsonUtilities.SaveJson(data, 文件夹路径.Text))
                {
                    MessageCommon.ShowInf("转换成功");
                }
                else
                {
                    MessageCommon.ShowErr("转换失败");
                }
            }
        }
Exemplo n.º 8
0
 static void Main()
 {
     try
     {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Process instance = RunningInstance();
         if (instance == null)
         {
             Application.Run(new 结果集());
         }
         else
         {
             HandleRunningInstance(instance);
         }
     }
     catch (Exception ex)
     {
         MessageCommon.ShowErr("亲!程序已炸!");
         LogUtilities.Error(ex.ToString());
     }
 }
Exemplo n.º 9
0
        private void 查询_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(脚本语句_Value.Text))
            {
                MessageCommon.ShowErr("脚本语句不可为空!");
                return;
            }

            #region 绑定数据
            string sqls = string.Empty;
            // 获取用户选择控件
            foreach (Control c in 数据模式_数据类型.Controls)
            {
                if (c is RadioButton && ((RadioButton)c).Checked == true)
                {
                    sqls = ((RadioButton)c).Name;
                }
            }
            SqlUserDto sqlUsers = new SqlUserDto();
            sqlUsers.Server       = 数据库ID_Value.Text;
            sqlUsers.DataBase     = 库_Value.Text;
            sqlUsers.Uid          = 用户名_Value.Text;
            sqlUsers.Pwd          = 密码_Value.Text;
            sqlUsers.DatabaseType = sqls;
            #endregion
            #region 判断窗体是否已打开
            Form test = Application.OpenForms["SqlDataShow"]; //查找是否打开过about窗体 
            if ((test == null) || (test.IsDisposed))          //如果没有打开过
            {
                sqlData = new SqlDataShow();
                sqlData.BingData(脚本语句_Value.Text, sqlUsers);
                sqlData.Show();   //打开子窗体出来
            }
            else
            {
                sqlData.Activate(); //如果已经打开过就让其获得焦点  
            }
            #endregion
        }