Beispiel #1
0
 /// <summary>
 /// btnUpdate_Click
 /// </summary>
 /// <param name="sender">sender</param>
 /// <param name="e">EventArgs</param>
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.txtId.Text != "" && this.txtId.Text != "" && this.txtEmail.Text != "")
         {
             if (this.dgvMembers.Rows[Containers.ROW_INDEX].Cells[0].Value.ToString() != this.txtId.Text)
             {
                 MessageBox.Show("Don't change Id\nId is primary key.",
                                 Containers.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 Containers.CONNECTION = DBA.Connect();
                 Containers.CONNECTION.Open();
                 Containers.DATA_TABLE = DBA.Fill(SQL.Find(), Containers.CONNECTION, this.txtId.Text);
                 if (Containers.DATA_TABLE.Rows.Count == 0)
                 {
                     MessageBox.Show(String.Format("Not member has Id = {0}.", this.txtId.Text),
                                     Containers.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     Containers.HASH_TABLE = new Hashtable();
                     Containers.HASH_TABLE.Add(Member.fillable[0], this.txtId.Text);
                     Containers.HASH_TABLE.Add(Member.fillable[1], this.txtName.Text);
                     Containers.HASH_TABLE.Add(Member.fillable[2], this.txtEmail.Text);
                     Containers.CONNECTION = DBA.Connect();
                     Containers.CONNECTION.Open();
                     DBA.ExecuteNonQuery(SQL.Update(), Containers.CONNECTION, Containers.HASH_TABLE);
                     MessageBox.Show("Update member success.",
                                     Containers.SUCCESS, MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("Update member fail.",
                         Containers.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Containers.CONNECTION.Close();
         PutData();
         FormClear();
     }
 }
Beispiel #2
0
 /// <summary>
 /// btnAdd_Click
 /// </summary>
 /// <param name="sender">sender</param>
 /// <param name="e">EventArgs</param>
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.txtName.Text != "" && this.txtEmail.Text != "")
         {
             Containers.CONNECTION = DBA.Connect();
             Containers.CONNECTION.Open();
             Containers.DATA_TABLE = DBA.Fill(SQL.Find(), Containers.CONNECTION, this.txtId.Text);
             if (Containers.DATA_TABLE.Rows.Count > 0)
             {
                 // rows init
                 IList <int> rows = new List <int>();
                 for (int index = 0; index < dgvMembers.Rows.Count - 1; index++)
                 {
                     if (Containers.DATA_TABLE.Rows[0][0].ToString() == dgvMembers.Rows[index].Cells[0].Value.ToString())
                     {
                         rows.Add(index + 1);
                     }
                 }
                 MessageBox.Show(String.Format("Exist member at row: {0}.", String.Join(",", rows.ToArray())),
                                 Containers.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 Containers.HASH_TABLE = new Hashtable();
                 Containers.HASH_TABLE.Add(Member.fillable[0], this.txtId.Text);
                 Containers.HASH_TABLE.Add(Member.fillable[1], this.txtName.Text);
                 Containers.HASH_TABLE.Add(Member.fillable[2], this.txtEmail.Text);
                 DBA.ExecuteNonQuery(SQL.Insert(), Containers.CONNECTION, Containers.HASH_TABLE);
                 MessageBox.Show("Add member success.",
                                 Containers.SUCCESS, MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("Add member fail.",
                         Containers.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Containers.CONNECTION.Close();
         PutData();
         FormClear();
     }
 }
Beispiel #3
0
 /// <summary>
 /// PutData
 /// </summary>
 public void PutData()
 {
     try
     {
         Containers.CONNECTION = DBA.Connect();
         Containers.CONNECTION.Open();
         Containers.DATA_TABLE      = DBA.Fill(SQL.Query(), Containers.CONNECTION, String.Empty);
         this.dgvMembers.DataSource = Containers.DATA_TABLE;
     }
     catch (Exception exception)
     {
         MessageBox.Show("Query member fail.",
                         Containers.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Containers.CONNECTION.Close();
     }
 }