这是预约房间的系统
Book Time是想预约的时间
Due Time是房间到期的时间预约房间的使用期为1小时在图中 我选了预约12点 房间到期的时间该是1点吧 为何在ListView显示的时间会不正确?

解决方案 »

  1.   

            private void Booking_Load(object sender, EventArgs e)
            {
               bookTime.Format = DateTimePickerFormat.Custom;
               bookTime.CustomFormat = "MM dd yyyy hh mm";
               bookTime.Value = DateTime.Now;           dueTime.Format = DateTimePickerFormat.Custom;
               dueTime.CustomFormat = "MM dd yyyy hh mm";
               dueTime.Value = DateTime.Now;
      

  2.   

            private void dueDate_ValueChanged(object sender, EventArgs e)
            {
                //check dueTime//            dueTime.Value = bookTime.Value.AddMinutes(60);
            }
      

  3.   

          private void btnConfirm_Click(object sender, EventArgs e)
            {
                /////confirm booking///
                txtBookNo.ReadOnly = true;            string bookNo = txtBookNo.Text;            string sqlComfirm;
                OleDbCommand cmd;            sqlComfirm = "INSERT INTO Book ("
                  + "BookNo, "
                  + "BookTime, "
                  + "memberNo "              + ") VALUES ("              + toSql(int.Parse(txtBookNo.Text)) + ", "
                  + toSql(bookTime.Value.ToLocalTime()) + ", "
                  + toSql(memberNoComboBox.Text).ToString()              + ")";
                try
                {
                    cmd = new OleDbCommand(sqlComfirm, mDB);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Booking inserted successfully");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }            btnBook.Enabled = true;
            }
      

  4.   

    dueTime.Format = DateTimePickerFormat.Custom;
               dueTime.CustomFormat = "MM dd yyyy hh mm";
               dueTime.Value = DateTime.Now; 
    你这里过期时间这样写是不对的,你这样写,过期时间只会保存了当前的时间,你是想保存预定时候的时间,你可以用一个临时变量来保存预定时候的时间,比如string DatetimeCahe=DateTime.Now.ToString().然后单击保存按钮的时候,可以用Convert.ToDateTime(DatetimeCahe).Value.AddMinutes(60);
      

  5.   


    不明白
     + toSql(bookTime.Value.ToLocalTime()) + ", "
    这句要如何改
      

  6.   

    改为+ toSql(Convert.ToDateTime(DatetimeCahe)) + ", "
    还有就是bookTime.Format = DateTimePickerFormat.Custom;
               bookTime.CustomFormat = "MM dd yyyy hh mm";
               bookTime.Value = DateTime.Now; //
    改为
    bookTime.Format = DateTimePickerFormat.Custom;
               bookTime.CustomFormat = "MM dd yyyy hh mm";
               bookTime.Value = Convert.ToDateTime(DatetimeCahe)
      

  7.   


       string DateTimeCahe="";//全局变量
       private void dueDate_ValueChanged(object sender, EventArgs e)
            {
                //check dueTime//
                DateTimeCahe=DateTime.Now.ToString();
               dueTime.Value = Convert.ToDateTime(DatetimeCahe).Value.AddMinutes(60);        } ; 
    private void btnConfirm_Click(object sender, EventArgs e)
            {
                /////confirm booking///
                txtBookNo.ReadOnly = true;
                
                string bookNo = txtBookNo.Text;            string sqlComfirm;
                OleDbCommand cmd;            sqlComfirm = "INSERT INTO Book ("
                  + "BookNo, "
                  + "BookTime, "
                  + "memberNo "              + ") VALUES ("              + toSql(int.Parse(txtBookNo.Text)) + ", "
                  + toSql(Convert.ToDateTime(DatetimeCahe).Value)+ ", "
                  + toSql(memberNoComboBox.Text).ToString()              + ")";
                try
                {
                    cmd = new OleDbCommand(sqlComfirm, mDB);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Booking inserted successfully");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }            btnBook.Enabled = true;
            }