Example #1
0
 /// <summary>
 /// 显示sql自定义查询错误信息
 /// </summary>
 /// <param name="c"></param>
 /// <param name="error"></param>
 /// <param name="rand"></param>
 public void tabPageErrorShow(SkinTabPage c, string error, string rand = "")
 {
     try
     {
         if (!RunSqlList.ContainsKey(rand))
         {
             return;
         }                                             //不包含返回
         Models.RunSqlForm rsf = RunSqlList[rand];
         if (rsf.datagridview != null)
         {
             foreach (Control control in c.Controls)
             {
                 if (control.Name == "datagridview" + rand)
                 {
                     c.Controls.Remove(control);
                 }
             }
             // rsf.datagridview.Controls.Clear();
         }
         string errorFctb = "errorfctb" + rand;//当前错误框唯一name
         if (rsf.errorFctb != null)
         {
             foreach (Control control in c.Controls)
             {
                 if (control.Name == errorFctb)
                 {
                     c.Controls.Remove(control);
                 }
             }
             // rsf.datagridview.Controls.Clear();
         }
         FastColoredTextBox fctb = new FastColoredTextBox();//输入框
         fctb.Name     = errorFctb;
         fctb.Location = new Point(10, c.Height / 2);
         fctb.Language = Language.SQL; //sql
         fctb.Width    = c.Width - 30; //控件宽度
         fctb.Height   = 300;          //控件高度
         fctb.ImeMode  = ImeMode.On;   //开启
         c.Controls.Add(fctb);
         rsf.errorFctb    = fctb;
         rsf.datagridview = null; //指定为null
         RunSqlList[rand] = rsf;  //重新赋值
         fctb.BeginInvoke(new Action(() =>
         {
             fctb.Multiline = true;
             fctb.WordWrap  = true;
             error          = error.Substring(0, error.IndexOf('在'));
             fctb.Text      = error;
             fctb.Language  = Language.CSharp;//xml
         }));
     }
     catch (Exception ex) { pLogs.logs(ex.ToString()); }
 }
Example #2
0
        // 菜单选择事件
        private void skinListBox_Click(object sender, EventArgs e)
        {
            SkinListBox slistBox = sender as SkinListBox;

            if (slistBox.SelectedItem != null)
            {
                string menuText = slistBox.SelectedItem.ToString();
                foreach (SkinTabPage item in tabControl.TabPages)
                {
                    if (item.Text == menuText)
                    {
                        tabControl.SelectedTab = item;
                        return;
                    }
                }
                SkinTabPage tabPag = null;
                switch (menuText)
                {
                    #region 系统管理

                case "彩盒上料":
                    //当前窗口设置成mdi容器
                    FrmCH_1 frmCH_1 = new FrmCH_1();
                    //frmCH_1.MdiParent = this;
                    frmCH_1.Text       = menuText;
                    frmCH_1.TopLevel   = false;
                    frmCH_1.Dock       = DockStyle.Fill;
                    tabPag             = new SkinTabPage(menuText);
                    tabPag.Validating += TabPag_Validating;
                    //设置父窗体为panel
                    //frmCH_1.Parent = tabPag;

                    tabPag.Controls.Add(frmCH_1);
                    tabControl.Controls.Add(tabPag);

                    frmCH_1.Show();
                    break;

                    #endregion
                }
                tabControl.SelectedTab = tabPag;
            }
        }
