private void button1_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.textBox1.Text) || String.IsNullOrEmpty(this.textBox2.Text) || String.IsNullOrEmpty(this.textBox3.Text) || String.IsNullOrEmpty(this.textBox4.Text) || String.IsNullOrEmpty(this.comboBox1.Text) || String.IsNullOrEmpty(this.dateTimePicker1.Text)) { MessageBox.Show("Please Enter Valid Record!!!"); } else { try { Worker w = new Worker(); w.FullName = this.textBox1.Text; w.CNIC = this.textBox2.Text; w.Address = this.textBox3.Text; w.MobileNo = this.textBox4.Text; w.EmgContact = comboBox1.Text; w.JoinDate = Convert.ToDateTime(dateTimePicker1.Value.Date); w.IsActive = this.checkBox2.Text; WorkerBLL wbll = new WorkerBLL(); if (wbll.insertWorker(w)) { MessageBox.Show("Worker Successfully Added!!!!!"); } else { MessageBox.Show("Failed To Add!!!!"); } } catch (Exception ex) { throw ex; } } }
protected void Add_Click(object sender, EventArgs e) { if (this.add.Text == "Update") { if (this.name.Text != "") { worker1.FullName = this.name.Text; } else { Response.Write("<script> alert('Empty Field is not allow fill all fields'); </script> "); } if (this.CNIC.Text != "") { worker1.CNIC = this.CNIC.Text; } else { Response.Write("<script> alert('Empty Field is not allow fill all fields Except UserName'); </script> "); } if (this.address.Text != "") { worker1.Address = this.address.Text; } else { Response.Write("<script> alert('Empty Field is not allow fill all fields'); </script> "); } if (this.mobileNo.Text != "") { worker1.MobileNo = this.mobileNo.Text; } else { Response.Write("<script> alert('Empty Field is not allow fill all fields'); </script> "); } if (this.emg.Text != "") { worker1.EmgContact = this.emg.Text; } else { Response.Write("<script> alert('Empty Field is not allow fill all fields'); </script> "); } if (this.date.Text != "") { worker1.JoinDate = Convert.ToDateTime(this.date.Text); } else { Response.Write("<script> alert('Empty Field is not allow fill all fields'); </script> "); } WorkerBLL wbll = new WorkerBLL(); try { if (wbll.updateWorker(worker1, name3)) { Response.Write("<script> alert('Updated Successfully'); </script> "); this.add.Text = "Add"; } else { Response.Write("<script> alert('Updated Successfully'); </script> "); this.add.Text = "Add"; } this.clearForm(); } catch (Exception ex) { throw ex; } } else { if (String.IsNullOrEmpty(this.name.Text) || String.IsNullOrEmpty(this.CNIC.Text) || String.IsNullOrEmpty(this.address.Text) || String.IsNullOrEmpty(this.emg.Text) || String.IsNullOrEmpty(this.mobileNo.Text) || String.IsNullOrEmpty(this.date.Text)) { Response.Write("<script> alert('Fill the required all fields'); </script> "); } else { Worker w = new Worker(); w.FullName = this.name.Text; w.CNIC = this.CNIC.Text; w.EmgContact = this.emg.Text; w.IsActive = this.IsActive.Text; w.JoinDate = Convert.ToDateTime(this.date.Text); w.MobileNo = this.mobileNo.Text; w.Address = this.address.Text; WorkerBLL wbll = new WorkerBLL(); try { if (wbll.insertWorker(w)) { Response.Write("<script> alert('Successfully saved'); </script> "); this.clearForm(); } else { Response.Write("<script> alert('Failed To Save'); </script> "); this.clearForm(); } } catch (Exception ex) { throw ex; } } } }