/// <summary> /// 主动给设备下发信息 /// </summary> /// <returns></returns> private static enumErrorCode CommunicateWithClient(int machineId, byte[] content, int userId, Dictionary <int, bool> downStatus, Dictionary <int, enumErrorCode> downResult) { enumErrorCode sendResult = enumErrorCode.HandlerSuccess; byte[] buffReceive = new byte[BUFFER_SIZE]; if (!netConnection.ContainsKey(machineId)) { db.RecordErrorInfo(enumSystemErrorCode.TcpSenderException, machineId.ToString(), content, userId); return(enumErrorCode.DeviceNotWork); } NetworkStream ns = netConnection[machineId]; try { ns.Write(content, 0, content.Length); if (downStatus.Keys.Contains(machineId)) { downStatus[machineId] = true; } else { downStatus.Add(machineId, true); } sendResult = waittingSendForResp(machineId, downStatus, downResult); } catch (Exception ex) { db.RecordErrorInfo(enumSystemErrorCode.TcpSenderException, ex, machineId.ToString(), content, userId); sendResult = enumErrorCode.DeviceCommunicateError; } return(sendResult); }
// // GET: /Order/Details/5 public ActionResult Detail(int id, enumErrorCode error = enumErrorCode.NONE) { Orders order = null; using (var t = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted })) { order = db.Orders.Find(id); if (order == null) { return(HttpNotFound()); } int userId = Convert.ToInt32(Session["UserID"]); if (!roomControl.CheckUserInRoom(userId, order.RoomId)) { return(RedirectToAction("Login", "Account")); } } ScheduleOrder tempSchedule = new ScheduleOrder(); tempSchedule.GetOrderMaterial(order.MaterialInfo); string[] materialArray = tempSchedule.MaterialList.Values.ToArray(); ViewData["materials"] = materialArray; ViewData["error"] = Constants.GetErrorString(error); return(View(order)); }
public static void DownScheduleHandler() { ServiceStack.Redis.IRedisClient client = GlobalVariable.RedisClient; while (true) { try { int count = client.GetListCount(GlobalVariable.PAGE_SEND_CONTENT); for (int i = 0; i < count; i++) { string strUserKey = client.DequeueItemFromList(GlobalVariable.PAGE_SEND_CONTENT); int machineId = client.Get <int>(GlobalVariable.PRE_DOWN_INFO_MACHINE + strUserKey); byte[] buff = client.Get <byte[]>(GlobalVariable.PRE_DOWN_INFO + strUserKey); string strUser = strUserKey.Substring(0, strUserKey.LastIndexOf('-')); int intUser = int.Parse(strUser); enumErrorCode result = CommunicateWithClient(machineId, buff, intUser); if (result != enumErrorCode.HandlerSuccess) { int intResult = (int)result; client.Set <int>(GlobalVariable.PRE_RESP_DOWN_INFO + strUserKey, intResult); } } } catch (Exception ex) { db.InsertErrorInfo(enumSystemErrorCode.TcpSenderException, ex, "outside", null); } Thread.Sleep(2000); } }
public ActionResult Assign(int id = 0) { Schedules schedules = null; int userId = Convert.ToInt32(Session["UserID"]); using (var t = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted })) { schedules = db.Schedules.Find(id); if (schedules == null) { return(HttpNotFound()); } if (!roomControl.CheckUserInRoom(userId, schedules.RoomId)) { return(RedirectToAction("Login", "Account")); } } db.Schedules.Attach(schedules); schedules.DetailInfo = schedules.DetailInfo == null ? string.Empty : schedules.DetailInfo; schedules.NoticeInfo = schedules.NoticeInfo == null ? string.Empty : schedules.NoticeInfo; byte[] buff = null; App_Start.Coder.EncodeSchedule(schedules, out buff); enumErrorCode result = this.SendScheduleHandler(schedules.MachineId, buff, userId, PRE_INFO_TYPE_CREATE); if (result == enumErrorCode.HandlerSuccess) { schedules.Status = enumStatus.Assigned; db.SaveChanges(); } return(RedirectToAction("Details", new { id = id, error = result })); }
public ActionResult Index(enumErrorCode error = enumErrorCode.NONE) { ViewData["error"] = Constants.GetErrorString(error); var itemList = from item in db.StaffInfo where item.Status != enumStaffStatus.Deleted orderby item.Status select item; return(View(itemList)); }
private enumErrorCode SendScheduleHandler(int machineId, byte[] buff, int userId, string infoType) { string strUserKey = string.Format("{0}-{1}", userId, DateTime.Now.ToString("yyyyMMddHHmmssFFF")); client.EnqueueItemOnList(PAGE_SEND_CONTENT, strUserKey); client.Set <int>(PRE_DOWN_INFO_MACHINE + strUserKey, machineId); client.Set(PRE_DOWN_INFO + strUserKey, buff); client.Set <string>(infoType + machineId.ToString(), strUserKey); enumErrorCode result = App_Start.TcpProtocolClient.WaittingSendForResp(strUserKey); client.Remove(PRE_DOWN_INFO_MACHINE + strUserKey); client.Remove(PRE_DOWN_INFO + strUserKey); client.Remove(infoType + machineId.ToString()); return(result); }
public ActionResult DeleteConfirmed(int id) { Schedules schedules = null; int userId = Convert.ToInt32(Session["UserID"]); using (var t = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted })) { schedules = db.Schedules.Find(id); //db.Schedules.Remove(schedules); if (!roomControl.CheckUserInRoom(userId, schedules.RoomId)) { return(RedirectToAction("Login", "Account")); } } enumErrorCode result = enumErrorCode.HandlerSuccess; if (schedules.Status == enumStatus.Assigned || schedules.Status == enumStatus.Working) { byte[] buff = null; App_Start.Coder.EncodeScheHandler(schedules, enumCommandType.DOWN_SHEDULE_CLOSE_SEND, out buff); result = this.SendScheduleHandler(schedules.MachineId, buff, userId, PRE_INFO_TYPE_CLOSE); } if (result == enumErrorCode.HandlerSuccess) { db.Schedules.Attach(schedules); var tempEntity = db.Entry(schedules); schedules.Status = enumStatus.Closed; schedules.LastUpdatePersonID = userId; schedules.LastUpdatePersonName = User.Identity.Name; schedules.DateLastUpdate = DateTime.Now; Orders orderInfo = db.Orders.Find(schedules.OrderId); orderInfo.ProductFreeCount += (schedules.ProductCount - schedules.FinishCount); db.Entry(orderInfo).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Delete", new { id = id, error = result })); }
public ActionResult UploadStaffInfo(HttpPostedFileBase excelFileName) { if (excelFileName.ContentLength <= 0) { return(RedirectToAction("Index")); } string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetFileName(excelFileName.FileName); string extName = Path.GetExtension(excelFileName.FileName); if (extName != ".xlsx") { return(RedirectToAction("Index", new { error = enumErrorCode.FileOnlyExcel })); } string serverPath = Path.Combine(Server.MapPath("~/Uploads"), fileName); excelFileName.SaveAs(serverPath); List <StaffInfo> staffList = new List <StaffInfo>(); enumErrorCode result = Excel.CheckAndReadStaffInfo(serverPath, staffList); if (result == enumErrorCode.HandlerSuccess) { try { foreach (StaffInfo staff in staffList) { FactoryRoom tempRoom = db.FactoryRoom.FirstOrDefault(item => item.RoomNumber == staff.DeptNumber); staff.DeptId = tempRoom.RoomID; staff.DeptName = tempRoom.RoomName; db.StaffInfo.Add(staff); //同步管理账户 WebSecurity.CreateUserAndAccount(staff.Number, staff.Phone); } db.SaveChanges(); } catch { result = enumErrorCode.ExcelContentError; } } return(RedirectToAction("Index", new { error = result })); }
public ActionResult Discard(int id = 0, enumErrorCode error = enumErrorCode.NONE) { using (var t = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted })) { Schedules schedules = db.Schedules.Find(id); if (schedules == null) { return(HttpNotFound()); } int userId = Convert.ToInt32(Session["UserID"]); if (!roomControl.CheckUserInRoom(userId, schedules.RoomId)) { return(RedirectToAction("Login", "Account")); } ViewData["error"] = Constants.GetErrorString(error); return(View(schedules)); } }
private static enumErrorCode CommunicateWithClient(int machineId, byte[] content, int userId) { enumErrorCode sendResult = enumErrorCode.HandlerSuccess; byte[] buffReceive = new byte[BUFFER_SIZE]; if (!netConnection.ContainsKey(machineId)) { //db.InsertErrorInfo(enumSystemErrorCode.TcpSenderException, null, machineId.ToString(), content); return(enumErrorCode.DeviceNotWork); } NetworkStream ns = netConnection[machineId]; try { ns.Write(content, 0, content.Length); } catch (Exception ex) { db.InsertErrorInfo(enumSystemErrorCode.TcpSenderException, ex, machineId.ToString(), content); sendResult = enumErrorCode.DeviceCommunicateError; } return(sendResult); }
public static string GetErrorString(enumErrorCode code) { return(errorKeyValue[code]); }