Advertisement
Guest User

Untitled

a guest
Jul 27th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.25 KB | None | 0 0
  1. enter code here
  2. public List<TblEmpAttendance> EmpAttendances { get; set; } //get all EmpAttendance Detail list
  3. public TblEmpAttendance SelectedEmpAttendance { get; set; } //display details of selected EmpAttendance Detail
  4. public string DisplayEmpAttendance { get; set; } //EmpAttendance Detail area
  5.  
  6. public partial class TblEmpAttendance
  7. {
  8. public int Emp_Attendance_Id { get; set; }
  9. public string Session { get; set; }
  10. public int Emp_Type_Id { get; set; }
  11. public string Emp_Type { get; set; }
  12. public int Emp_Dept_Id { get; set; }
  13. public string Emp_Deptartment { get; set; }
  14. public System.DateTime Date { get; set; }
  15. public int Emp_Official_Id { get; set; }
  16. public string Emp_Code { get; set; }
  17. public string Emp_Name { get; set; }
  18. public int Status_Id { get; set; }
  19. public string Status { get; set; }
  20.  
  21. [ScriptIgnore]
  22. public TblDepartment TblDepartment { get; set; }
  23. [ScriptIgnore]
  24. public TblEmployeeOfficialDetail TblEmployeeOfficialDetail { get; set; }
  25. [ScriptIgnore]
  26. public TblEmployeeType TblEmployeeType { get; set; }
  27.  
  28. }
  29. }
  30.  
  31. #**my controller:** #
  32. public class EmployeeController : Controller
  33. {
  34. SMS_dbEntities db = new SMS_dbEntities();
  35. EmployeeFullDetailModel empattendancemodel = new EmployeeFullDetailModel();
  36.  
  37. public ActionResult Attendance()
  38. {
  39. EmployeeFullDetailModel model = new EmployeeFullDetailModel();
  40. model.EmpAttendances = db.TblEmpAttendances.OrderBy(m => m.Emp_Attendance_Id).ToList();
  41. model.SelectedEmpAttendance = null;
  42.  
  43. return View(model);
  44.  
  45. }
  46.  
  47. [HttpGet]
  48. public JsonResult GetDepartment(string TypeId = "")
  49. {
  50. int TID = 0;
  51. if (int.TryParse(TypeId, out TID))
  52. {
  53.  
  54. }
  55. if (Request.IsAjaxRequest())
  56. {
  57. var department = db.TblDepartments.Where(m => m.Type_Id.Equals(TID)).OrderBy(m => m.Department_Id).ToList();
  58. return new JsonResult
  59. {
  60. Data = department,
  61. JsonRequestBehavior = JsonRequestBehavior.AllowGet
  62. };
  63. }
  64.  
  65. else
  66. {
  67. return new JsonResult
  68. {
  69. Data = "NOT A VALID REQUEST",
  70.  
  71. };
  72. }
  73.  
  74. }
  75.  
  76. [HttpGet]
  77. public JsonResult GetEMPDetails(string DeptId = "")
  78. {
  79. int DID = 0;
  80. if (int.TryParse(DeptId, out DID))
  81. {
  82.  
  83. }
  84. if (Request.IsAjaxRequest())
  85. {
  86. var empdetails = db.TblEmployeeOfficialDetails.Where(m => m.Employee_Department_Id.Equals(DID)).OrderBy(m => m.Employee_Official_Id).ToList();
  87. return new JsonResult
  88. {
  89. Data = empdetails,
  90. JsonRequestBehavior = JsonRequestBehavior.AllowGet
  91. };
  92. }
  93.  
  94. else
  95. {
  96. return new JsonResult
  97. {
  98. Data = "NOT A VALID REQUEST",
  99.  
  100. };
  101. }
  102.  
  103. }
  104.  
  105. [HttpPost]
  106. public ActionResult NewEmpAttendanceAction()
  107. {
  108.  
  109. ViewBag.code_IdList = new SelectList(db.TblEmployeeOfficialDetails, "Employee_Code", "Employee_Name");
  110. ViewBag.Status_IdList = new SelectList(db.TblAttendanceStatus, "Attendance_Status_Id", "Attendance_Status_Long");
  111. ViewBag.Type_IdList = new SelectList(db.TblEmployeeTypes, "EmployeeType_Id", "EmployeeType_Description");
  112. ViewBag.Department_IdList = new SelectList(db.TblDepartments, "Department_Id", "Department_Name");
  113. empattendancemodel.EmpAttendances = db.TblEmpAttendances.OrderBy(m => m.Emp_Attendance_Id).ToList();
  114. empattendancemodel.SelectedEmpAttendance = null;
  115. empattendancemodel.DisplayEmpAttendance = "WriteOnly";
  116. return View("Attendance", empattendancemodel);
  117.  
  118. }
  119. [HttpPost]
  120. public ActionResult InsertEmpAttendanceAction(TblEmpAttendance empattendanceobj, *List<TblEmpAttendance> attendance*)//returns null always
  121. {
  122. //AND WHAT TO DO HERE
  123. }
  124.  
  125. #**My INSERT PARTIAL VIEW IS:** #
  126.  
  127. foreach(var item in Model)
  128. {
  129. <div>
  130. <div class="form-group" style="width :50%; float:left; padding-right:10px">
  131. <label>SESSION</label> <br />
  132. <input type="text" class="form-control font" id="ses" name="ses" value="2015-2016" readonly>
  133. </div>
  134. <div class="form-group" style="width: 50%; float: right; padding-right: 10px">
  135. <label>DATE</label> <br />
  136. <input type="text" class="form-control font" id="Date" name="Date" value="@item.Date.ToShortDateString()">
  137. </div>
  138. </div>
  139.  
  140. <div>
  141.  
  142. <div class="form-group" style="width :50%; float:left">
  143. <label>EMPLOYEE TYPE</label> <br />
  144. @foreach (var type in ViewBag.Type_IdList)
  145. {
  146. <input type="radio" name="type" value="@type.Value" style="font:bold 16px verdana" /> <label>@type.Text</label> <br />
  147. }
  148. </div>
  149. <div class="form-group" style="width :50%; float:right">
  150. <label>EMPLOYEE DEPARTMENT</label> <br />
  151. @Html.DropDownList("DDLDepartment", ViewBag.Department_IdList as SelectList,"--SELECT DEPARTMENT--", new { @class = "ddlfont" })
  152. </div>
  153. </div>
  154.  
  155.  
  156. <div id="original" hidden>
  157. @Html.DropDownList("DDLStatus", ViewBag.Status_IdList as SelectList, new {@class = "ddlfont" })
  158. </div>
  159.  
  160. <div class="form-group font" id="attend">
  161.  
  162. <table>
  163. <tr>
  164. <th>EMPLOYEE CODE</th>
  165. <th>EMPLOYEE NAME</th>
  166. <th>ATTENDANCE</th>
  167. </tr>
  168. <tr>
  169.  
  170. </tr>
  171.  
  172. </table>
  173. </div>
  174.  
  175.  
  176. <div>
  177. <input type="text" id="Session" name="Session" value="@item.Session">
  178. <input type="text" id="Emp_Official_Id" name="Emp_Official_Id" value="@item.Emp_Official_Id">
  179. <input type="text" id="Emp_Type_Id" name="Emp_Type_Id" value="@item.Emp_Type_Id">
  180. <input type="text" id="Emp_Type" name="Emp_Type" value="@item.Emp_Type">
  181. <input type="text" id="Emp_Dept_Id" name="Emp_Dept_Id" value="@item.Emp_Dept_Id">
  182. <input type="text" id="Emp_Deptartment" name="Emp_Deptartment" value="@item.Emp_Deptartment">
  183. <input type="text" id="Emp_Code" name="Emp_Code" value="@item.Emp_Code">
  184. <input type="text" id="Emp_Name" name="Emp_Name" value="@item.Emp_Name">
  185. <input type="text" id="Status_Id" name="Status_Id" value="@item.Status_Id">
  186. <input type="text" id="Status" name="Status" value="@item.Status">
  187. </div>
  188.  
  189. <div>
  190. <input type="submit" value="SAVE" class="btnsave"
  191. formaction="/Employee/InsertEmpAttendanceAction" />
  192. <input type="submit" value="CANCEL" class="btncancel"
  193. formaction="/Employee/Attendance" />
  194. </div>
  195.  
  196. **AND MY ATTENDANCE PARTIAL VIEW**
  197.  
  198. <div class="box-body">
  199. <button type="submit" class="btn btn-primary" formaction="/Employee/NewEmpAttendanceAction">ADD NEW ATTENDANCE</button>
  200.  
  201.  
  202. @{
  203.  
  204. if (Model.SelectedEmpAttendance != null)
  205. {
  206.  
  207. if (Model.DisplayEmpAttendance == "ReadOnly")
  208. {
  209. Html.RenderPartial("Attendance/ShowAttendance", Model.SelectedEmpAttendance);
  210. }
  211.  
  212. if (Model.DisplayEmpAttendance == "ReadWrite")
  213. {
  214. Html.RenderPartial("Attendance/EditAttendance", Model.SelectedEmpAttendance);
  215. }
  216. }
  217. if (Model.DisplayEmpAttendance == "WriteOnly")
  218. {
  219.  
  220. Html.RenderPartial("Attendance/InsertAttendance", new List<SchoolManagementSystem.EFModel.TblEmpAttendance> {new SchoolManagementSystem.EFModel.TblEmpAttendance()});
  221.  
  222. }
  223.  
  224. }
  225.  
  226.  
  227. <div class="box-header">
  228. <i class="fa fa-envelope"></i>
  229. <h3 class="box-title">VIEW ATTENDANCE DETAILS</h3>
  230.  
  231. <!-- tools box -->
  232. <div class="pull-right box-tools">
  233. <button class="btn btn-info btn-sm" data-widget="collapse" id="collapseview"><i class="fa fa-arrow-circle-right"></i></button>
  234. </div>
  235. </div>
  236.  
  237.  
  238. <div class="box-body">
  239.  
  240.  
  241. <table border="1" cellpadding="10">
  242. <tr class="form-group">
  243. <th>SESSION</th>
  244. <th>TYPE</th>
  245. <th>DATE</th>
  246. <th>EMPLOYEE CODE</th>
  247. <th>NAME</th>
  248. <th>STATUS</th>
  249. <th colspan="2" class="hd">Actions</th>
  250. </tr>
  251.  
  252.  
  253. @if (Model.EmpAttendances != null)
  254. {
  255. foreach (var empattendance in Model.EmpAttendances)
  256. {
  257.  
  258. if (Model.SelectedEmpAttendance != null)
  259. {
  260. if (empattendance.Emp_Attendance_Id == Model.SelectedEmpAttendance.Emp_Attendance_Id)
  261. {
  262. @:
  263. <tr></tr>
  264. }
  265.  
  266. else
  267. {
  268. @:
  269. <tr></tr>
  270. }
  271.  
  272. }
  273.  
  274. else
  275. {
  276. @:
  277. <tr></tr>
  278. }
  279.  
  280. @:
  281. <tr>
  282. <td>@empattendance.Session</td>
  283. <td>@empattendance.Emp_Type</td>
  284. <td>@empattendance.Date</td>
  285. <td>@empattendance.Emp_Code</td>
  286. <td>@empattendance.Emp_Name</td>
  287. <td>@empattendance.Status</td>
  288.  
  289. <td><input type="submit" id="btnselect" formaction="~/Employee/SelectEmpAttendanceAction/@empattendance.Emp_Attendance_Id" value="SELECT" class="btnselect" /></td>
  290. <td><input type="submit" id="btndelete" formaction="~/Employee/DeleteEmpAttendanceAction/@empattendance.Emp_Attendance_Id" value="DELETE" class="btndelete" /></td>
  291. </tr>
  292. }
  293. }
  294. </table>
  295. </div>
  296.  
  297. </div>
  298. </div>
  299. </form>
  300.  
  301.  
  302. </section>
  303. </div><!-- /.content-wrapper -->
  304.  
  305. #**MY JQUERY IS:** #
  306.  
  307. $(document).ready(function () {
  308. $("#Session").val($('#ses').val());
  309. $('#DDLDepartment').attr('disabled', true);
  310. $("input[type='radio']").change(function () {
  311.  
  312. if ($(this).select = true) {
  313. $('#Emp_Type').val($(this).next('label').text());
  314. $("#Emp_Type_Id").val($(this).val());
  315.  
  316. var typeid = parseInt($(this).val());
  317. console.log(typeid);
  318.  
  319. var ddldept = $('#DDLDepartment');
  320. ddldept.empty();
  321. ddldept.append($("<option></option").val("").html("--SELECT DEPARTMENT--"));
  322. //console.log(ddldept);
  323.  
  324. $.ajax({
  325. url: "@Url.Action("GetDepartment", "Employee")",
  326. type: "GET",
  327. data: { TypeId: typeid },
  328. dataType: "json",
  329. contentType: "application/json",
  330. processdata: true,
  331. success: function (data) {
  332. $.each(data, function (i, valdept) {
  333. console.log(valdept);
  334. //console.log(ddldept);
  335. ddldept.append(
  336. $("<option value='" + valdept.Department_Id + "'>" + valdept.Department_Name + "</option>")
  337. );
  338. $('#DDLDepartment').attr('disabled', false)
  339. });
  340. },
  341.  
  342. error: function () {
  343.  
  344. },
  345.  
  346. });
  347. }
  348. else {
  349. alert("SELECT VALID TYPE")
  350. $('#DDLDepartment').empty();
  351. $('#DDLDepartment').attr('disabled', true);
  352. }
  353.  
  354.  
  355. });
  356. });
  357.  
  358.  
  359.  
  360.  
  361. $(document).ready(function () {
  362. $("#DDLDepartment").click(function () {
  363.  
  364. $("#Emp_Deptartment").val($("#DDLDepartment option:selected").text());
  365. $("#Emp_Dept_Id").val($("#DDLDepartment option:selected").val());
  366.  
  367. $('#attend table tr:not(:first)').remove();
  368. var deptid = parseInt($('#DDLDepartment').val());
  369. console.log(deptid);
  370. if ($('#DDLDepartment').val() != "--SELECT DEPARTMENT--") {
  371.  
  372. $.ajax({
  373. url: "@Url.Action("GetEMPDetails", "Employee")",
  374. type: "GET",
  375. data: { DeptId: deptid },
  376. dataType: "json",
  377. contentType: "application/json",
  378. processdata: true,
  379. success: function (data) {
  380. var dropdown = $('#DDLStatus').clone();
  381. $.each(data, function (i, empdetail) {
  382. console.log(empdetail);
  383. $('#attend table').append("<tr><td>" + empdetail.Employee_Code + "</td><td>" + empdetail.Employee_Name + "</td><td>" + "<span class='abc'></span>" + "</td></tr>");
  384. $('.abc').html(dropdown);
  385.  
  386.  
  387. //$("#Emp_Official_Id").val(empdetail.Employee_Official_Id);
  388.  
  389.  
  390. });
  391.  
  392.  
  393. },
  394.  
  395. });
  396. }
  397. else {
  398. alert(" PLEASE SELECT VALID DEPARTMENT ")
  399. }
  400.  
  401. });
  402. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement