コード例 #1
0
ファイル: StaffManager.cs プロジェクト: anhtv13/ISD_PROJECT
 public void saveStaff(Staff sta)
 {
     cmd.CommandText = "INSERT INTO staff(name, address, email, phone, birthday, role)" +
                 " values(@name, @address, @email, @phone, @birthday, @role)";
             cmd.Parameters.AddWithValue("@name", sta.getName());
             cmd.Parameters.AddWithValue("@address", sta.getAddress());
             cmd.Parameters.AddWithValue("@email", sta.getEmail());
             cmd.Parameters.AddWithValue("@phone", sta.getPhone());
             cmd.Parameters.AddWithValue("@birthday", sta.getBirthday());
             cmd.Parameters.AddWithValue("@role", sta.getRoleId());
             cmd.ExecuteNonQuery();
             conn.Close();
 }
コード例 #2
0
ファイル: StaffManager.cs プロジェクト: anhtv13/ISD_PROJECT
 public void updateStaff(Staff sta)
 {
     cmd.CommandText = " UPDATE staff SET name = @name, address=@address, "+
                       " email = @email, phone = @phone, birthday=@birthday, role = @role "+
                       " where id = @id ";
     cmd.Parameters.AddWithValue("@name", sta.getName());
     cmd.Parameters.AddWithValue("@address", sta.getAddress());
     cmd.Parameters.AddWithValue("@email", sta.getEmail());
     cmd.Parameters.AddWithValue("@phone", sta.getPhone());
     cmd.Parameters.AddWithValue("@birthday", sta.getBirthday());
     cmd.Parameters.AddWithValue("@role", sta.getRoleId());
     cmd.Parameters.AddWithValue("@id", sta.getId());
     cmd.ExecuteNonQuery();
     conn.Close();
 }
コード例 #3
0
ファイル: StaffGUI.cs プロジェクト: anhtv13/ISD_PROJECT
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to add a staff?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    name = textBoxName.Text;
                    address = textBoxAddress.Text;
                    email = textBoxEmail.Text;
                    phone = textBoxPhone.Text;
                    birthday = textBoxBirthday.Text;
                    role = int.Parse(comboBox1.SelectedItem.ToString());

                    sta = new Staff(name, address, email, phone, birthday, role);
                    if (sta.repOK())
                    {
                        //MessageBox.Show(sta.toString());
                        staMan = new StaffManager();
                        staMan.saveStaff(sta);

                        //write text file
                        DateTime now = DateTime.Now;
                        System.IO.StreamWriter file = new System.IO.StreamWriter(@"person.txt", true);
                        file.WriteLine("Add staff{" + sta.toStringInfo() + "}" + "    " + now);
                        file.Close();
                        tableGetData();
                        MessageBox.Show("Add staff successfully");
                    }
                    else
                    {
                        MessageBox.Show("Invalid Staff.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #4
0
ファイル: StaffGUI.cs プロジェクト: anhtv13/ISD_PROJECT
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to delete a staff?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int selectedIndex = table1.CurrentCell.RowIndex;
                    if (selectedIndex >= 0)
                    {
                        String id = table1.Rows[selectedIndex].Cells[0].Value.ToString();
                        //MessageBox.Show(id);

                        staMan = new StaffManager();
                        staMan.deleteStaff(id);

                        //write text file
                        sta = new Staff();
                        DateTime now = DateTime.Now;
                        System.IO.StreamWriter file = new System.IO.StreamWriter(@"person.txt", true);
                        file.WriteLine("Delete staff{" + id + "}" + "    " + now);
                        file.Close();
                        tableGetData();
                        MessageBox.Show("Delete staff successfully.");
                    }
                    else
                        MessageBox.Show("Select a staff to delete.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }