public ShowEmployeeMonitoring GetEmployeeByEmpId1(string id, int foodItemId) { try { string date = DateTime.Now.Date.ToString(); Query = @"SELECT e.Id, e.EmpId, e.Name, e.JoinDate, d.Name as DivisionName, p.Name as DepartmentName, g.Name as DesignationName, e.Proximity, e.Status, e.EmailId, e.EmployeePhotograph, t.Status as FoodStatus FROM Employee e INNER JOIN Division d on d.Id = e.DivisionId INNER JOIN Department p on p.Id = e.DepartmentId INNER JOIN Designation g on g.Id = e.DesignationId INNER JOIN EmployeeCafeteriaTransaction t on t.EmpId = e.EmpId Where e.Proximity = '" + id + "' and t.FoodItemCostId = '" + foodItemId + "' and t.CheckDate = '" + date + "'"; Command.CommandText = Query; Command.Connection = Connection; Connection.Open(); Reader = Command.ExecuteReader(); ShowEmployeeMonitoring employees = new ShowEmployeeMonitoring(); int number = 1; if (Reader.HasRows) { while (Reader.Read()) { ShowEmployeeMonitoring employee = new ShowEmployeeMonitoring(); employee.Id = Convert.ToInt32(Reader["Id"]); employee.EmpId = Reader["EmpId"].ToString(); employee.Name = Reader["Name"].ToString(); employee.JoinDate = (DateTime)Reader["JoinDate"]; employee.Division = Reader["DivisionName"].ToString(); employee.Department = Reader["DepartmentName"].ToString(); employee.Designation = Reader["DesignationName"].ToString(); employee.CardNumber = Reader["Proximity"].ToString(); // employee.Status = Convert.ToBoolean(Reader["Status"].ToString()); employee.EmailId = Reader["EmailId"].ToString(); employee.Statuss = Reader["FoodStatus"].ToString(); employee.UploadFile = Reader["EmployeePhotograph"].ToString(); employee.Number = number; employees = employee; number++; } Reader.Close(); } return(employees); } catch (Exception exception) { return(null); } finally { Connection.Close(); } }
public bool GetEmployeeByEmpId123(string id, int foodItemId, string date) { try { // string date = DateTime.Now.Date.ToString(); Query = @"SELECT e.Id, e.EmpId, e.Name, e.JoinDate, d.Name as DivisionName, p.Name as DepartmentName, g.Name as DesignationName, e.Proximity, e.Status, e.EmailId, e.EmployeePhotograph FROM Employee e INNER JOIN Division d on d.Id = e.DivisionId INNER JOIN Department p on p.Id = e.DepartmentId INNER JOIN Designation g on g.Id = e.DesignationId INNER JOIN EmployeeCafeteriaTransaction t on t.EmpId = e.EmpId Where e.Proximity = '" + id + "' and t.FoodItemCostId = '" + foodItemId + "' and t.CheckDate = '" + date + "'"; Command.CommandText = Query; Command.Connection = Connection; Connection.Open(); Reader = Command.ExecuteReader(); ShowEmployeeMonitoring employees = new ShowEmployeeMonitoring(); bool status = false; if (Reader.HasRows) { while (Reader.Read()) { status = true; } Reader.Close(); } return(status); } catch (Exception exception) { return(false); } finally { Connection.Close(); } }
public ActionResult Test1(int foodItemId) { if (Session["UserRoleId"] == null) { return(RedirectToAction("Login", "Login")); } try { string presentTime = DateTime.Now.TimeOfDay.ToString(); bool IsFoodItemTimeExist = _employeeManager.IsFoodItemTimeExist(presentTime, foodItemId); // List<ShowEmployeeMonitoring> employees1 = new List<ShowEmployeeMonitoring>(); //Queue employees1 = new Queue(); Stack employees1 = new Stack(); List <ShowEmployeeMonitoring> employees420 = new List <ShowEmployeeMonitoring>(); if (IsFoodItemTimeExist == true) { EmployeeMonitoring employ = null; string year = DateTime.Now.Year.ToString(); string month = DateTime.Now.Month.ToString(); string day = DateTime.Now.Day.ToString(); if (month.Length == 1) { month = "0" + month; } if (day.Length == 1) { day = "0" + day; } string textFile = year + month + day + ".txt"; //test 1**************** //FileStream fileStream = new FileStream(@"E:\\ATT_DATA\\" + textFile + "", FileMode.OpenOrCreate, FileAccess.ReadWrite, // FileShare.None); // StreamReader sr = new StreamReader(fileStream); //test 2**************** using (var fs = new FileStream(@"D:\\ATT_DATA\\" + textFile + "", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var sr = new StreamReader(fs, Encoding.Default)) { //Read the first line of text var line = sr.ReadLine(); List <EmployeeMonitoring> employees = new List <EmployeeMonitoring>(); employees.Clear(); //int number = 1; //Continue to read until you reach end of file while (line != null) { int index = line.IndexOf(','); string date = line.Substring(0, index); string year1 = date.Substring(0, 4); string month1 = date.Substring(4, 2); string day1 = date.Substring(6, 2); string dates = year1 + "-" + month1 + "-" + day1; DateTime dates1 = Convert.ToDateTime(dates); if (foodItemId == 9) { dates1 = dates1.AddDays(-1); } int index1 = index + 1; string time1 = line.Substring(index1, 6); int index2 = index + 8; string cardNumber = line.Substring(index2, 8); string hh = time1.Substring(0, 2); string mm = time1.Substring(2, 2); string ss = time1.Substring(4, 2); string time = hh + ":" + mm + ":" + ss; bool employs = false; bool employs1 = false; bool employs2 = false; bool IsFoodItemTimeExist1 = _employeeManager.IsFoodItemTimeExist(time, foodItemId); if (IsFoodItemTimeExist1 == true) { if (cardNumber != "") { employ = _employeeManager.GetEmployeeByEmpId(cardNumber); bool employ12 = _employeeManager.GetEmployeeByEmpId12(cardNumber, foodItemId); if (employ12 == true) { ShowEmployeeMonitoring employ1 = _employeeManager.GetEmployeeByEmpId1(cardNumber, foodItemId); var status = employees420.Find(m => m.EmpId == employ1.EmpId); if (status == null) { employees420.Add(employ1); employees1.Push(employ1); } } else { ShowEmployeeMonitoring employ1 = _employeeManager.GetEmployeeByEmpId2(cardNumber, foodItemId); var status = employees420.Find(m => m.EmpId == employ1.EmpId); if (status == null) { // employ1.Statuss = ""; employ1.Statuss = @"<p style=""color: red""> Not Listed </p>"; employees420.Add(employ1); employees1.Push(employ1); } } } EmployeeCafeteriaTransaction emptransection = new EmployeeCafeteriaTransaction(); emptransection.EmpId = employ.EmpId; emptransection.FoodItemCostId = foodItemId; emptransection.CheckTime = time; emptransection.CheckDate = dates1.ToString(); if (emptransection.EmpId != null) { employs = _employee.IsEmployeeExist0901(emptransection.EmpId, foodItemId, time, dates); employs1 = _employee.IsEmployeeExist09011(emptransection.EmpId, time, dates, foodItemId); employs2 = _employee.IsEmployeeExist090112(emptransection.EmpId, time, dates, foodItemId); if (employs == false) { if (employs1 == false) { if (employs2 == false) { int message = _employee.SaveRecord1(emptransection); } } } employs = _employee.IsEmployeeExist191(emptransection.EmpId, foodItemId, time, dates); employs1 = _employee.IsEmployeeExist101(emptransection.EmpId, time, dates); if (employs == true) { if (employs1 == true) { int message = _employee.ConfirmMeal(emptransection); var message1 = _employeeManager.GetListofuser(emptransection); } } } } //Read the next line line = sr.ReadLine(); } //close the file sr.Close(); } } return(Json(employees1, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(null); } }
public JsonResult Import(HttpPostedFileBase Textfile) { HttpPostedFileBase file = Request.Files[0]; // your file EmployeeMonitoring employ = null; Stack employees1 = new Stack(); string imageUrl = ""; if (file != null) { if (file.ContentType == "text/plain") { var imageType = file.ContentType; if (imageType == "text/plain") { imageUrl = "123" + ".txt"; } file.SaveAs(Server.MapPath("/") + "/UploadFile/" + imageUrl); } } // StreamReader sr = new StreamReader(Server.MapPath("/") + "/UploadFile/" + imageUrl); using (var fs = new FileStream(Server.MapPath(" / ") + "/UploadFile/" + imageUrl, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var sr = new StreamReader(fs, Encoding.Default)) { //Read the first line of text var line = sr.ReadLine(); List <EmployeeMonitoring> employees = new List <EmployeeMonitoring>(); employees.Clear(); //int number = 1; //Continue to read until you reach end of file while (line != null) { int index = line.IndexOf(','); string date = line.Substring(0, index); string year1 = date.Substring(0, 4); string month1 = date.Substring(4, 2); string day1 = date.Substring(6, 2); string dates = year1 + "-" + month1 + "-" + day1; DateTime dates1 = Convert.ToDateTime(dates); int index1 = index + 1; string time1 = line.Substring(index1, 6); int index2 = index + 8; string cardNumber = line.Substring(index2, 8); string hh = time1.Substring(0, 2); string mm = time1.Substring(2, 2); string ss = time1.Substring(4, 2); string time = hh + ":" + mm + ":" + ss; bool employs = false; bool employs1 = false; int foodItemId = _employeeManager.GetFoodItemCostIdByTime(time); if (foodItemId == 9) { dates1 = dates1.AddDays(-1); } bool IsFoodItemTimeExist1 = _employeeManager.IsFoodItemTimeExist(time, foodItemId); if (IsFoodItemTimeExist1 == true) { if (cardNumber != "") { employ = _employeeManager.GetEmployeeByEmpId(cardNumber); //bool employ12 = _employeeManager.GetEmployeeByEmpId123(cardNumber, foodItemId, dates); //if (employ12 == true) //{ // ShowEmployeeMonitoring employ1 = _employeeManager.GetEmployeeByEmpId1(cardNumber, foodItemId); // // employees1.Add(employ1); // // employees1.Enqueue(employ1); // employees1.Push(employ1); //} } EmployeeCafeteriaTransaction emptransection = new EmployeeCafeteriaTransaction(); emptransection.EmpId = employ.EmpId; emptransection.FoodItemCostId = foodItemId; emptransection.CheckTime = time; emptransection.CheckDate = dates1.ToString(); if (emptransection.EmpId != null) { employs = _employee.IsEmployeeExist(emptransection.EmpId, foodItemId, time, dates); employs1 = _employee.IsEmployeeExist1(emptransection.EmpId, time, dates); if (employs == false) { if (employs1 == false) { int message = _employee.SaveRecord(emptransection); // var message1 = _employeeManager.GetListofuser(emptransection); bool employ12 = _employeeManager.GetEmployeeByEmpId123(cardNumber, foodItemId, dates); if (employ12 == true) { ShowEmployeeMonitoring employ1 = _employeeManager.GetEmployeeByEmpId1235(cardNumber, foodItemId, dates); // employees1.Add(employ1); // employees1.Enqueue(employ1); employees1.Push(employ1); } } } } } //Read the next line line = sr.ReadLine(); } //close the file sr.Close(); } //Read the first line of text //var line = sr.ReadLine(); //List<EmployeeMonitoring> employees = new List<EmployeeMonitoring>(); //List<ShowEmployeeMonitoring> employees1 = new List<ShowEmployeeMonitoring>(); //employees.Clear(); ////int number = 1; ////Continue to read until you reach end of file //while (line != null) //{ // int index = line.IndexOf(','); // string date = line.Substring(0, index); // string year = date.Substring(0, 4); // string month = date.Substring(4, 2); // string day = date.Substring(6, 2); // string dates = year + "-" + month + "-" + day; // int index1 = index + 1; // string time1 = line.Substring(index1, 6); // int index2 = index + 8; // string cardNumber = line.Substring(index2, 8); // string hh = time1.Substring(0, 2); // string mm = time1.Substring(2, 2); // string ss = time1.Substring(4,2); // string time = hh + ":" + mm + ":" + ss; // int foodItemId = 0; // bool employs = false; // bool employs1 = false; // if (cardNumber != "") // { // foodItemId = _employeeManager.GetFoodItemCostIdByTime(time); // employ = _employeeManager.GetEmployeeByEmpId(cardNumber); // ShowEmployeeMonitoring employ1 = _employeeManager.GetEmployeeByEmpId1(cardNumber, foodItemId); // employees1.Add(employ1); // //employees1.Add(number); // // number++; // } // EmployeeCafeteriaTransaction emptransection = new EmployeeCafeteriaTransaction(); // emptransection.EmpId = employ.EmpId; // emptransection.FoodItemCostId = foodItemId; // emptransection.CheckTime = time; // emptransection.CheckDate = dates; // employs = _employee.IsEmployeeExist(emptransection.EmpId, foodItemId, time, dates); // employs1 = _employee.IsEmployeeExist1(emptransection.EmpId, time, dates); // if (employs == false) // { // if (employs1 == false) // { // int message = _employee.SaveRecord(emptransection); // var message1 = _employeeManager.GetListofuser(emptransection); // //employees.Add(message1); // //employ.Number = number; // //number++; // } // } // //Read the next line // line = sr.ReadLine(); //} ////close the file //sr.Close(); string fullPath = Request.MapPath("~/UploadFile/" + imageUrl); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } return(Json(employees1, JsonRequestBehavior.AllowGet)); }