旅行フォーム、配送フォーム、集荷フォーム
メインフォームには、テキストボックスにデータを入力する場所から旅行に移動するボタンがあり、追加を押すとlistbox
、メインフォームに入力したデータに応じて集荷または配達が追加されます
listbox
メイン フォームの に配信を追加すると、配信フォームの にもlistbox
配信が追加されるようにするにはどうすればよいですか
またはlistbox
、メインフォームにピックアップを追加すると、ピックアップフォームにもピックアップが追加さlistbox
れます
配信を追加する方法のサンプルコード:
メイン フォームの [配送を追加] ボタン:
private void btnDelivery_Click(object sender, EventArgs e)
{
deliveryForm.deliverytrips = new DeliveryTrips();
//New delivery- note added to the deliveryForm object
deliveryForm.ShowDialog();
//Show the deliveryForm. ShowDialog ensures that the form has the exclusive focus until it is closed.
if (deliveryForm.deliverytrips != null)
//if null then the "cancel" button was pressed
{
DeliveryTrips newApp = deliveryForm.deliverytrips;
//Get the delivery object from the form
theDelivery.addDeliveryTrip(newApp);
//Add the delivery to the summary
}
updateList();
//Update the list object to reflect the delivery in the summary
メイン フォームのリストボックスに配達を追加するための TRIP FROM のコード:
public partial class frmDelivery : Form
{
private DeliveryTrips theDeliveryTrips;
//The DeliveryTrips object being created/edited
public DeliveryTrips deliverytrips
{ //Property to allow access to theDeliveryTrips
get { return theDeliveryTrips; }
set { theDeliveryTrips = value; }
}
public frmDelivery()
{ //Constructor
InitializeComponent();
}
private void frmDelivery_Load(object sender, EventArgs e)
{
//When makeing the form visible, set the text boxes to reflect the values in
//theDeliveryTrips.
if (theDeliveryTrips != null)
{
txtDescription.Text = "Delivery";
txtDescription.ReadOnly = true;
txtCustomerName.Text = theDeliveryTrips.customername;
txtCustomerAddress.Text = theDeliveryTrips.customeraddress;
txtTime.Text = theDeliveryTrips.arrivaltime.ToString();
}
}
private void btnAdd_Click_1(object sender, EventArgs e)
{
theDeliveryTrips.description = txtDescription.Text;
theDeliveryTrips.customername = txtCustomerName.Text;
theDeliveryTrips.customeraddress = txtCustomerAddress.Text;
theDeliveryTrips.arrivaltime = TimeSpan.Parse(txtTime.Text);
this.Hide();
//Hide the forum
}
private void btnCancel_Click_1(object sender, EventArgs e)
{
theDeliveryTrips = null;
//Set theDeliveryTrips to null as to remove any changes made
this.Hide();
//Hide the forum
}
}