public Result insert(DTO_BILL bill) { String query = "INSERT INTO [BILL] ([ID_BIL], [DATETIME], [ID_EMP], [ID_TAB], [STATUS], [SUMPRICE], [SUBPRICE]) "; query += "VALUES (@ID_BIL, @DATETIME, @ID_EMP, @ID_TAB, @STATUS, @SUMPRICE, @SUBPRICE)"; SqlCommand cmmd = new SqlCommand(); cmmd.Connection = conn; cmmd.CommandType = System.Data.CommandType.Text; cmmd.CommandText = query; cmmd.Parameters.AddWithValue("@ID_BIL", bill.ID); cmmd.Parameters.AddWithValue("@DATETIME", bill.DATETIME); cmmd.Parameters.AddWithValue("@ID_EMP", bill.ID_EMP); cmmd.Parameters.AddWithValue("@ID_TAB", bill.ID_TAB); cmmd.Parameters.AddWithValue("@STATUS", bill.STATUS); cmmd.Parameters.AddWithValue("@SUMPRICE", bill.SUMPRICE.ToString()); cmmd.Parameters.AddWithValue("@SUBPRICE", bill.SUBPRICE.ToString()); try { conn.Open(); cmmd.ExecuteNonQuery(); } catch (Exception e) { conn.Close(); System.Console.WriteLine(e.Message); return(new Result(false, e.Message)); } conn.Close(); return(new Result(true)); }
private void dgv_bill_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { String id = dgv_bill.Rows[e.RowIndex].Cells[0].Value.ToString(); DTO_BILL bill = bus_bil.SelectID(id); MessageBox.Show(id); tbx_idBill.Text = id; tbx_idTable.Text = bill.ID_TAB; dtp_bill.Value = bill.DATETIME; //select bill_info from id_bill LoadDataGridBillInfo(id); } }
public DTO_BILL SelectID_Table(String id_table) { DTO_BILL bill = new DTO_BILL(); String query = "SELECT * FROM [BILL]"; query += "WHERE [ID_TAB] = @ID_TAB"; query += " AND [STATUS] = @STATUS"; SqlCommand cmmd = new SqlCommand(); cmmd.Connection = conn; cmmd.CommandType = System.Data.CommandType.Text; cmmd.CommandText = query; cmmd.Parameters.AddWithValue("@ID_TAB", id_table); cmmd.Parameters.AddWithValue("@STATUS", "NO"); try { conn.Open(); SqlDataReader reader; reader = cmmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { bill = new DTO_BILL(reader["ID_BIL"].ToString(), Convert.ToDateTime(reader["DATETIME"].ToString()), reader["ID_EMP"].ToString(), reader["ID_TAB"].ToString(), reader["STATUS"].ToString(), Convert.ToDouble(reader["SUMPRICE"].ToString()), Convert.ToDouble(reader["SUBPRICE"].ToString())); } } } catch (Exception e) { conn.Close(); System.Console.WriteLine(e.Message); return(null); } conn.Close(); return(bill); }
private void btn_submit_Click(object sender, EventArgs e) { if (ntd_price.Value == 0) { MessageBox.Show("Don't input price!"); } else { List <DTO_BILL_INFO> temp = list_in; Double sum_price = 0, subprice = 0; Double custom_price = Convert.ToDouble(ntd_price.Value); if (temp.Count() != 0) { foreach (DTO_BILL_INFO item in temp) { sum_price += item.PRICE; //insert bill infor String id_info = bus_infoBill.nextID(); DTO_BILL_INFO temp_bill_info = new DTO_BILL_INFO(id_info, item.ID_FOD, item.ID_BIL, item.COUNT, item.PRICE); bus_infoBill.insert(temp_bill_info); } subprice = custom_price - sum_price; //insert bill DTO_BILL bill = new DTO_BILL(lb_ID.Text, dtp_time.Value, "U02", lb_id_table.Text, "DONE", sum_price, subprice); Result result = bus_bill.insert(bill); //insert bill info lst_bill.Items.Clear(); lb_sum.Text = sum_price.ToString(); lb_sub.Text = subprice.ToString(); btn_add.Enabled = false; btn_order.Enabled = false; btn_submit.Enabled = false; btn_reset.Enabled = false; } else { MessageBox.Show("You must add food for bill"); } } }
public void ShowBill(String id) { lst_bill.Items.Clear(); bill = bus_bill.SelectID_Table(id); listbill_info = bus_infoBill.SelectAll(bill.ID); //if(listbill_info != null) //{ // foreach (DTO_Menu item in listbill_info) // { // ListViewItem lsi = new ListViewItem(item.DISPLAYNAME.ToString()); // lsi.SubItems.Add(item.COUNT.ToString()); // lsi.SubItems.Add(item.PRICE.ToString()); // lst_bill.Items.Add(lsi); // } // btn_order.Enabled = false; //} //else //{ // btn_order.Enabled = true; // MessageBox.Show("You can order."); //} }
public Result insert(DTO_BILL bill) { return(dal_bill.insert(bill)); }