Beispiel #1
0
 public SQLiteTable EN_PEOPLE()
 {
     SQLiteTable tb = new SQLiteTable("EN_ITEMS");
     tb.Columns.Add(new SQLiteColumn("itemid", true));
     tb.Columns.Add(new SQLiteColumn("itemname"));
     tb.Columns.Add(new SQLiteColumn("type", ColType.Integer)); //0 == pool, 1 == L1, 2 == L2, 3 == note, 4 == file
     tb.Columns.Add(new SQLiteColumn("permitto"));
     tb.Columns.Add(new SQLiteColumn("owner"));
     tb.Columns.Add(new SQLiteColumn("hashtags"));
     tb.Columns.Add(new SQLiteColumn("isactive", ColType.Integer));
     tb.Columns.Add(new SQLiteColumn("islocked", ColType.Integer));
     return tb;
 }
Beispiel #2
0
        public void createTable()
        {
            using (SQLiteConnection conn = new SQLiteConnection(dataSource))
            {
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    cmd.Connection = conn;
                    conn.Open();
                    SQLiteHelper sh = new SQLiteHelper(cmd);
                    sh.DropTable(tableName);

                    SQLiteTable tb = new SQLiteTable(tableName);
                    tb.Columns.Add(new SQLiteColumn("id", true));
                    tb.Columns.Add(new SQLiteColumn("url", ColType.Text));
                    tb.Columns.Add(new SQLiteColumn("referer", ColType.Text));
                    tb.Columns.Add(new SQLiteColumn("status", ColType.Integer));
                    tb.Columns.Add(new SQLiteColumn("duration", ColType.Decimal));
                    sh.CreateTable(tb);
                    conn.Close();
                }
            }
        }
Beispiel #3
0
        public void CreateTable(SQLiteTable table)
        {
            StringBuilder sb = new Text.StringBuilder();

            sb.Append("create table if not exists `");
            sb.Append(table.TableName);
            sb.AppendLine("`(");

            bool firstRecord = true;

            foreach (SQLiteColumn col in table.Columns)
            {
                if (col.ColumnName.Trim().Length == 0)
                {
                    throw new Exception("Column name cannot be blank.");
                }

                if (firstRecord)
                {
                    firstRecord = false;
                }
                else
                {
                    sb.AppendLine(",");
                }

                sb.Append(col.ColumnName);
                sb.Append(" ");

                if (col.AutoIncrement)
                {
                    sb.Append("integer primary key autoincrement");
                    continue;
                }

                switch (col.ColDataType)
                {
                case ColType.Text:
                    sb.Append("text"); break;

                case ColType.Integer:
                    sb.Append("integer"); break;

                case ColType.Decimal:
                    sb.Append("decimal"); break;

                case ColType.DateTime:
                    sb.Append("datetime"); break;

                case ColType.BLOB:
                    sb.Append("blob"); break;
                }

                if (col.PrimaryKey)
                {
                    sb.Append(" primary key");
                }
                else if (col.NotNull)
                {
                    sb.Append(" not null");
                }
                else if (col.DefaultValue.Length > 0)
                {
                    sb.Append(" default ");

                    if (col.DefaultValue.Contains(" ") || col.ColDataType == ColType.Text || col.ColDataType == ColType.DateTime)
                    {
                        sb.Append("'");
                        sb.Append(col.DefaultValue);
                        sb.Append("'");
                    }
                    else
                    {
                        sb.Append(col.DefaultValue);
                    }
                }
            }

            sb.AppendLine(");");

            cmd.CommandText = sb.ToString();
            cmd.ExecuteNonQuery();
        }
