コード例 #1
0
ファイル: CustomerGUI.cs プロジェクト: anhtv13/ISD_PROJECT
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to delete a customer?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int selectedIndex = table1.CurrentCell.RowIndex;
                    if (selectedIndex >= 0)
                    {
                        String id = table1.Rows[selectedIndex].Cells[0].Value.ToString();

                        cusMan = new CustomerManager();
                        cusMan.deleteCustomer(id);

                        //print log
                        cus = new Customer();
                        DateTime now = DateTime.Now;
                        System.IO.StreamWriter file = new System.IO.StreamWriter(@"person.txt", true);
                        file.WriteLine("Delete customer{" + id + "}" + "    " + now);
                        file.Close();
                        tableGetData();
                        MessageBox.Show("Delete Customer successfully.");
                    }

                    else
                        MessageBox.Show("Select a customer to delete.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #2
0
ファイル: CustomerGUI.cs プロジェクト: anhtv13/ISD_PROJECT
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to add a customer?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    name = textBoxName.Text;
                    address = textBoxAddress.Text;
                    email = textBoxEmail.Text;
                    phone = textBoxPhone.Text;
                    birthday = textBoxBirthday.Text;

                    cus = new Customer(name, address, email, phone, birthday, "0");
                    if (cus.repOK())
                    {
                        //MessageBox.Show(cus.toString());
                        cusMan = new CustomerManager();
                        cusMan.saveCustomer(cus);

                        //write text file
                        //MessageBox.Show(cus.toString());
                        DateTime now = DateTime.Now;
                        System.IO.StreamWriter file = new System.IO.StreamWriter(@"person.txt", true);
                        file.WriteLine("Add customer{" + cus.toStringInfo() + "}" + "    " + now);
                        file.Close();
                        tableGetData();
                        MessageBox.Show("Add customer successfully.");
                    }
                    else
                    {
                        MessageBox.Show("Invalid Customer.");
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #3
0
ファイル: CustomerGUI.cs プロジェクト: anhtv13/ISD_PROJECT
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to update a customer?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int selectedIndex = table1.CurrentCell.RowIndex;
                    if (selectedIndex >= 0)
                    {
                        String id = table1.Rows[selectedIndex].Cells[0].Value.ToString();
                        name = textBoxName.Text;
                        address = textBoxAddress.Text;
                        email = textBoxEmail.Text;
                        phone = textBoxPhone.Text;
                        birthday = textBoxBirthday.Text;
                        point = labelPoint.Text;

                        cus = new Customer(id, name, address, email, phone, birthday, point);
                        if (cus.repOK())
                        {
                            //MessageBox.Show("ID= " + cusID + "\n" + cus.toString());
                            cusMan = new CustomerManager();
                            cusMan.updateCustomer(cus);

                            //write text file
                            DateTime now = DateTime.Now;
                            System.IO.StreamWriter file = new System.IO.StreamWriter(@"person.txt", true);
                            file.WriteLine("Update customer{" + cus.toStringInfo() + "}" + "    " + now);
                            file.Close();
                            tableGetData();
                            MessageBox.Show("Update customer successfully.");
                        }
                        else
                        {
                            MessageBox.Show("Invalid Customer.");
                        }
                    }
                    else
                        MessageBox.Show("Select a customer to update.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }