private void paymentForm_Load(object sender, EventArgs e) { SqlCommand command = new SqlCommand("SELECT * FROM Xe WHERE MaTheXe = " + Convert.ToInt32(id)); DataTable table = vehicle.getVehicle(command); Calculate calculate = new Calculate(); if (table.Rows.Count > 0) { labelCardID.Text = table.Rows[0]["MaTheXe"].ToString(); labelTypeOfVehicle.Text = table.Rows[0]["LoaiXe"].ToString(); labelInTime.Text = table.Rows[0]["ThoiGianVao"].ToString(); labelShape.Text = table.Rows[0]["HinhThucGui"].ToString(); if (table.Rows[0][1].ToString() == "Xe Dap") { labelPicture.Text = "Vehicle Picture:"; byte[] pic = (byte[])table.Rows[0]["AnhXe"]; MemoryStream AnhXe = new MemoryStream(pic); pictureBoxVehiclePicture.Image = Image.FromStream(AnhXe); } else { labelPicture.Text = "License Picture:"; byte[] pic = (byte[])table.Rows[0]["BienSo"]; MemoryStream BienSo = new MemoryStream(pic); pictureBoxVehiclePicture.Image = Image.FromStream(BienSo); } TimeSpan parkingTime = DateTime.Now.Subtract((DateTime)table.Rows[0]["ThoiGianVao"]); labelDays.Text = parkingTime.Days.ToString(); labelHours.Text = parkingTime.Hours.ToString(); var Fee = calculate.parkingFeeAndFine(labelTypeOfVehicle.Text, labelShape.Text, parkingTime); labelParkingFee.Text = Fee.Item1.ToString(); labelFine.Text = Fee.Item2.ToString(); labelTotal.Text = (Fee.Item1 + Fee.Item2).ToString(); } }
public (float, float) parkingFeeAndFine(string LoaiXe, string HinhThucGui, TimeSpan ThoiGianGui) { Calculate calculate = new Calculate(); DataTable table = calculate.getData(new SqlCommand("SELECT * FROM PhiGuiXe")); float PhiGuiXe = 0; float TienPhat = 0; float cost; // Lấy phí gửi xe theo giờ của từng loại xe trong database if (LoaiXe == "Xe Dap") { cost = float.Parse(table.Rows[0][1].ToString()); } else if (LoaiXe == "Xe May") { cost = float.Parse(table.Rows[2][1].ToString()); } else { cost = float.Parse(table.Rows[1][1].ToString()); } // Tính mức phí của tất cả loại xe if (HinhThucGui == "By Hour") { PhiGuiXe = cost * ThoiGianGui.Hours; if (ThoiGianGui.Days < 1) { TienPhat = 0; } else { TienPhat = (cost * 8 * ThoiGianGui.Days) * 2; } } else if (HinhThucGui == "By Day") { PhiGuiXe = cost * 8; if (ThoiGianGui.Days <= 1) { TienPhat = 0; } else { TienPhat = cost * 8 * 3; } } else if (HinhThucGui == "By Week") { PhiGuiXe = cost * 8 * 3; if (ThoiGianGui.Days <= 10) { TienPhat = 0; } else { TienPhat = cost * 8 * 3 * 2; } } return(PhiGuiXe, TienPhat); }