Exemplo n.º 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()); }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 自定义sql查询键盘事件
 /// </summary>
 /// <param name="obj1"></param>
 /// <param name="obj2"></param>
 public void RunSqlKeysDown(object obj1, object obj2)
 {
     try
     {
         if (obj1 == null)
         {
             return;
         }
         if (obj2 == null)
         {
             return;
         }
         KeyEventArgs keys = (KeyEventArgs)obj2;
         if (keys.KeyData == Keys.F5)//f5运行
         {
             FastColoredTextBox fctb = (FastColoredTextBox)obj1;
             string             name = fctb.Name;
             string             rand = name.Replace("fctb", "");
             Models.RunSqlForm  rsf  = RunSqlList[rand];
             getRunSql(rsf.button, obj2);
         }
     }
     catch (Exception ex) { pLogs.logs(ex.ToString()); }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 自定义sql运行 button按钮
 /// </summary>
 /// <param name="obj1"></param>
 /// <param name="obj2"></param>
 public void getRunSql(object obj1, object obj2)
 {
     try
     {
         if (obj1 == null)
         {
             return;
         }
         SkinButton        sb   = (SkinButton)obj1;
         string            name = sb.Name;
         string            rand = name.Replace("sqlrun", "");
         Models.RunSqlForm rsf  = RunSqlList[rand];
         string            text = rsf.fctb.Text;
         if (text == "")
         {
             return;
         }
         if (rsf.selectHash == null)
         {
             return;
         }
         string   hash  = rsf.selectHash;
         string[] array = hash.Split('|');
         if (array.Length <= 1)                               //主要数据库
         {
             string databaseHash                  = array[0]; //数据库hash
             Data.pDataManageClass       p        = new Data.pDataManageClass();
             Dictionary <string, string> database = p.getDataBaseHash(databaseHash);
             if (database["type"] == Data.DataBaseType.Mysql.ToString())
             {
                 lib.pMysql mysql = new lib.pMysql(database["ip"], database["port"], database["username"], database["password"], "");
                 Dictionary <int, object> List = mysql.getRows(text);
                 if (mysql.error.Length <= 0)
                 {
                     tabPageDataGridViewShow(rsf.stp, List, rand);//结果显示
                 }
                 else
                 {
                     tabPageErrorShow(rsf.stp, mysql.error, rand);//错误显示
                 }
             }
         }
         if (array.Length >= 4)              //表
         {
             string type         = array[2]; //获取类型
             string databaseHash = array[0]; //数据库hash
             string table        = array[3]; //数据库table
             if (type == Data.DataBaseType.Mysql.ToString())
             {
                 Data.pDataManageClass       p        = new Data.pDataManageClass();
                 Dictionary <string, string> database = p.getDataBaseHash(databaseHash);
                 lib.pMysql mysql = new lib.pMysql(database["ip"], database["port"], database["username"], database["password"], table);
                 Dictionary <int, object> List = mysql.getRows(text);
                 if (mysql.error.Length <= 0)
                 {
                     tabPageDataGridViewShow(rsf.stp, List, rand);//结果显示
                 }
                 else
                 {
                     tabPageErrorShow(rsf.stp, mysql.error, rand);//错误显示
                 }
             }
         }
     }
     catch (Exception ex) { pLogs.logs(ex.ToString()); }
     //string name = obj1;
 }
Exemplo n.º 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()); }
        }