/// <summary> /// The get containers. /// </summary> /// <param name="ship"> /// The ship. /// </param> /// <param name="port"> /// The port. /// </param> /// <returns> /// The <see cref="List"/>. /// </returns> public List<Container> GetContainers(string ship, string port) { var containerlist = new List<Container>(); using (var db = new Database()) { Container containers = null; db.OpenConnection(); db.CreateCommand( "Select Container.*,Company.Name AS name,Ship.type AS shiptype from Container,Ship,Port,Company WHERE Ship.Type LIKE @ship AND Port.Name LIKE @port AND Company.ID = Container.Company_ID AND Ship.ID = Container.Ship_ID"); db.AddParameter("@ship", ship); db.AddParameter("@port", port); MySqlDataReader dr = db.Command.ExecuteReader(); while (dr.Read()) { containers = new Container(); containers.id = (int)dr["id"]; containers.type = (string)dr["type"]; containers.weight = (int)dr["weight"]; containers.onship = (string)dr["shiptype"]; containers.companyname = (string)dr["name"]; containerlist.Add(containers); } } return containerlist; }
/// <summary> /// The bt export_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void btExport_Click(object sender, EventArgs e) { { var folderBrowserDialog1 = new FolderBrowserDialog(); // Set the help text description for the FolderBrowserDialog. folderBrowserDialog1.Description = "Selecteer waar u het bestand wilt opslaan."; // Do not allow the user to create new files via the FolderBrowserDialog. folderBrowserDialog1.ShowNewFolderButton = false; // Default to the My Documents folder. folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Personal; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { // Set a variable to the My Documents path. string comboship = this.comboTypeSchip.SelectedItem.ToString(); string port = this.comboBestemming.SelectedItem.ToString(); var company = new Company(); var container = new Container(); string date = DateTime.Now.ToString("dd-MM-yyyy"); //sets the date List<Container> containers = BLContainer.GetContainers(comboship, port); string mydocpath = folderBrowserDialog1.SelectedPath; var str = new StringBuilder(); containers = containers.OrderBy(o => container.companyname).ToList(); //sorts the list on companyname str.AppendLine("Gemaakt op: " + date); //sets date in document str.AppendLine(); str.AppendLine("Bestemming: " + port);//sets selected desination str.AppendLine(); str.AppendLine("Schip type: " + comboship); //sets selected ship str.AppendLine(); foreach (Container containerlist in containers) { str.AppendLine( string.Format( "{0}: Container ID:{1} - X:{2} Y:{3} Z:{4}", containerlist.companyname, containerlist.id, containerlist.x, containerlist.y, containerlist.z)); } using (var outfile = new StreamWriter(mydocpath + @"\CSC Export.txt")) { outfile.Write(str.ToString()); } } } }