Przeglądaj źródła

测试版改了时间格式,希望好使

Shenjian 7 lat temu
rodzic
commit
0e2fadd8dd
3 zmienionych plików z 44 dodań i 7 usunięć
  1. BIN
      source/DB.accdb
  2. 7 6
      source/DBcon.cs
  3. 37 1
      source/Form1.cs

BIN
source/DB.accdb


+ 7 - 6
source/DBcon.cs

@@ -8,6 +8,7 @@ namespace BooksManageSystem
 {
     internal class DBcon
     {
+        private string dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
 
         #region 书籍列表
         private DataTable _dal_getBookList()
@@ -119,7 +120,7 @@ namespace BooksManageSystem
             }
 
             using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values 
-(" + id + "," + ((int)EnumOP.售).ToString() + ",'" + time.ToString() + "'," + count.ToString() + ",'" + opertor + "'," + (c - count) + ")"))
+(" + id + "," + ((int)EnumOP.售).ToString() + ",'" + time.ToString(dateTimeFormat) + "'," + count.ToString() + ",'" + opertor + "'," + (c - count) + ")"))
             {
                 //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
                 DBHelper.ExecuteNonQuery(comm);
@@ -193,7 +194,7 @@ namespace BooksManageSystem
             if (bid==0)
             {
                 using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values 
-(" + id + "," + ((int)EnumOP.购).ToString() + ",'" + time.ToString() + "'," + count.ToString() + ",'" + oper + "'," + (c + count) + ")"))
+(" + id + "," + ((int)EnumOP.购).ToString() + ",'" + time.ToString(dateTimeFormat) + "'," + count.ToString() + ",'" + oper + "'," + (c + count) + ")"))
                 {
                     //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
                     DBHelper.ExecuteNonQuery(comm);
@@ -203,7 +204,7 @@ namespace BooksManageSystem
             else
             {
                 using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count,bid) values 
-(" + id + "," + ((int)EnumOP.购).ToString() + ",'" + time.ToString() + "'," + count.ToString() + ",'" + oper + "'," + (c + count) + "," + bid + ")"))
+(" + id + "," + ((int)EnumOP.购).ToString() + ",'" + time.ToString(dateTimeFormat) + "'," + count.ToString() + ",'" + oper + "'," + (c + count) + "," + bid + ")"))
                 {
                     //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
                     DBHelper.ExecuteNonQuery(comm);
@@ -221,7 +222,7 @@ namespace BooksManageSystem
         /// <returns></returns>
         public int Blist(int totalcount, DateTime time)
         {
-            using (OleDbCommand comm = new OleDbCommand(@"insert into blist (bcount,bdate) values(" + totalcount + ",'" + time.ToString() + "')"))
+            using (OleDbCommand comm = new OleDbCommand(@"insert into blist (bcount,bdate) values(" + totalcount + ",'" + time.ToString(dateTimeFormat) + "')"))
             {
                 DBHelper.ExecuteNonQuery(comm);
             }
@@ -251,7 +252,7 @@ namespace BooksManageSystem
             }
 
             using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values 
-(" + id + "," + ((int)EnumOP.还).ToString() + ",'" + time.ToString() + "'," + count.ToString() + ",'" + oper + "'," + (c + count) + ")"))
+(" + id + "," + ((int)EnumOP.还).ToString() + ",'" + time.ToString(dateTimeFormat) + "'," + count.ToString() + ",'" + oper + "'," + (c + count) + ")"))
             {
                 //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
                 DBHelper.ExecuteNonQuery(comm);
@@ -612,7 +613,7 @@ namespace BooksManageSystem
             sb.AppendLine("queryCountByID");
             sb.AppendLine(queryCountByID(1).ToString());
             sb.AppendLine("Lingqu");
-            sb.AppendLine(Lingqu(1, 7, "ling", DateTime.Now).ToString());
+            sb.AppendLine(Lingqu(1, 7, "ling", DateTime.Now).ToString(dateTimeFormat));
 
 
 

+ 37 - 1
source/Form1.cs

@@ -697,9 +697,45 @@ namespace BooksManageSystem
 
         private void button1_Click(object sender, EventArgs e)
         {
+
+            MessageBox.Show(DateTime.Now.ToString());
+
+
             //测试函数
+            using (OleDbCommand comm = new OleDbCommand(@"select books_count from books where id = @id"))
+            {
+
+                comm.Parameters.AddWithValue("@id", 1);
+
+                MessageBox.Show("id参数:" + DBHelper.ExecuteScalar(comm).ToString());
+            }
+            using (OleDbCommand comm = new OleDbCommand(@"update books set books_count = @ccount where id = @id"))
+            {
+
+                comm.Parameters.AddWithValue("@ccount", 999);
+                comm.Parameters.AddWithValue("@id", 1);
+
+                MessageBox.Show("id参数、数量参数:" + DBHelper.ExecuteNonQuery(comm).ToString());
+            }
+
+            using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values (@id,@op,@op_date,@op_count,@opertor,@after_op_count)"))
+            {
+
+                comm.Parameters.AddWithValue("@id", 1);
+                comm.Parameters.AddWithValue("@op", (int)EnumOP.领);
+                comm.Parameters.AddWithValue("@op_date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
+                comm.Parameters.AddWithValue("@op_count", 99);
+                comm.Parameters.AddWithValue("@opertor", "Hansi");
+                comm.Parameters.AddWithValue("@after_op_count", 22);
+
+                //insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values (?,?,?,?,?,?)
+                //insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values (1,2,'2018/2/6 10:48:09',1,'afsdf',1)
+                //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
+                MessageBox.Show("多个参数,包含时间: 成功!" + DBHelper.ExecuteNonQuery(comm).ToString());
+            }
+
 
-            MessageBox.Show(con.TestCon());
+            //MessageBox.Show(con.TestCon());
         }
     }
 }