Ejemplo n.º 1
0
        private void btn_Query_Click(object sender, EventArgs e)
        {
            Database.DemoDataQueryParams queryParams = new Database.DemoDataQueryParams()
            {
                Line   = 1,
                Column = 2,
                Plat   = 3,
            };

            //if (Database.DemoData.Insert(queryParams))
            //{
            //    Console.WriteLine("Insert OK..");
            //}
            Database.DemoData.QueryData(queryParams);
            label_Status.Text = "正在查询中";

            Task.Factory.StartNew(() =>
            {
                var ret = Database.LocalDataQuery.QueryData();
                if (ret.Item1)
                {
                    this.Invoke(new Action(() =>
                    {
                        dataGridView1.DataSource = ret.Item2;
                        label_Status.Text        = "查询完毕";
                    }));
                }
            });
        }
Ejemplo n.º 2
0
        public static bool Insert(DemoDataQueryParams queryParams)
        {
            string sql = "REPLACE INTO [demo_data] ([line_number], [column_number], [plat_number], [update_time]) " +
                         "VALUES(@Line, @Column, @Plat, @UpdateTime);";

            //"VALUES(1, 4, 1, '2018-06-03 15:02:00');";

            using (SQLiteCommand cmd = new SQLiteCommand(sql))
            {
                cmd.Parameters.Add("@Line", System.Data.DbType.Int32).Value          = queryParams.Line;
                cmd.Parameters.Add("@Column", System.Data.DbType.Int32).Value        = queryParams.Column;
                cmd.Parameters.Add("@Plat", System.Data.DbType.Int32).Value          = queryParams.Plat;
                cmd.Parameters.Add("@UpdateTime", System.Data.DbType.DateTime).Value = DateTime.Now;

                return(DemoDataSource.Instance.Execute(cmd) > 0);
            }
        }
Ejemplo n.º 3
0
        public static Tuple <bool, DataTable> QueryData(DemoDataQueryParams queryParams)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("SELECT * FROM [demo_data] ");
            sql.Append("WHERE ");
            sql.Append("[line_number] = @Line;");

            using (SQLiteCommand cmd = new SQLiteCommand(sql.ToString()))
            {
                cmd.Parameters.Add("@Line", System.Data.DbType.Int32).Value = queryParams.Line;


                DataTable table = DemoDataSource.Instance.GetTable(cmd);

                if (table != null)
                {
                    return(new Tuple <bool, DataTable>(true, table));
                }
                return(new Tuple <bool, DataTable>(false, null));
            }
        }