Beispiel #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            #region 判断IP的合法性
            foreach (Control c in this.Controls)
            {
                if (c is TextBox)
                {
                    if (string.IsNullOrEmpty((c as TextBox).Text))
                    {
                        MessageBox.Show("有设置选项未填写。", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            foreach (Control c in this.panel1.Controls)
            {
                if (c is TextBox)
                {
                    if (string.IsNullOrEmpty((c as TextBox).Text))
                    {
                        MessageBox.Show("COS服务器IP未填写。", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (Convert.ToInt32(c.Text) >= 256)
                    {
                        MessageBox.Show("请输入正确的IP地址。", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }

            #endregion
            #region 服务程序数据库操作
            string ip = textBox1.Text + "." + textBox2.Text + "." + textBox3.Text + "." + textBox4.Text;
            int interval = Convert.ToInt32(textBox5.Text);
            int timeout = Convert.ToInt32(textBox6.Text);
            using (SQLiteConnection conn = new SQLiteConnection(@"data source=.\CloudAgent.db"))
            {
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    cmd.Connection = conn;
                    conn.Open();
                    SQLiteHelper sh = new SQLiteHelper(cmd);
                    SQLiteTable tb = new SQLiteTable("server");
                    tb.Columns.Add(new SQLiteColumn("id", true));
                    tb.Columns.Add(new SQLiteColumn("ip", ColType.Text));
                    sh.CreateTable(tb);
                    SQLiteTable tb2 = new SQLiteTable("setting");
                    tb2.Columns.Add(new SQLiteColumn("id", true));
                    tb2.Columns.Add(new SQLiteColumn("key", ColType.Text));
                    tb2.Columns.Add(new SQLiteColumn("value", ColType.Integer));

                    sh.CreateTable(tb2);
                    sh.BeginTransaction();
                    try
                    {
                        var dic = new Dictionary<string, object>();
                        dic["ip"] = ip;
                        sh.Insert("server", dic);
                        var dicData = new Dictionary<string, object>();
                        var dicData2 = new Dictionary<string, object>();
                        var dicData3 = new Dictionary<string, object>();
                        dicData["key"] = "interval";
                        dicData["value"] = interval;
                        dicData2["key"] = "timeout";
                        dicData2["value"] = timeout;
                        dicData3["key"] = "hostset";
                        dicData3["value"] = "";
                        DataTable dt = sh.Select("select * from setting where key='interval';");
                        if(dt.Rows.Count>0)
                        sh.Update("setting", dicData, "key", "interval");
                        else
                        sh.Insert("setting", dicData);
                        DataTable dt2 = sh.Select("select * from setting where key='timeout';");
                        if (dt2.Rows.Count > 0)
                            sh.Update("setting", dicData2, "key", "timeout");
                        else
                            sh.Insert("setting", dicData2);
                        DataTable dt3 = sh.Select("select * from setting where key='hostset';");
                        if (dt3.Rows.Count == 0)
                            sh.Insert("setting", dicData3);
                        sh.Commit();
                    }
                    catch
                    {
                        sh.Rollback();
                    }

                    conn.Close();
                }
            }

            #endregion
            #region 是否打开服务

            if (radioButton1.Checked) {

                Thread ce = new Thread(delegate ()
                {
                    Process p = new Process();
                    string path = System.Environment.CurrentDirectory;
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.FileName = path + @"\CloudAgent.exe";
                    //MessageBox.Show(p.StartInfo.FileName);
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.EnableRaisingEvents = true;
                    p.StartInfo.Arguments = "-install";
                    try
                    {
                       // MessageBox.Show(radioButton1.Checked.ToString());
                        p.Start();

                        p.WaitForExit();
                    }
                    catch (System.ComponentModel.Win32Exception err)
                    {
                        MessageBox.Show("系统找不到指定的程序文件。\r{2}");
                        p.Close();
                        return;
                    }

                    p.Close();
                });
                ce.IsBackground = false;
                ce.Start();
                Thread ce2 = new Thread(delegate ()
                {
                    Process p = new Process();
                    string path = System.Environment.CurrentDirectory;
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.FileName = path + @"\AutoOnOffLine.exe";
                    //MessageBox.Show(p.StartInfo.FileName);
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.EnableRaisingEvents = true;
                    p.StartInfo.Arguments = "-install";
                    try
                    {
                        // MessageBox.Show(radioButton1.Checked.ToString());
                        p.Start();

                        p.WaitForExit();
                    }
                    catch (System.ComponentModel.Win32Exception err)
                    {
                        MessageBox.Show("系统找不到指定的程序文件。\r{2}");
                        p.Close();
                        return;
                    }

                    p.Close();
                });
                ce2.IsBackground = false;
                ce2.Start();

            }
            if (radioButton2.Checked)
            {
                Thread ce = new Thread(delegate ()
                {
                    Process p = new Process();
                    string path = System.Environment.CurrentDirectory;
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.FileName = path+@"\CloudAgent.exe";
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.EnableRaisingEvents = true;
                    p.StartInfo.Arguments = "-remove";
                    try
                    {
                        p.Start();
                        p.WaitForExit();
                    }
                    catch (System.ComponentModel.Win32Exception err)
                    {
                        MessageBox.Show("系统找不到指定的程序文件。\r{2}");
                        p.Close();
                        return;
                    }

                    p.Close();
                });
                ce.IsBackground = false;
                ce.Start();
                Thread ce2 = new Thread(delegate ()
                {
                    Process p = new Process();
                    string path = System.Environment.CurrentDirectory;
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.FileName = path + @"\AutoOnOffLine.exe";
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.EnableRaisingEvents = true;
                    p.StartInfo.Arguments = "-remove";
                    try
                    {
                        p.Start();
                        p.WaitForExit();
                    }
                    catch (System.ComponentModel.Win32Exception err)
                    {
                        MessageBox.Show("系统找不到指定的程序文件。\r{2}");
                        p.Close();
                        return;
                    }

                    p.Close();
                });
                ce2.IsBackground = false;
                ce2.Start();
            }
            #endregion
               /* Environment.Exit(1);*/
               Application.Exit();
        }
Beispiel #5
0
 public QueryObj(int _caseid, SQLiteTable _newtable)
 {
     caseid = _caseid;
     newtable = _newtable;
 }
Beispiel #6
0
        public void CreateTable(SQLiteTable table)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("create table if not exists `");
            stringBuilder.Append(table.TableName);
            stringBuilder.AppendLine("`(");
            bool flag = true;

            foreach (SQLiteColumn column in table.Columns)
            {
                if (column.ColumnName.Trim().Length != 0)
                {
                    if (flag)
                    {
                        flag = false;
                    }
                    else
                    {
                        stringBuilder.AppendLine(",");
                    }
                    stringBuilder.Append(column.ColumnName);
                    stringBuilder.Append(" ");
                    if (column.AutoIncrement)
                    {
                        stringBuilder.Append("integer primary key autoincrement");
                    }
                    else
                    {
                        switch (column.ColDataType)
                        {
                        case ColType.Text:
                            stringBuilder.Append("text");
                            break;

                        case ColType.DateTime:
                            stringBuilder.Append("datetime");
                            break;

                        case ColType.Integer:
                            stringBuilder.Append("integer");
                            break;

                        case ColType.Decimal:
                            stringBuilder.Append("decimal");
                            break;

                        case ColType.BLOB:
                            stringBuilder.Append("blob");
                            break;
                        }
                        if (column.PrimaryKey)
                        {
                            stringBuilder.Append(" primary key");
                        }
                        else if (column.NotNull)
                        {
                            stringBuilder.Append(" not null");
                        }
                        else if (column.DefaultValue.Length > 0)
                        {
                            stringBuilder.Append(" default ");
                            if (!column.DefaultValue.Contains(" ") && column.ColDataType != 0 && column.ColDataType != ColType.DateTime)
                            {
                                stringBuilder.Append(column.DefaultValue);
                            }
                            else
                            {
                                stringBuilder.Append("'");
                                stringBuilder.Append(column.DefaultValue);
                                stringBuilder.Append("'");
                            }
                        }
                    }
                    continue;
                }
                throw new Exception("Column name cannot be blank.");
            }
            stringBuilder.AppendLine(");");
            this.cmd.CommandText = stringBuilder.ToString();
            this.cmd.ExecuteNonQuery();
        }