Exemplo n.º 1
0
        //Constructs a new Edit form for a new entry or an edit session...
        public Form_Edit_New(MainForm mainForm, List<Member> members)
        {
            InitializeComponent();
            parentForm = mainForm;
            memberImpl = new MemberImpl();
            converter = new Converter();

            this.cbxSex.Items.AddRange(new Object[] { Gender.Female.ToString(), Gender.Male.ToString() });
            this.cbxCity.Items.AddRange(new Object[]{Province.Anvers.ToString(), Province.Bruxelles.ToString(),
                Province.Charleroi.ToString(), Province.Liège.ToString(), Province.Namur.ToString(),
                Province.Etranger.ToString()});
            if (members != null)
            {
                this.NewRecord = false;
                this.btnSave.Enabled = true;
                this.editMembers = members;
                this.editMembers.Reverse();
                this.activeMemberIndex = 0;
                this.zapper(activeMemberIndex);
                this.btnZapperNext.Enabled = true;
                this.btnZapperPrev.Enabled = true;
            }
            else
            {
                this.NewRecord = true;
                this.editMembers = null;
                this.btnSave.Enabled = false;
                this.btnZapperNext.Enabled = false;
                this.btnZapperPrev.Enabled = false;
                this.lblZapper.Text = "1/1";
            }
        }
Exemplo n.º 2
0
        private void loadDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.openFileDialog.Title = "Select Excel File";
            this.openFileDialog.Multiselect = false;
            this.openFileDialog.Filter = "MS Office Excel File(*.xls, *xlsx)|*.xls; *xlsx";
            Converter converter = new Converter();
            if (this.openFileDialog.ShowDialog() == DialogResult.OK) {
                string dirName = Path.GetFullPath(this.openFileDialog.FileName);
                FileStream stream = File.Open(dirName, FileMode.Open, FileAccess.Read);
                IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
                //excelReader.IsFirstRowAsColumnNames = true;
                //DataSet result = excelReader.AsDataSet();

                if (excelReader.ResultsCount > 0)
                {
                    List<Member> newMembers = new List<Member>();
                    while (excelReader.Read())
                    {
                        Member member = new Member();
                        member.IsValid = true;
                        member.Lastname = excelReader.GetString(0);
                        member.Firstname = excelReader.GetString(1);
                        if (member.Lastname.Length == 0 || member.Firstname.Length == 0) {
                            member.IsValid = false;
                        }
                        string thisMemberSex = excelReader.GetString(2).ToLower();
                        try
                        {
                            member.Sex = converter.stringToGender(thisMemberSex);
                        }
                        catch (Exception) {
                            member.Sex = Gender.Unspecified;
                            member.IsValid = false;
                        }
                        string thisMemberCity = excelReader.GetString(3).ToLower();
                        try
                        {
                            member.City = converter.stringToCity(thisMemberCity);
                        }
                        catch (Exception) {
                            member.City = Province.Unspecified;
                            member.IsValid = false;
                        }
                        member.Email = excelReader.GetString(4).ToLower();
                        if (!(member.Email.Contains("@") || member.Email.Contains(".") || member.Email.IndexOf("@") > 0 || member.Email.LastIndexOf(".") > member.Email.IndexOf("@")))
                        {
                            member.IsValid = false;
                        }
                        member.Phone = excelReader.GetString(5);
                        try
                        {
                            member.Cardnum = excelReader.GetInt16(6);
                        }
                        catch (FormatException) {
                            member.IsValid = false;
                        }
                        newMembers.Add(member);
                    }
                    this.uploadedMembers = newMembers;
                    //Create a file upload manager...
                    ExcelFileUploader fileUploader = new ExcelFileUploader(this);
                    fileUploader.ShowDialog();
                }
                excelReader.Close();
            }
        }