private void Receive(string serial) { this.serial.Text = serial; vehicle = DeputeDao.GetBySerial(serial); if (vehicle != null) { this.setControlReadOnly(false); this.isUpdate = true; try { SetDeputeInfo(vehicle); } catch { MessageUtil.ShowWarning("发生错误!"); } this.SetOriginCustomer(vehicle.OriginCustomer); this.SetCurrentCustomer(vehicle.CurrentCustomer); } else { this.serial.Focus(); } }
public static void DeleteDepute(Depute entity) { ISession session = SessionFactory.OpenSession(); { session.Delete(entity); session.Flush(); } }
public static object AddDepute(Depute entity) { entity.Serial = GetLatestSerial(); ISession session = SessionFactory.OpenSession(); { var id = session.Save(entity); session.Flush(); return(id); } }
/// <summary> /// 设置车辆信息 /// </summary> /// <param name="vehicle"></param> public void SetDeputeInfo(Depute vehicle) { this.reserial.Text = vehicle.Reserial; this.originId.Text = vehicle.OriginCustomer.UserId; if (vehicle.Originpic != null) { this.originPic.Image = Utilities.ConvertBytes2Image(vehicle.Originpic); } this.currentId.Text = vehicle.CurrentCustomer.UserId; if (vehicle.Currentpic != null) { this.currentPic.Image = Utilities.ConvertBytes2Image(vehicle.Currentpic); } this.license.Text = vehicle.License; this.vin.Text = vehicle.Vin; this.vehicleType.SelectedValue = vehicle.Vehicletype.Id; this.brand.Text = vehicle.Brand; this.certificate.Text = vehicle.Certificate; this.register.Text = vehicle.Register; this.certification.Text = vehicle.Certification; this.department.Text = vehicle.Department; if (vehicle.Company.Id != null) { this.company.SelectedValue = vehicle.Company.Id; } if (vehicle.Firstpic != null) { this.pictureBox1.Image = Utilities.ConvertBytes2Image(vehicle.Firstpic); } if (vehicle.Secondpic != null) { this.pictureBox2.Image = Utilities.ConvertBytes2Image(vehicle.Secondpic); } if (vehicle.Thirdpic != null) { this.pictureBox3.Image = Utilities.ConvertBytes2Image(vehicle.Thirdpic); } if (vehicle.Forthpic != null) { this.pictureBox4.Image = Utilities.ConvertBytes2Image(vehicle.Forthpic); } if (vehicle.Istraded) { this.retradeBtn.Enabled = false; this.saveBtn.Enabled = false; } }
/// <summary> /// 保存按钮点击,将数据保存至数据库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveBtn_Click(object sender, EventArgs e) { this.ValidateChildren(ValidationConstraints.Enabled & ValidationConstraints.TabStop & ValidationConstraints.Selectable); if (!ValidatorManager.ValidateControls(this)) { MessageBox.Show("控件内容不合法"); return; } Customer originInfo = GetOriginCustomer(); Customer currentInfo = GetCurrentCustomer(); Depute vehicle = GetDeputeInfo(); if (this.isUpdate) { try { //CustomerDao.Update(originInfo); //CustomerDao.Update(currentInfo); DeputeDao.UpdateDepute(vehicle); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } else { try { //CustomerDao.Add(originInfo); //CustomerDao.Add(currentInfo); object id = DeputeDao.AddDepute(vehicle); MessageBox.Show("当前流水号为 " + id); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } this.resetControlContent(); this.setControlReadOnly(true); this.serial.Focus(); }
/// <summary> /// 流水号失去焦点后,如果用户输入了流水号,则根据输入的流水号进行查找,否则生成流水号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void serial_Leave(object sender, EventArgs e) { if (this.serial.ReadOnly || (this.serial.Text.Length != 11 && this.serial.Text.Length != 0)) { return; } InitComboBox(); if (Utilities.IsNullOrEmpty(this.serial.Text)) { vehicle = new Depute(); this.serial.Text = DeputeDao.GetLatestSerial(); this.setControlReadOnly(false); this.isUpdate = false; } else { vehicle = DeputeDao.GetBySerial(this.serial.Text); if (vehicle != null) { this.setControlReadOnly(false); this.isUpdate = true; SetDeputeInfo(vehicle); this.SetOriginCustomer(vehicle.OriginCustomer); this.SetCurrentCustomer(vehicle.CurrentCustomer); } else { this.serial.Focus(); } } }
/// <summary> /// 挂车交易 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void retradeBtn_Click(object sender, EventArgs e) { this.ValidateChildren(ValidationConstraints.Enabled & ValidationConstraints.TabStop & ValidationConstraints.Selectable); if (!ValidatorManager.ValidateControls(this)) { MessageBox.Show("控件内容不合法"); return; } Customer originInfo = GetOriginCustomer(); Customer currentInfo = GetCurrentCustomer(); Depute vehicle = GetDeputeInfo(); try { if (this.isUpdate) { DeputeDao.UpdateDepute(vehicle); } else { object id = DeputeDao.AddDepute(vehicle); } } catch (Exception ex) { MessageBox.Show("保存二次过户信息时出错,错误信息为:" + ex.Message); return; } if (vehicle.Istraded) { MessageBox.Show("此流水号挂车交易已经结束!"); } Vehicle _vehicle = new Vehicle(); _vehicle.OriginCustomer = GetOriginCustomer(); _vehicle.CurrentCustomer = GetCurrentCustomer(); _vehicle.License = this.license.Text; _vehicle.Vin = this.vin.Text; _vehicle.Vehicletype = new Vehicletype(); _vehicle.Vehicletype.Id = this.vehicleType.SelectedValue.ToString(); _vehicle.Brand = this.brand.Text; _vehicle.Certificate = this.certificate.Text; _vehicle.Register = this.register.Text; _vehicle.Certification = this.certification.Text; _vehicle.Department = this.department.Text; _vehicle.Company = new Company(); _vehicle.Company.Id = this.company.SelectedValue.ToString(); _vehicle.Originpic = Utilities.ConvertImage2Bytes(this.originPic.Image); _vehicle.Currentpic = Utilities.ConvertImage2Bytes(this.currentPic.Image); _vehicle.Firstpic = Utilities.ConvertImage2Bytes(this.pictureBox1.Image); _vehicle.Secondpic = Utilities.ConvertImage2Bytes(this.pictureBox2.Image); _vehicle.Thirdpic = Utilities.ConvertImage2Bytes(this.pictureBox3.Image); _vehicle.Forthpic = Utilities.ConvertImage2Bytes(this.pictureBox4.Image); _vehicle.Actual = "0"; _vehicle.Transactions = "0"; _vehicle.SaveDate = DateTime.ParseExact(VehicleDao.GetCurrentTimestamp(), "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture); _vehicle.Saver = vehicle.Saver; try { vehicle.Reserial = VehicleDao.AddVehicle(_vehicle).ToString(); vehicle.Istraded = true; DeputeDao.UpdateDepute(vehicle); Clipboard.SetDataObject(vehicle.Reserial); MessageBox.Show("过户流水号为:" + vehicle.Reserial + "。此号码已经复制在粘贴板中,可在信息录入界面按Ctrl+V粘贴使用。"); } catch (Exception ex) { MessageBox.Show("二次过户时出错,错误信息为:" + ex.Message); return; } this.resetControlContent(); this.setControlReadOnly(true); this.serial.Focus(); }