public bool addTollBill(TollBills rt, out string TollBillId)
 {
     var result = tollBillsDAT.addTollBill(rt);
     if (result.Rows[0].ItemArray[0].ToString() == "0")
     {
         TollBillId = result.Rows[0].ItemArray[1].ToString();
         return true;
     }
     TollBillId = "";
     return false;
 }
        public DataTable addTollBill(TollBills rt)
        {
            try
            {
                string[] names = new string[6];
                object[] values = new object[6];

                names[0] = "@p_SERVICENOTEID"; values[0] = rt.Servicenoteid;
                names[1] = "@p_DISCOUNTMONEY"; values[1] = rt.DiscountMoney;
                names[2] = "@p_DEBTUNTILDATE"; values[2] = rt.DebtUntilDate;
                names[3] = "@p_DATETOLL"; values[3] = rt.Datetoll;
                names[4] = "@p_TOTAL"; values[4] = rt.Total;
                names[5] = "@p_NOTE"; values[5] = rt.Note;

                return this.ExcuteStoreProcedure("TOLLBILLS_Ins", names, values);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Message = {1}", ex.Message);
            }

            return null;
        }
 public bool updateTollBill(TollBills rt)
 {
     try
     {
         string sql = "Update TollBills "
             + "set servicenoteid = N'" + rt.Servicenoteid + "', "
             + "discountmoney = " + rt.DiscountMoney.ToString().Replace(',', '.') + ", "
             + "datetoll = CONVERT(DATETIME, '" + rt.Datetoll + "', 103), "
             + "debtuntildate = " + rt.DebtUntilDate.ToString().Replace(',', '.') + ", "
             + "total = " + rt.Total.ToString().Replace(',', '.') + ", "
             + "note = N'" + rt.Note + "' "
             + "where id = '" + rt.Id.Trim() + "'";
         int result = this.ExecuteNonQuery(sql);
         if (result != 0)
         {
             return true;
         }
     }
     catch (System.Exception ex)
     {
         Console.WriteLine("Message = {1}", ex.Message);
     }
     return false;
 }
        public DataTable searchTollBill(TollBills rt, string contractId, string roomName, string dateNoteService, decimal roomPrice, decimal serviceTotalMoney, decimal debt, decimal total)
        {
            try
            {
                string[] names = new string[13];
                object[] values = new object[13];

                names[0] = "@p_ID"; values[0] = rt.Id;
                names[1] = "@p_CONTRACTID"; values[1] = contractId;
                names[2] = "@p_SERVICENOTEID"; values[2] = rt.Servicenoteid;
                names[3] = "@p_DISCOUNTMONEY"; values[3] = rt.DiscountMoney;
                names[4] = "@p_DATETOLL"; values[4] = rt.Datetoll;
                names[5] = "@p_TOTAL"; values[5] = rt.Total;
                names[6] = "@p_NOTE"; values[6] = rt.Note;
                names[7] = "@p_ROOMNAME"; values[7] = roomName;
                names[8] = "@p_DATENOTESERVICE"; values[8] = dateNoteService;
                names[9] = "@p_PRICEROOM"; values[9] = roomPrice;
                names[10] = "@p_SERVICETOTALMONEY"; values[10] = serviceTotalMoney;
                names[11] = "@p_DEBT"; values[11] = debt;
                names[12] = "@p_TOP"; values[12] = 0;

                return this.ExcuteStoreProcedure("TOLLBILLS_Search", names, values);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Message = {1}", ex.Message);
            }

            return null;
        }
 public bool updateTollBill(TollBills rt)
 {
     return tollBillsDAT.updateTollBill(rt);
 }
 public DataTable searchTollBill(TollBills rt, string contractId, string roomName, string dateNoteService, decimal roomPrice, decimal serviceTotalMoney, decimal debt, decimal total)
 {
     return tollBillsDAT.searchTollBill(rt, contractId, roomName, dateNoteService, roomPrice, serviceTotalMoney, debt, total);
 }
        private void btnSaveAndExport_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("If you export to Tollbills, you will not be able to edit or delete it again?\n\nDo you want to continues?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                var serviceNoteId = SaveServiceNote();
                if (!string.IsNullOrEmpty(serviceNoteId))
                {
                    DataTable debtTable = debtBLT.searchDebt(new Debt()
                    {
                        Contractid = txtContractID.Text,
                        DateSet = "",
                    });

                    decimal debt = 0, priceRoom = 0, totalTollsBill = 0;
                    if (debtTable != null && debtTable.Rows.Count > 0)
                    {
                        debt = (debtTable.Rows[0] as DataRow).Field<decimal>("DEBTUNTILDATE");
                    }

                    DataTable contractTable = contractBLT.searchContract(new Contract()
                    {
                        Id = txtContractID.Text,
                        IsValid = true
                    });
                    if (contractTable != null && contractTable.Rows.Count > 0)
                    {
                        priceRoom = (contractTable.Rows[0] as DataRow).Field<decimal>("PRICEROOM");
                    }
                    totalTollsBill = priceRoom + decimal.Parse(txtTotalMoney.Text) + debt;

                    TollBills tollBills = new TollBills()
                    {
                        Datetoll = dateTimePickerDate.Text,
                        DiscountMoney = 0,
                        DebtUntilDate = debt,
                        Servicenoteid = serviceNoteId,
                        Note = "",
                        Total = totalTollsBill
                    };

                    //Insert
                    string id;
                    if (tollBillsBLT.addTollBill(tollBills, out id))
                    {
                        MessageBox.Show("Export to Tollbills of " + serviceNoteId.ToUpper() + " successfully!\nThe new tollbills Id = " + id + ".");
                        this.Close();
                    }
                    else
                        MessageBox.Show("Export fail! Try again later.");
                }
            }
        }
 /// <summary>
 /// //Tìm xem trong bảng TollBills đã có thông tin ServiceNoteID này chưa?
 //     - Nếu có rồi thì không cho chỉnh sửa và xóa ServiceNoteId này nữa, chỉ cho xem thôi;
 //     - Nếu chưa có thì cho phép chỉnh sửa và xóa.
 /// </summary>
 /// <param name="servicenoteid"></param>
 private void CheckEditServiceNote(string servicenoteid)
 {
     var temp = new TollBills()
     {
         Servicenoteid = servicenoteid
     };
     DataTable result = tollBillsBLT.searchTollBill(temp, "", "", "", 0,0,0,0);
     if (result != null && result.Rows.Count > 0)
     {
         this.btnEdit.Text = "View detail";
         this.btnDelete.Enabled = false;
     }
     else
     {
         this.btnEdit.Text = "Edit";
         this.btnDelete.Enabled = true;
     }
 }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (txtId.Text == string.Empty)
            {
                MessageBox.Show("You don't choose a tollbills to " + btnEdit.Text + "!", "Infomations", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {

                TollBills tb = new TollBills()
                {
                    Id = txtId.Text.Trim(),
                    Datetoll = dateTimePickerDate.Text,
                    Servicenoteid =((dgvTollBills.DataSource as DataTable).Rows[dgvTollBills.CurrentCell.RowIndex] as DataRow).Field<string>("SERVICENOTEID"),
                    DiscountMoney = decimal.Parse(txtDiscountMoney.Text.Trim() == "" ? "0" : txtDiscountMoney.Text.Trim()),
                    Note = txtNote.Text,
                    Total = decimal.Parse(txtTotal.Text.Trim() == "" ? "0" : txtTotal.Text.Trim())
                };

                TollBillEdit serviceNoteEdit = new TollBillEdit(tb, txtContractId.Text.Trim(), (cmbRoom.SelectedValue == null) ? "" : cmbRoom.SelectedValue.ToString(),
                    dateTimePickerNoteService.Text,
                    txtPriceRoom.Text.Trim() == "" ? "0" : txtPriceRoom.Text.Trim(),
                    txtTotalMoneyService.Text.Trim() == "" ? "0" : txtTotalMoneyService.Text.Trim(),
                    txtDebt.Text.Trim() == "" ? "0" : txtDebt.Text.Trim(),
                    txtTotal.Text.Trim() == "" ? "0" : txtTotal.Text.Trim(),
                    btnEdit.Text == "Edit" ? true : false);

                if (btnEdit.Text == "Edit")
                    serviceNoteEdit.EditCompletedHandler += FormTollBillsEdit_Completed;
                serviceNoteEdit.ShowDialog();
            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (btnSearch.Text == "Reset")
            {
                this.resetUI();
                this.changeModeEditUI(true);
            }
            else
            {
                TollBills tb = new TollBills()
                {
                    Id = txtId.Text.Trim(),
                    Datetoll = dateTimePickerDate.Text,
                    DiscountMoney= decimal.Parse(txtDiscountMoney.Text.Trim() == "" ? "0" : txtDiscountMoney.Text.Trim()),
                    Note=txtNote.Text,
                    Total = decimal.Parse(txtTotal.Text.Trim() == "" ? "0" : txtTotal.Text.Trim())
                };

                this.dgvTollBills.DataSource = tollBillsBLT.searchTollBill(tb,
                    txtContractId.Text,
                    (cmbRoom.SelectedValue == null) ? "" : cmbRoom.SelectedValue.ToString(),
                    dateTimePickerNoteService.Text,
                    decimal.Parse(txtPriceRoom.Text.Trim() == "" ? "0" : txtPriceRoom.Text.Trim()),
                    decimal.Parse(txtTotalMoneyService.Text.Trim() == "" ? "0" : txtTotalMoneyService.Text.Trim()),
                    decimal.Parse(txtDebt.Text.Trim() == "" ? "0" : txtDebt.Text.Trim()),
                    decimal.Parse(txtTotal.Text.Trim() == "" ? "0" : txtTotal.Text.Trim()));
            }
        }