You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.7 KiB

  1. using Swift.DAL.GridAutoDemo;
  2. using Swift.web.Library;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. namespace Swift.web.GridAutoDemo
  10. {
  11. public partial class InsertDemo : System.Web.UI.Page
  12. {
  13. private readonly EmployeeDetailsDao detailsDao = new EmployeeDetailsDao();
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. txtPageName.Text = "Add Employee";
  17. btnAdd.Visible = true;
  18. btnEdit.Visible = false;
  19. if (!IsPostBack)
  20. {
  21. string eId = GetStatic.ReadQueryString("Id", "");
  22. if (eId != "")
  23. {
  24. EditForm(eId);
  25. }
  26. }
  27. }
  28. protected void btnAdd_Click(object sender, EventArgs e)
  29. {
  30. Msg.Visible = false;
  31. var name = txtName.Text;
  32. var address = txtAddress.Text;
  33. var email = txtEmail.Text;
  34. var mobileNo = txtMobile.Text;
  35. var departName = txtDepName.Text;
  36. var dob = Convert.ToDateTime(txtDob.Text);
  37. var companyJoin = Convert.ToDateTime(txtJoinDate.Text);
  38. int workday = Convert.ToInt32(txtWorkDay.Text);
  39. var description = txtDescription.Text;
  40. var result = detailsDao.EmployeeRegister(new EmployeeModel() { Name = name, Address = address, Email = email, MobileNo = mobileNo, DepartName = departName, DOB = dob, CompanyJoinDate = companyJoin, WorkDayOnWeek = workday, Description = description, Flag = "I" });
  41. if (result.ErrorCode == "1")
  42. {
  43. Msg.CssClass = "alert alert-danger";
  44. Msg.Text = result.Msg;
  45. Msg.Visible = true;
  46. GetStatic.AlertMessage(this, result.Msg);
  47. return;
  48. }
  49. ClearAll();
  50. Msg.CssClass = "alert alert-info";
  51. Msg.Text = "Data Updated !!";
  52. Msg.Visible = true;
  53. }
  54. protected void EditForm(string Id)
  55. {
  56. ClearAll();
  57. var result = detailsDao.GetEmployeeDetails(Id);
  58. if (result != null)
  59. {
  60. txtPageName.Text = "Update Employee";
  61. btnAdd.Visible = false;
  62. btnEdit.Visible = true;
  63. txtId.Text = result["Id"].ToString();
  64. txtName.Text = result["Name"].ToString();
  65. txtAddress.Text = result["Address"].ToString();
  66. txtEmail.Text = result["Email"].ToString();
  67. txtMobile.Text = result["MobileNo"].ToString();
  68. txtDepName.Text = result["DepartName"].ToString();
  69. txtDob.Text = result["DOB"].ToString();
  70. txtJoinDate.Text = result["CompanyJoinDate"].ToString();
  71. txtWorkDay.Text = result["WorkDayOnWeek"].ToString();
  72. txtDescription.Text = result["Description"].ToString();
  73. }
  74. }
  75. protected void btnEdit_Click(object sender, EventArgs e)
  76. {
  77. Msg.Visible = false;
  78. var id = txtId.Text.ToString();
  79. var name = txtName.Text;
  80. var address = txtAddress.Text;
  81. var email = txtEmail.Text;
  82. var mobileNo = txtMobile.Text;
  83. var departName = txtDepName.Text;
  84. var dob = Convert.ToDateTime(txtDob.Text);
  85. var companyJoin = Convert.ToDateTime(txtJoinDate.Text);
  86. int workday = Convert.ToInt32(txtWorkDay.Text);
  87. var description = txtDescription.Text;
  88. var result = detailsDao.EmployeeRegister(new EmployeeModel() { Id = Convert.ToInt32(id), Name = name, Address = address, Email = email, MobileNo = mobileNo, DepartName = departName, DOB = dob, CompanyJoinDate = companyJoin, WorkDayOnWeek = workday, Description = description, Flag = "U" });
  89. if (result.ErrorCode == "1")
  90. {
  91. Msg.CssClass = "alert alert-danger";
  92. Msg.Text = result.Msg;
  93. Msg.Visible = true;
  94. GetStatic.AlertMessage(this, result.Msg);
  95. return;
  96. }
  97. ClearAll();
  98. Msg.CssClass = "alert alert-info";
  99. Msg.Text = "Data Updated !!";
  100. Msg.Visible = true;
  101. }
  102. private void ClearAll()
  103. {
  104. txtId.Text = "";
  105. txtName.Text = "";
  106. txtAddress.Text = "";
  107. txtEmail.Text = "";
  108. txtMobile.Text = "";
  109. txtDepName.Text = "";
  110. txtDob.Text = "";
  111. txtJoinDate.Text = "";
  112. txtWorkDay.Text = "";
  113. txtDescription.Text = "";
  114. }
  115. }
  116. }