public float GetPriceBidaTable(int id, int idtable, float total) { DataTable table = new DataTable(); MYDB db = new MYDB(); SqlCommand command = new SqlCommand("select * from BidaTabledb,BidaTableMap b where b.BidaTableID = @idtable and BidaTableMapID = @id", db.Connection); command.Parameters.Add("@idtable", SqlDbType.Int).Value = idtable; command.Parameters.Add("@id", SqlDbType.Int).Value = id; SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(table); if (table.Rows.Count == 0) { return(total = 50); } else { DateTime begin = Convert.ToDateTime(table.Rows[0]["TimeBegin"].ToString()); DateTime end = Convert.ToDateTime(table.Rows[0]["TimeEnd"].ToString()); TimeSpan timeplay = new TimeSpan(); timeplay = end - begin; int thoigianchoi = 1; if (timeplay.TotalHours <= 1) { thoigianchoi = 1; } else { if (timeplay.TotalMinutes % 60 == 0) { thoigianchoi = Convert.ToInt32(timeplay.TotalHours); } else { thoigianchoi = Convert.ToInt32(timeplay.TotalHours) + 1; } } total = total + Convert.ToInt32(table.Rows[0]["Bprice"].ToString()) * thoigianchoi; return(total); } }
private void buttonTimKiem_Click(object sender, EventArgs e) { string phone = textBox1.Text; MYDB db = new MYDB(); DataTable tb = new DataTable(); DataTable table = new DataTable(); SqlCommand command = new SqlCommand("Select * from Customersdb where Cphone= " + textBox1.Text.Trim(), db.Connection); SqlDataAdapter apter = new SqlDataAdapter(command); apter.Fill(tb); if (tb.Rows.Count >= 1) { int id = Convert.ToInt32(tb.Rows[0][0]); timkiem(id, table); loaddatagifview(table); } else { MessageBox.Show("khong tim thay thong tin khach hang"); } }
public bool check(int id, DateTime timebegin, DateTime timeend) { MYDB db = new MYDB(); SqlCommand command = new SqlCommand("select * from BidaTableMap where BidaTableID = @id and TimeBegin <= @timeEnd and TimeEnd >= @timebegin ", db.Connection); command.Parameters.Add("@id", SqlDbType.Int).Value = id; command.Parameters.Add("@timeend", SqlDbType.DateTime).Value = timeend; command.Parameters.Add("@timebegin", SqlDbType.DateTime).Value = timebegin; SqlDataAdapter apter = new SqlDataAdapter(command); DataTable table = new DataTable(); apter.Fill(table); if (table.Rows.Count == 0) { return(true); } else { return(false); } }
private void ButtonSignin_Click(object sender, EventArgs e) { MYDB lg = new MYDB(); lg.openconection(); SqlDataAdapter adapter = new SqlDataAdapter(); DataTable table = new DataTable(); SqlCommand command = new SqlCommand("SELECT * FROM Customersdb WHERE Cuser=@User and Cpass=@Pass", lg.Connection); command.Parameters.Add("@User", SqlDbType.VarChar).Value = textBoxUser.Text; command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = textBoxPass.Text; SqlDataReader reader = command.ExecuteReader(); if ((reader.Read() == true)) //if (command.ExecuteNonQuery() == 1) { KhachHangForm kh = new KhachHangForm(textBoxUser.Text); kh.Show(); } else { lg.closeconection(); lg.openconection(); command = new SqlCommand("SELECT * FROM Employeesdb WHERE Euser=@User and Epass=@Pass", lg.Connection); command.Parameters.Add("@User", SqlDbType.VarChar).Value = textBoxUser.Text; command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = textBoxPass.Text; SqlDataReader reader1 = command.ExecuteReader(); if (reader1.Read() == true) { NhanVienForm nv = new NhanVienForm(); nv.Show(); } else { MessageBox.Show("invalid user"); } } }
private void ButtonCapNhat_Click(object sender, EventArgs e) { string sex; if (radioButtonNam.Checked == true) { sex = "Man"; } else { sex = "Girl"; } MYDB db = new MYDB(); SqlCommand cmd = new SqlCommand("update Customersdb set CName=@ht,Cphone=@st,CBrithday=@bd,Csex=@dc where [Cuser]=N'" + std + "'", db.Connection); cmd.Parameters.Add("@ht", SqlDbType.NVarChar).Value = textBoxHoTen.Text; cmd.Parameters.Add("@st", SqlDbType.NVarChar).Value = textBoxStd.Text; cmd.Parameters.Add("@bd", SqlDbType.DateTime).Value = dateTimePicker1.Value; cmd.Parameters.Add("@dc", SqlDbType.NVarChar).Value = sex; db.openconection(); if (cmd.ExecuteNonQuery() == 1) { db.closeconection(); ThongTinKhachHang_Load(sender, e); textBoxHoTen.Enabled = false; textBoxStd.Enabled = false; dateTimePicker1.Enabled = false; radioButtonNam.Enabled = false; radioButtonNu.Enabled = false; MessageBox.Show("Đã Cập Nhật Thành Công", "Thông tin Khách Hàng", MessageBoxButtons.OK); } else { db.closeconection(); MessageBox.Show("Không Thể Cập Nhật", "Thông Tin Khách Hàng", MessageBoxButtons.OK); } }
public bool insert(DateTime Bdate, int employee, int bidatablemapID, float total) { MYDB db = new MYDB(); SqlCommand command = new SqlCommand("INSERT INTO Billsdb (Bdate,Employee,BidaTableMapID,Total)" + " VALUES (@Bdate,@Employee,@BidaTableMapID,@Total)", db.Connection); //command.Parameters.Add("@id", SqlDbType.Int).Value = PeopleId; command.Parameters.Add("@Bdate", SqlDbType.DateTime).Value = Bdate; command.Parameters.Add("@Employee", SqlDbType.Int).Value = employee; command.Parameters.Add("@BidaTableMapID", SqlDbType.Int).Value = bidatablemapID; command.Parameters.Add("@Total", SqlDbType.Float).Value = total; db.openconection(); if ((command.ExecuteNonQuery() == 1)) { db.closeconection(); return(true); } else { db.closeconection(); return(false); } }
public bool insert(int id, int status, int custommer, DateTime begin, DateTime end) { MYDB db = new MYDB(); SqlCommand command = new SqlCommand("INSERT INTO BidaTableMap (BidaTableID, Status,Customer,TimeBegin,TimeEnd)" + " VALUES (@id, @status, @customer, @begin,@end)", db.Connection); //command.Parameters.Add("@id", SqlDbType.Int).Value = PeopleId; command.Parameters.Add("@id", SqlDbType.Int).Value = id; command.Parameters.Add("@status", SqlDbType.Int).Value = status; command.Parameters.Add("@customer", SqlDbType.Int).Value = custommer; command.Parameters.Add("@begin", SqlDbType.DateTime).Value = begin; command.Parameters.Add("@end", SqlDbType.DateTime).Value = end; db.openconection(); if ((command.ExecuteNonQuery() == 1)) { db.closeconection(); return(true); } else { db.closeconection(); return(false); } }
public float GetPriceOrderFood(int id, float total = 0) { DataTable table = new DataTable(); MYDB db = new MYDB(); SqlCommand command = new SqlCommand("select FoodID,Fprice from OrderFooddb ,Foodsdb where Food = FoodID and BidaTableMap = @id", db.Connection); command.Parameters.Add("@id", SqlDbType.Int).Value = id; SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(table); if (table.Rows.Count == 0) { return(total = 0); } else { for (int i = 0; i < table.Rows.Count; i++) { total = total + Convert.ToInt32(table.Rows[i]["Fprice"].ToString()); } return(total); } }