Ejemplo n.º 1
0
        private void openSelectScriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.panelFields.Controls.Clear();
            this.panelFields.Visible = false;
            this.panelDisp.Visible   = false;

            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.InitialDirectory = ConfigurationManager.AppSettings["InitDir"];
            fileDialog.Filter           = @"SQL files (*.sql)|*.sql|All files (*.*)|*.*";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string       file         = ReadFile(fileDialog.FileName);
                TableObjects tableObjects = ParseSelectStatement(file);
                int          i            = 0;
                foreach (Field f in tableObjects.Fields)
                {
                    fieldControl fc = new fieldControl();

                    fc.Location     = new Point(0, i);
                    fc.lblName.Text = f.Name;
                    this.panelFields.Controls.Add(fc);
                    i = i + 30;
                }
                this.panelFields.Refresh();
                this.btnGenerateSQL.Visible = true;
                this.panelFields.Visible    = true;
                this.panelDisp.Visible      = true;
                this.label5.Text            = tableObjects.TableName;
            }
        }
Ejemplo n.º 2
0
        public void SetNewsKeyWords(int id, string names, string range)
        {
            var count = m_db.ExecuteScalar <int>("select count(*) from dbo.Objects where Project_id= @0 ", id);

            if (count == 0)
            {
                var obj = new TableObjects();
                obj.project_id = id;
                obj.names      = names;
                obj.range      = range;
                m_logger.Log(id, "新增监控机构名新闻");
                m_db.Insert(obj);
            }
            else
            {
                m_logger.Log(id, "更新监控机构名新闻");
                m_db.Update <TableObjects>(" set names= @0,range = @1 where Project_id=@2 ", names, range, id);
            }
        }
Ejemplo n.º 3
0
        private TableObjects ParseSelectStatement(string SelectString)
        {
            tableObjects = new TableObjects();
            if (SelectString.ToUpper().IndexOf(" FROM ") > 0)
            {
                tableObjects.TableName = SelectString.ToUpper().Substring(SelectString.ToUpper().IndexOf(" FROM ") + 6, SelectString.Length - (SelectString.ToUpper().IndexOf(" FROM ") + 6));
            }
            else
            {
                tableObjects.TableName = SelectString.ToUpper().Substring(SelectString.ToUpper().IndexOf("FROM ") + 5, SelectString.Length - (SelectString.ToUpper().IndexOf("FROM ") + 5));
            }
            //tableObjects.TableName = SelectString.ToUpper().Substring(SelectString.ToUpper().IndexOf(" FROM ") + 6, SelectString.Length - (SelectString.ToUpper().IndexOf(" FROM ") + 6));
            tableObjects.TableName = tableObjects.TableName.ToUpper().Replace(";", "").Replace("LIMIT 100", "").Replace(" ", "").Replace("ADMIN.", "").Replace(@" ", "").Replace("\t", "").Replace("\r", "").Replace("\n", "");;
            if (SelectString.ToUpper().IndexOf(" FROM ") > 0)
            {
                SelectString = SelectString.ToUpper().Remove(SelectString.ToUpper().IndexOf(" FROM "), SelectString.Length - (SelectString.ToUpper().IndexOf(" FROM ")));
            }
            else
            {
                SelectString = SelectString.ToUpper().Remove(SelectString.ToUpper().IndexOf("FROM "), SelectString.Length - (SelectString.ToUpper().IndexOf("FROM ")));
            }
            SelectString = SelectString.ToUpper().Replace(@"SELECT", "").Replace(@";", "").Replace(@" ", "").Replace("\t", "").Replace("\r", "").Replace("\n", "").Replace("ADMIN", "");

            if (tableObjects.TableName.ToUpper().IndexOf("..") > 0)
            {
                tableObjects.TableName = tableObjects.TableName.ToUpper().Remove(0, (tableObjects.TableName.ToUpper().IndexOf("..") + 2));
            }
            SelectString = SelectString.ToUpper().Replace(@".", "");
            //tableObjects.TableName = SelectString.ToUpper().Substring(SelectString.ToUpper().IndexOf("FROM") + 4, SelectString.Length - (SelectString.ToUpper().IndexOf("FROM") + 4));
            ///SelectString = SelectString.ToUpper().Remove(SelectString.ToUpper().IndexOf("FROM" + tableObjects.TableName));
            tableObjects.Fields = new List <Field>();
            string[] sarray = SelectString.Split(',');
            foreach (string s in sarray)
            {
                Field f = new Field();
                f.Name = s;
                tableObjects.Fields.Add(f);
            }
            return(tableObjects);
        }