コード例 #1
0
ファイル: Insert_Form.cs プロジェクト: TashikMoin/Skedulo
 private void Insert_Button_Click(object sender, EventArgs e)
 {
     if (From == "Insert")
     {
         Employee.Id   = int.Parse(Id_Textbox.Text);
         Employee.Name = Name_Textbox.Text;
         Employee.Experience_In_Years = Experience_Textbox.Text;
         Employee.JobRole             = JobRole_Textbox.Text;
         Employee.Salary = int.Parse(Salary_Textbox.Text);
         Data_Object.EmployeeTables.InsertOnSubmit(Employee); // Data that is to be submitted is now in pending state
         Data_Object.SubmitChanges();
         MessageBox.Show(" Data Has Been Inserted Successfully. ");
         Clear("Insert");
     }
     else if (From == "Update")
     {
         EmployeeTable Employee = Data_Object.EmployeeTables.SingleOrDefault(X => X.Id == int.Parse(Id_Textbox.Text));
         Employee.Id                  = int.Parse(Id_Textbox.Text.ToString());
         Employee.Name                = Name_Textbox.Text.ToString();
         Employee.Salary              = decimal.Parse(Salary_Textbox.Text.ToString());
         Employee.JobRole             = JobRole_Textbox.Text.ToString();
         Employee.Experience_In_Years = Experience_Textbox.Text.ToString();
         Data_Object.SubmitChanges();
         MessageBox.Show(" Data Has Been Updated. ");
         Clear("Update");
     }
     else
     {
         MessageBox.Show(" An Error Occured, Please Try Again ");
     }
 }
コード例 #2
0
 private void Delete_Button_Click(object sender, EventArgs e)
 {
     if (Data_Grid.SelectedRows.Count > 0)
     {
         if (MessageBox.Show("Are You Sure Do You Want To Delete ? ", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             for (int Record = 0; Record < Data_Grid.SelectedRows.Count; ++Record)
             {
                 int           Emp_Id   = Convert.ToInt32(Data_Grid.SelectedRows[Record].Cells[0].Value);
                 EmployeeTable Employee = Data_Object.EmployeeTables.SingleOrDefault(Emp => Emp.Id == Emp_Id);
                 Data_Object.EmployeeTables.DeleteOnSubmit(Employee);
                 Data_Object.SubmitChanges();
             }
             Load_Data();
         }
     }
 }