Example #3
0
        private void openFileViewer(Int32 fileID)
        {
            string connectionStringPBox  = DBSource.ConnectionStringPBox;
            string connectionStringPData = DBSource.ConnectionStringPData;
            string commandText           = @"SELECT file_id,file_name,file_type,file_size,file_nodeid FROM FileMemo where file_id = " + fileID;

            helperPBox = new dBHelper(connectionStringPBox);
            if (helperPBox.Load(commandText, "") == true)
            {
                if (fileID > 0 && helperPBox.DataSet.Tables[0].Rows.Count > 0)
                {
                    DataRow       dataRow    = helperPBox.DataSet.Tables[0].Select("file_id=" + fileID)[0];
                    string        filename   = dataRow["file_name"].ToString();
                    string        filetype   = dataRow["file_type"].ToString();
                    List <Byte[]> l_fileData = new FileDBHelper().getFileData(fileID);
                    if (l_fileData.Count == 0)
                    {
                        MessageBoxEx.Show("找不到对应数据文件!");
                        return;
                    }
                    SkinTabPage tp = new SkinTabPage();
                    tp.Text = filename;
                    switch (filetype)
                    {
                    case ".jpg":
                    case ".png":
                    case ".bmp":
                    case ".gif":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            try
                            {
                                Bitmap    bmap         = new Bitmap(Application.StartupPath + "\\temp\\" + filename + filetype);
                                PicViewer uc_picviewer = new PicViewer();
                                uc_picviewer.showPic(filename, bmap);
                                uc_picviewer.Dock = DockStyle.Fill;
                                tp.Controls.Add(uc_picviewer);
                                tabControl_Viewer.TabPages.Add(tp);
                            }
                            catch (Exception exp) { }
                        }
                        break;
                    }

                    case ".doc":
                    case ".docx":
                    case ".xls":
                    case ".xlsx":
                    case ".ppt":
                    case ".pptx":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            DocViewer uc_docviewer = new DocViewer();
                            tp.Tag            = uc_docviewer;
                            uc_docviewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(uc_docviewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            uc_docviewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".txt":
                    case ".sql":
                    case ".log":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            StreamReader sr        = new StreamReader(Application.StartupPath + "\\temp\\" + filename + filetype, Encoding.Default);
                            TxtViewer    txtViewer = new TxtViewer();
                            txtViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(txtViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            txtViewer.showTxt(sr.ReadToEnd());
                            sr.Close();
                        }
                        break;
                    }

                    case ".htm":
                    case ".html":
                    case ".mht":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            WebViewer webViewer = new WebViewer();
                            webViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(webViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            webViewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".pdf":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            PDFViewer pdfViewer = new PDFViewer();
                            pdfViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(pdfViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            pdfViewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".mp4":
                    case ".avi":
                    case ".rm":
                    case ".rmvb":
                    case ".flv":
                    case ".xr":
                    case ".wmv":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                        }
                        FrmPlayer aplayer = new FrmPlayer();
                        aplayer.Text = filename;
                        aplayer.Show();
                        aplayer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        break;
                    }
                    }
                    tabControl_Viewer.SelectedTab = tp;
                }
            }
        }
