Beispiel #1
0
        private void btnEditCustomer_Click(object sender, EventArgs e)
        {
            if (dgvFiltered.SelectedRows.Count > 0)
            {
                formAdd_Edit form1 = new formAdd_Edit(listCustomerAll);
                ChangeLanguage(cBoxLanguage.SelectedItem.ToString(), form1);
                //form1.setBalanceReadOnly();
                form1.txtBoxBalance.Enabled = false;
                form1.setFirstNameReadOnly();

                // Import Data of selected Customer
                Customer cust1 = (Customer)dgvFiltered.SelectedRows[0].DataBoundItem;
                form1.setID(cust1.ID);
                form1.setFirstName(cust1.FirstName);
                form1.setLastName(cust1.LastName);
                form1.setEMail(cust1.eMail);
                form1.setBalance(cust1.Balance);

                form1.setTitle((sender as Button).Text);
                if (form1.ShowDialog() == DialogResult.OK)
                {
                    cust1.FirstName = form1.getFirstName();
                    cust1.LastName  = form1.getLastName();
                    cust1.eMail     = form1.getEMail();
                    cust1.addMoney(form1.getAddMoney());
                    UpdateDataGridView(cBoxFilterBy.SelectedIndex, txtBxFilterBy.Text);
                    writeCSV(listCustomerAll);
                }
            }
            else
            {
                MessageBox.Show("No customer was selected!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Beispiel #2
0
        private void btnAddCustomer_Click(object sender, EventArgs e)
        {
            formAdd_Edit form1 = new formAdd_Edit(listCustomerAll);

            ChangeLanguage(cBoxLanguage.SelectedItem.ToString(), form1);
            form1.txtBoxAddMoney.Enabled = false;

            form1.setTitle((sender as Button).Text);
            if (form1.ShowDialog() == DialogResult.OK)
            {
                listCustomerAll.Add(form1.customer1);
                writeCSV(listCustomerAll);
                UpdateDataGridView(cBoxFilterBy.SelectedIndex, txtBxFilterBy.Text);
            }
        }
Beispiel #3
0
        private bool writeCSV(List <Customer> ListWriteAll)
        {
            try
            {
                if (saveStream.Equals(""))
                {
                    //exception is thrown
                }
                else if (savetoother.Equals(true))     //wenn save button gedrückt wird
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.Filter           = "CSV files (*.csv)|*.csv";
                    saveFileDialog.FilterIndex      = 2;
                    saveFileDialog.RestoreDirectory = true;

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            if ((saveStream = saveFileDialog.OpenFile()) != null)
                            {
                                dateipath = saveFileDialog.FileName;
                                Console.WriteLine(dateipath);
                                using (StreamWriter sw = new StreamWriter(saveStream))
                                {
                                    sw.WriteLine("ID;Balance;FirstName;LastName;Email");

                                    formAdd_Edit form1 = new formAdd_Edit(listCustomerAll);

                                    foreach (var l in listCustomerAll)
                                    {
                                        String res = encriptData(l.ID.ToString(), l.Balance.ToString(), l.FirstName, l.LastName, l.eMail);
                                        Console.WriteLine(res);
                                        sw.WriteLine(res);
                                    }
                                    sw.Close();
                                }

                                return(true);
                            }
                            return(false);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: Could not write to file from disk. Original error: " + ex.Message);
                        }
                    }
                }

                else
                {
                    using (StreamWriter sw = new StreamWriter(dateipath, false))
                    {
                        sw.WriteLine("ID;Balance;FirstName;LastName;Email");

                        formAdd_Edit form1 = new formAdd_Edit(listCustomerAll);

                        foreach (var l in listCustomerAll)
                        {
                            String res = encriptData(l.ID.ToString(), l.Balance.ToString(), l.FirstName, l.LastName, l.eMail);
                            Console.WriteLine(res);
                            sw.WriteLine(res);
                        }
                        sw.Close();
                    }
                    saveStream.Close();
                    return(true);
                }
            }

            catch (Exception e)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter           = "CSV files (*.csv)|*.csv";
                saveFileDialog.FilterIndex      = 2;
                saveFileDialog.RestoreDirectory = true;

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        if ((saveStream = saveFileDialog.OpenFile()) != null)
                        {
                            dateipath = saveFileDialog.FileName;
                            Console.WriteLine(dateipath);
                            using (StreamWriter sw = new StreamWriter(saveStream))
                            {
                                sw.WriteLine("ID;Balance;FirstName;LastName;Email");

                                formAdd_Edit form1 = new formAdd_Edit(listCustomerAll);

                                foreach (var l in listCustomerAll)
                                {
                                    String res = encriptData(l.ID.ToString(), l.Balance.ToString(), l.FirstName, l.LastName, l.eMail);
                                    Console.WriteLine(res);
                                    sw.WriteLine(res);
                                }
                                sw.Close();
                            }

                            return(true);
                        }
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: Could not write to file from disk. Original error: " + ex.Message);
                    }
                }
            }
            return(false);
        }