Form Design code for User Table

  1. <div class="hideeee" name="myhide" ng-show="edit3" ng-hide="false">
  2. <button class="btn btn-success" ng-click="editUser()" style="margin-left: 980px;
  3. margin-top: 7px">
  4. <span class="glyphicon glyphicon-user"></span>Create New User
  5. </button>
  6. <label id="msgLab" style="color: #008080; font-size: large"></label>
  7. <br /><%--
  8. <label >
  9. Search:</label>--%>
  10. <br /><%--
  11. <input type="text" ng-model="search" ng-keydown="clear()" style="margin-left: 980px;" placeholder="Search">--%>
  12. <hr />
  13. <div class="manish">
  14. <h3>
  15. Users</h3>
  16. <hr />
  17. <form class="navbar-form" role="search">
  18. <div class="input-group add-on">
  19. <input ng-model="search" ng-keydown="clear()" placeholder="Search" name="srch-term" id="search" class="form-control" type="text">
  20. <div class="input-group-btn">
  21. <button class="btn btn-default" type="submit">
  22. <i class="glyphicon glyphicon-search"></i> Search
  23. </button>
  24. </div>
  25. </div>
  26. </form>
  27. <pagination style="margin-left: 850px;" total-items="totalItems" items-per-page="itemsPerPage" ng-model="currentPage" ng-change="pageChanged()" class="pagination-sm" boundary-links="true" previous-text="‹" next-text="›" first-text="«" last-text="»"></pagination>
  28. <br />
  29. [
  30. <a href="" ng-click="Btn=''">Reset</a> ]
  31. <table class="table table-striped table-bordered table-condensed">
  32. <thead>
  33. <tr class="danger"><%--
  34. <th>
  35. ID
  36. </th>--%>
  37. <th>
  38. <a href="" ng-click="Btn = 'name'; reverse=true"></a>
  39. <a href="" ng-click="Btn = '-fName'; reverse=true">First Name</a>
  40. </th>
  41. <th class="text-center">
  42. <a href="" ng-click="Btn = 'name'; reverse=true"></a>
  43. <a href="" ng-click="Btn = '-lName'; reverse=true">Last Name</a>
  44. </th>
  45. <th class="text-center" colspan="2">
  46. <a href="" ng-click="Btn = 'name'; reverse=true"></a>
  47. <a href="" ng-click="Btn = '-email'; reverse=true">Email Id</a>
  48. </th>
  49. <th class="text-center" colspan="2">
  50. <a href="" ng-click="Btn = 'num'; reverse=true"></a>
  51. <a href="" ng-click="Btn = '-number'; reverse=true">Phone Number</a>
  52. </th>
  53. <th class="text-center" colspan="2" >
  54. Image
  55. </th>
  56. <th class="text-center">
  57. Action
  58. </th>
  59. </tr>
  60. </thead>
  61. <tbody>
  62. <tr style="color: #7A2900" ng-repeat="user in usersa | filter:search | orderBy:Btn:reverse "><%--
  63. <td class="danger" class="text-center">
  64. {{user.id }}
  65. </td>--%>
  66. <td>
  67. {{user.fName }}
  68. </td>
  69. <td class="text-center">
  70. {{user.lName }}
  71. </td>
  72. <td class="text-center" colspan="2">
  73. {{user.email }}
  74. </td>
  75. <td class="text-center" colspan="2">
  76. {{user.number }}
  77. </td>
  78. <td class="text-center" colspan="2">
  79. <img ng-src="upload/{{user.hid}}" height="100px" width="100px" />
  80. </td>
  81. <td class="text-center">
  82. <a href="#" class="btn btn-primary" ng-click="edit(user.id)">
  83. <span class="glyphicon glyphicon-pencil"></span>Edit
  84. </a> |
  85. <a href="#" class="btn btn-danger" ng-click="del(user.id)">
  86. <span
  87. class="glyphicon glyphicon-remove"></span>Delete
  88. </a>
  89. </td>
  90. </tr>
  91. </tbody>
  92. </table>
  93. <p ng-hide="true">
  94. total Items: {{totalItems}}
  95. <br />
  96. Items per page: {{itemsPerPage}}
  97. <br />
  98. Current Page: {{currentPage}}
  99. </p>
  100. </div>
  101. </div>


Code For User Form Design
  1. <div class="form-horizontal" name="myForm" ng-show="edit2" ng-hide="true">
  2. <hr />
  3. <h3 ng-show="edit1" ng-hide="false">
  4. Create New User:</h3>
  5. <h3 ng-show="edit11" ng-hide="false"">
  6. Edit User:</h3>
  7. <input type="hidden" ng-model="newuser.id" />
  8. <div class="form-group" ng-show="edit5" ng-hide="false">
  9. <label class="col-sm-2 control-label">
  10. First Name:</label>
  11. <div class="col-sm-10">
  12. <input type="text" id="fname" name="fName" ng-model="newuser.fName" placeholder="First Name" />
  13. </div>
  14. </div>
  15. <div class="form-group" ng-show="edit5" ng-hide="false">
  16. <label class="col-sm-2 control-label">
  17. Last Name:</label>
  18. <div class="col-sm-10">
  19. <input type="text" id="lname" name="lname" ng-model="newuser.lName" placeholder="Last Name" />
  20. </div>
  21. </div>
  22. <div class="form-group" ng-show="edit5" ng-hide="false">
  23. <label class="col-sm-2 control-label">
  24. Email Id:</label>
  25. <div class="col-sm-10">
  26. <input type="text" id="email" name="email" ng-model="newuser.email" placeholder="Email ID" />
  27. </div>
  28. </div>
  29. <div class="form-group" ng-show="edit5" ng-hide="false">
  30. <label class="col-sm-2 control-label">
  31. Phone No:</label>
  32. <div class="col-sm-10">
  33. <input type="text" id="numb" class="num" name="num" ng-model="newuser.number" placeholder="Enter Phone NO" />
  34. </div>
  35. </div>
  36. <div class="form-group">
  37. <label class="col-sm-2 control-label">
  38. Birth Date:</label>
  39. <div class="col-sm-2">
  40. <p class="input-group">
  41. <input type="text" name="bday" id="bday" class="form-control" ng-focus="open($event)" ng-blur="out()" datepicker-popup="{{format}}" ng-model="newuser.bdate" is-open="opened" readonly="readonly" />
  42. <span class="input-group-btn">
  43. <button type="button" class="btn btn-default" ng-click="open($event)">
  44. <i class="glyphicon glyphicon-calendar"></i>
  45. </button>
  46. </span>
  47. </p>
  48. </div>
  49. </div>
  50. <div class="form-group" ng-show="edit7" ng-hide="false">
  51. <label class="col-sm-2 control-label">
  52. Image:</label>
  53. <div class="col-sm-15">
  54. <input type="file" file-model="myFile" id="myFile" class="btn btn-primary"/>
  55. <button ng-click="uploadFile()" class="btn btn-primary">
  56. <span class="glyphicon glyphicon-upload"> Upload File</span>
  57. </button>
  58. <br />
  59. </div>
  60. </div>
  61. <div class="col-sm-10" ng-show="remove" ng-hide="true" style="margin-left: 170px" >
  62. <img id="getimg" height="100px" width="100px"/>
  63. <button class="btn btn-danger" ng-click="removefile()" ng-show="remove1" ng-hide="false">
  64. <span
  65. class="glyphicon glyphicon-remove"></span>Remove
  66. </button>
  67. </div>
  68. <div class="form-group">
  69. <input type="text" id="hid" name="hid" ng-model="newuser.hid" ng-hide="true"/>
  70. </div>
  71. <hr />
  72. <button class="btn btn-primary" ng-click="saveUser()">
  73. <span class="glyphicon glyphicon-save"></span>Save Data
  74. </button>
  75. <button id="cbtn" class="btn btn-danger" ng-click="cancel()">
  76. <span class="glyphicon glyphicon-cancel"></span>Cancel
  77. </button>
  78. </div>