Example #4
0
        /// <summary>
        /// 显示sql自定义tabpage dataview
        /// </summary>
        /// <param name="c"></param>
        /// <param name="list"></param>
        public void tabPageDataGridViewShow(SkinTabPage c, Dictionary <int, object> list, string rand = "")
        {
            DataGridView dgv = new DataGridView();

            dgv.Name = "datagridview" + rand;//动态name
            if (list.Count <= 0)
            {
                Models.RunSqlForm rsf1 = RunSqlList[rand];
                if (rsf1.datagridview != null)
                {
                    foreach (Control control in c.Controls)
                    {
                        if (control.Name == dgv.Name)
                        {
                            c.Controls.Remove(control);
                        }
                    }
                }
                rsf1.datagridview = dgv;
                RunSqlList[rand]  = rsf1;
                //}));
                dgv.Location = new Point(10, c.Height / 2);
                dgv.Width    = c.Width - 30;
                dgv.Height   = 300;
                c.Controls.Add(dgv);
                MessageBox.Show("没有查询到相关数据!", "查询提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //dgv.BeginInvoke(new Action(() =>
            //{
            Dictionary <string, string> d = (Dictionary <string, string>)list[0];

            foreach (var item in d)
            {
                dgv.Columns.Add(item.Value, item.Key);
            }
            dgv.Rows.Clear();//清理行数
            dgv.Rows.Add(list.Count);
            for (int i = 0; i < list.Count; i++)
            {
                Dictionary <string, string> item = (Dictionary <string, string>)list[i];
                object[] arr = new object[item.Count];
                int      g   = 0;
                foreach (var value in item)
                {
                    dgv.Rows[i].Cells[g].Value = value.Value;
                    g++;
                }
            }
            Models.RunSqlForm rsf = RunSqlList[rand];
            if (rsf.datagridview != null)
            {
                foreach (Control control in c.Controls)
                {
                    if (control.Name == dgv.Name)
                    {
                        c.Controls.Remove(control);
                    }
                }
                // rsf.datagridview.Controls.Clear();
            }
            if (rsf.datagridview != null)
            {
                foreach (Control control in c.Controls)
                {
                    if (control.Name == "errorfctb" + rand)
                    {
                        c.Controls.Remove(control);
                    }
                }
                // rsf.datagridview.Controls.Clear();
            }
            rsf.datagridview = dgv;
            RunSqlList[rand] = rsf;
            //}));
            dgv.Location = new Point(10, c.Height / 2);
            dgv.Width    = c.Width - 30;
            dgv.Height   = 300;
            c.Controls.Add(dgv);
        }
Example #5
0
        /// <summary>
        /// 动态sql生成查询
        /// </summary>
        /// <param name="hash"></param>
        public void createSqlRunTab(string hash)
        {
            try
            {
                string[] array = hash.Split('|');
                string   text  = "";
                Dictionary <string, string> database = new Dictionary <string, string>();
                if (array.Length <= 0)
                {
                    return;
                }
                if (array.Length == 1)//查询主数据库
                {
                    Data.pDataManageClass p = new Data.pDataManageClass();
                    string dataHash         = array[0];
                    database = p.getDataBaseHash(array[0]);
                    array    = new string[4];
                    array[0] = dataHash;
                    array[1] = "database";
                    array[2] = database["type"];
                }
                if (array[2] == Data.DataBaseType.Mysql.ToString())//mysql
                {
                    if (array.Length > 2)
                    {
                        text = array[3];
                        if (array[1] == "database")
                        {
                            text = database["name"];
                        }
                    }
                }

                ContextMenuStrip cms = new ContextMenuStrip(); //关闭右键菜单
                Random           rd  = new Random();
                cms.Items.Add("关闭" + text);                    //添加右键文本
                string      rand = rd.Next(10000, 99999).ToString();
                string      name = text + rand;
                SkinTabPage page = new SkinTabPage();
                page.ToolTipText      = Text + " 查询"; //提示显示完整
                page.Text             = text + " 查询"; //tab显示文本
                page.Name             = name;         //tab name 唯一
                page.ContextMenuStrip = cms;
                cms.Name         = "cms" + rand;
                cms.ItemClicked += closeTabPage;//关联事件
                this.skinTabControl1.Controls.Add(page);

                Label lab = new Label();
                lab.Text     = text + " 查询";
                lab.Location = new Point(10, 5);
                page.Controls.Add(lab);

                SkinButton skbutton = new SkinButton();
                skbutton.Text     = "查询";
                skbutton.Name     = "sqlrun" + rand;
                skbutton.Click   += getRunSql;//点击事件
                skbutton.Location = new Point(10, 30);
                page.Controls.Add(skbutton);

                FastColoredTextBox fctb = new FastColoredTextBox();//输入框
                fctb.Name        = "fctb" + rand;
                fctb.Location    = new Point(10, 80);
                fctb.Language    = Language.SQL;            //sql
                fctb.Width       = page.Width - 30;         //控件宽度
                fctb.Height      = page.Height / 3;         //控件高度
                fctb.ImeMode     = ImeMode.On;              //开启
                fctb.KeyDown    += RunSqlKeysDown;          //键盘事件
                fctb.BorderStyle = BorderStyle.FixedSingle; //边框
                page.Controls.Add(fctb);                    //添加输入框

                skinTabControl1.SelectedTab = page;         //指定tabpage显示

                if (array.Length == 5)                      //打开表查询
                {
                    fctb.BeginInvoke(new Action(() =>
                    {
                        string table = array[4];
                        fctb.Text    = string.Format("select *from {0}", table);
                    }));
                }

                Models.RunSqlForm rsf = new Models.RunSqlForm
                {
                    button     = skbutton,
                    fctb       = fctb,
                    stp        = page,
                    selectHash = hash,
                };
                if (!RunSqlList.ContainsKey(rand))
                {
                    RunSqlList.Add(rand, rsf);//添加列队
                }
                else
                {
                    RunSqlList[rand] = rsf;
                }
            }
            catch (Exception ex) { pLogs.logs(ex.ToString()); }
        }