示例#1
0
        private void OpenAddEmployeeForm(object sender, EventArgs e)
        {
            var aef = new AddEmployeeForm {
                Owner = this
            };

            aef.ShowDialog();
        }
示例#2
0
        private void ImportXML(string path)
        {
            using (XmlReader xmlreader = XmlReader.Create(path))
            {
                var serializer = new XmlSerializer(typeof(Employee[]));
                if (serializer.CanDeserialize(xmlreader))
                {
                    Employee[] employees = (Employee[])serializer.Deserialize(xmlreader);
                    var        aef       = new AddEmployeeForm();
                    using (OleDbConnection connection = new OleDbConnection())
                    {
                        connection.ConnectionString = MainForm.Connection;
                        try
                        {
                            connection.Open();
                            for (int i = 0; i < employees.Length; i++)
                            {
                                OleDbCommand add = connection.CreateCommand();
                                //employees[i].ID or aef.FindNewID().ToString("D4")
                                add.CommandText = "INSERT INTO Employees (ID, FirstName, MiddleName," +
                                                  " LastName, DateOfBirth, PhoneNumber, HomeAddress)" +
                                                  " VALUES ('" + aef.FindNewID().ToString("D4") + "','" +
                                                  employees[i].FirstName + "','" + employees[i].MiddleName + "','" +
                                                  employees[i].LastName + "','" + employees[i].DateOfBirth + "','" +
                                                  employees[i].PhoneNumber + "','" + employees[i].HomeAddress + "')";
                                add.ExecuteNonQuery();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString());
                        }
                    }
                }
            }

            FillEmployeesTableAsync(this, EventArgs.Empty);
        }