Save Button Code
  1. $scope.saveUser = function() {
  2. var a = $("#hid").val();
  3. $.ajax({
  4. type: "POST",
  5. url: "localstorage2.aspx/SaveUser",
  6. contentType: "application/json; charset=utf-8",
  7. data: JSON.stringify({
  8. id: $scope.id,
  9. fName: $scope.fName,
  10. lName: $scope.lName,
  11. email: $scope.email,
  12. number: $scope.number,
  13. hid: $scope.hid = a
  14. }),
  15. success: function(data) {
  16. strErrorMsg = "";
  17. notEmpty(document.getElementById('fname'), '-Enter your first name.');
  18. notEmpty(document.getElementById('lname'), '-Enter your last name.');
  19. notEmpty(document.getElementById('email'), '-Enter your Email ID.');
  20. notEmpty(document.getElementById('numb'), '-Enter your Phone NO.');
  21. notEmpty(document.getElementById('bday'), '-Enter your birth date.');
  22. validateEmail(document.getElementById('email'), '-Enter Valid Email');
  23. ValidMno(document.getElementById('numb'), '-Enter Valid Phone No');
  24. if (strErrorMsg == '') {
  25. var data = localStorage.getItem('iid');
  26. studa = JSON.parse(data);
  27. if ($scope.id == 0) {
  28. $scope.id = aid++;
  29. $scope.users.push({
  30. id: $scope.id,
  31. fName: $scope.fName,
  32. lName: $scope.lName,
  33. email: $scope.email,
  34. number: $scope.number,
  35. hid: $scope.hid = a
  36. });
  37. $("#msgLab").text("Record Save successfully");
  38. localStorage.setItem('iid', angular.toJson($scope.id));
  39. } else {
  40. for (i in $scope.users) {
  41. if ($scope.users[i].id == $scope.id) {
  42. $scope.users[i] = ({
  43. id: $scope.id,
  44. fName: $scope.fName,
  45. lName: $scope.lName,
  46. email: $scope.email,
  47. number: $scope.number,
  48. hid: $scope.hid
  49. });
  50. $scope.users[i].hid = a;
  51. $("#msgLab").text("Record Edit successfully");
  52. }
  53. }
  54. }
  55. localStorage.setItem('stu', angular.toJson($scope.users));
  56. $scope.totalItems = $scope.users.length;
  57. $scope.itemsPerPage = 3
  58. $scope.currentPage = 1;
  59. $scope.maxSize = 5;
  60. $scope.bigTotalItems = 175;
  61. $scope.bigCurrentPage = 1;
  62. $scope.pageCount = function() {
  63. return Math.ceil($scope.Friends.length / $scope.itemsPerPage);
  64. };
  65. $scope.edit2 = false;
  66. $scope.edit3 = true;
  67. $scope.$apply();
  68. }
  69. $window.alert(' Errors \n' + strErrorMsg);
  70. },
  71. error: function() {
  72. alert("error");
  73. }
  74. });
  75. };

Cancel button Code

  1. $scope.cancel = function ()
  2. {
  3. $scope.edit2 = false;
  4. $scope.edit3 = true;
  5. };

Delete button code

  1. $scope.del = function(id)
  2. {
  3. var deleteUser = $window.confirm('Are you sure you want to Record delete?');
  4. if (deleteUser) {
  5. $window.alert('One Record Delete');
  6. for (i in $scope.users) {
  7. if ($scope.users[i].id == id)
  8. {
  9. if ($scope.users[i].hid != "noimage.jpg")
  10. {
  11. $.ajax({
  12. type: "POST",
  13. url: "localstorage2.aspx/DeleteImage",
  14. contentType: "application/json; charset=utf-8",
  15. data: JSON.stringify({
  16. hid: $scope.users[i].hid
  17. }),
  18. success: function(data) {
  19. alert("succc");
  20. },
  21. error: function() {
  22. //alert("error");
  23. }
  24. });
  25. }
  26. $scope.users.splice(i, 1);
  27. $scope.newuser = {};
  28. $("#msgLab").text("Record Delete successfully");
  29. localStorage.setItem('stu', angular.toJson($scope.users));
  30. //localStorage.setItem('iid', angular.toJson($scope.newuser.id));
  31. }
  32. }
  33. }
  34. };


Edit Button Code
  1. $scope.edit = function(id) {
  2. for (i in $scope.users) {
  3. if ($scope.users[i].id == id) {
  4. if ($scope.users[i].hid == "noimage.jpg") {
  5. $scope.remove1 = false;
  6. } else {
  7. $scope.remove1 = true;
  8. }
  9. ({
  10. id: $scope.id,
  11. fName: $scope.fName,
  12. lName: $scope.lName,
  13. email: $scope.email,
  14. number: $scope.number,
  15. hid: $scope.hid
  16. }) = angular.copy($scope.users[i]);
  17. $("#getimg").attr('src', 'upload/' + $scope.users[i].hid);
  18. $scope.edit2 = true;
  19. $scope.edit3 = false;
  20. $scope.edit5 = true;
  21. $scope.edit1 = false;
  22. $scope.edit11 = true;
  23. $(myFile).val('');
  24. $("#msgLab").text("");
  25. $scope.remove = true;
  26. }
  27. }
  28. };




Remove Image at Edit time remove code
  1. $scope.removefile = function () {
  2. var Removeimg = $window.confirm('Are you sure you want to Remove The Image?');
  3. if (Removeimg) {
  4. $("#hid").val("noimage.jpg");
  5. $("#getimg").attr('src', 'upload/noimage.jpg');
  6. if ($("#hid").val() == "noimage.jpg") {
  7. $scope.remove1 = false;
  8. } else {
  9. $scope.remove1 = true;
  10. }
  11. }
  12. };
Create a New User Code
  1. $scope.editUser = function()
  2. {
  3. $scope.fName = "";
  4. $scope.lName = "";
  5. $scope.email = "";
  6. $scope.number = "";
  7. $scope.edit1 = true;
  8. $scope.edit11 = false;
  9. $scope.edit2 = true;
  10. $scope.edit3 = false;
  11. $scope.edit5 = true;
  12. $scope.edit6 = true;
  13. $(myFile).val('');
  14. $("#hid").val("noimage.jpg");
  15. $("#msgLab").text("");
  16. $scope.remove = false;
  17. $scope.id = 0;
  18. };

File Upload code

  1. $scope.uploadFile = function ()
  2. {
  3. var fileval = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
  4. if ($(myFile).val() == "") {
  5. alert("Select a file");
  6. }
  7. else if ($.inArray($(myFile).val().split('.').pop().toLowerCase(), fileval) == -1) {
  8. alert("Select a image file");
  9. $(myFile).val('');
  10. $("#hid").val("noimage.jpg");
  11. }
  12. else
  13. {
  14. var file = $scope.myFile;
  15. var uploadUrl = "Image.aspx";
  16. fileUpload.uploadFileToUrl(file, uploadUrl);
  17. $scope.myFile = "";
  18. $scope.remove = true;
  19. $scope.remove1 = true;
  20. var reader = new FileReader();
  21. reader.onload = function (e) {
  22. scope.image = e.target.result;
  23. scope.$apply();
  24. }
  25. }
  26. elem.on('change', function () {
  27. reader.readAsDataURL(elem[0].files[0]);
  28. });
  29. };
  30. localstorage2.aspx Code For Delete a File From Folder
  31. <Services.WebMethod()>
  32. Public Shared Function DeleteImage(ByVal hid As String) As String
  33. If System.IO.File.Exists("D:\manish\Localstor\upload\" & hid) Then
  34. System.IO.File.Delete("D:\manish\Localstor\upload\" & hid)
  35. Else
  36. End If
  37. End Function
Image.aspx Code For Upload Fie
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2. Response.Clear()
  3. Dim fileid As String = System.Guid.NewGuid.ToString()
  4. ' Dim fname As String = Context.Request.Files.Get(0).FileName()
  5. Context.Request.Files.Get(0).SaveAs("D:\manish\Localstor\upload\" & fileid & ".jpg")
  6. Response.Write(fileid)
  7. Response.End()
  8. End Sub