public IHttpActionResult TaoThanhMenu([FromBody] ThongTinChamCong obj) { //Employee emp = obj._token; if (obj != null && obj.ChuoiToken != null && obj.ChuoiToken.ToString() != "") { if (ValidateCurrentToken(obj.ChuoiToken.ToString()) == true) { string RowID = GetClaim(obj.ChuoiToken.ToString(), "RowID"); Toolkits t = new Toolkits(); var newMenu = t.Select_All_Menu2_Huu_2(Int32.Parse(RowID)); return(Ok(newMenu)); } else { return(NotFound()); } } else { return(NotFound()); } }
public WHRequestGridRowModel(WarehouseRequest Request, string UserName, string ApprovalUser) { cell = new string[7]; cell[0] = Request.WarehouseRequestID.ToString(); cell[1] = Request.RequestNumber; cell[2] = UserName; cell[3] = Request.CreateDate.ToString("yyyy-MM-dd HH:mm"); cell[4] = ApprovalUser; cell[5] = Toolkits.CheckZero(Request.ApprovalDate)?"-": Request.ApprovalDate.ToString("yyyy-MM-dd HH:mm"); cell[6] = Enum.GetName(typeof(WarehouseRequestStatus), Request.State); }
public void SetUserCookie(string UserName) { HttpContext context = HttpContext.Current; string fullName = Toolkits.GetLogonName(UserName); string[] _info = UserName.Split('\\'); if (_info[1] == "DefaultAppPool" || string.IsNullOrEmpty(UserName)) { return; } if (context.Request.Cookies["User"] == null) { DataTable dt; try { dt = _userRepository.Get_UserIngoDataA(fullName); } catch (Exception ex) { dt = null; } if (dt != null) { HttpCookie _cookie = new HttpCookie("User"); if (dt.Rows.Count > 0) { _cookie.Values.Add("UserID", dt.Rows[0]["UserID"].ToString()); _cookie.Values.Add("UserCode", HttpUtility.UrlEncode(dt.Rows[0]["UserCode"].ToString(), Encoding.GetEncoding("UTF-8"))); _cookie.Values.Add("FullName", HttpUtility.UrlEncode(dt.Rows[0]["FullName"].ToString(), Encoding.GetEncoding("UTF-8"))); _cookie.Values.Add("Department", dt.Rows[0]["DepartmentID"].ToString()); _cookie.Values.Add("DepartmentName", HttpUtility.UrlEncode(dt.Rows[0]["DepartmenName"].ToString(), Encoding.GetEncoding("UTF-8"))); _cookie.Values.Add("Position", dt.Rows[0]["PositionID"].ToString()); _cookie.Values.Add("PositionName", HttpUtility.UrlEncode(dt.Rows[0]["PositionName"].ToString(), Encoding.GetEncoding("UTF-8"))); context.Response.Cookies.Add(_cookie); } else { throw new HttpException(401, string.Format("在系统中没有找到 {0} 的信息,请与系统管理员联系", _info[1] + "---" + UserName)); //context.Response.Redirect("/User/NoRegister?UserName="******"---" + UserName); } } else { throw new HttpException(401, string.Format("在系统中没有找到 {0} 的信息,请与系统管理员联系", _info[1] + "---" + UserName)); //context.Response.Redirect("/User/NoRegister?UserName="******"---" + UserName); } } }
public void OnException(ExceptionContext filterContext) { filterContext.ExceptionHandled = true; var ex = filterContext.Exception; string controller = filterContext.RouteData.Values["controller"].ToString(); string action = filterContext.RouteData.Values["action"].ToString(); #region 日志记录 string logPath = filterContext.HttpContext.Server.MapPath("~/Log/") + "ErrorHandle_" + DateTime.Now.ToString("yyMMddHH") + ".txt"; string _logStr = string.Format("控制器:{0}\r\n处理函数:{1}\r\n异常信息:{2}", controller, action, ex.ToString()); Toolkits.WriteLog(logPath, _logStr); #endregion throw new HttpException(500, _logStr); //filterContext.Result = new RedirectResult(string.Format("/Home/ErrorHandler?controllername={0}&actionname={1}&exMessage={2}", controller, action, HttpUtility.UrlEncode(ex.Message))); }
public static byte[] GetPO(string server, int PurchaseOrderID) { HttpWebRequest _request = null; HttpWebResponse _response = null; string acc = ConfigurationManager.AppSettings["ServerAcc"].ToString(); string pwd = ConfigurationManager.AppSettings["ServerPwd"].ToString(); NetworkCredential _cred = new NetworkCredential(acc, pwd); //NetworkCredential _cred = CredentialCache.DefaultNetworkCredentials; //Uri uri = new Uri(server); //ICredentials credentials = CredentialCache.DefaultNetworkCredentials; //NetworkCredential _cred = credentials.GetCredential(uri, "Basic"); string content = ""; try { _request = (HttpWebRequest)WebRequest.Create(server + "/Purchase/PRForm?PurchaseOrderID=" + PurchaseOrderID); _request.PreAuthenticate = true; _request.Credentials = _cred; _request.Timeout = 10000; _request.AllowAutoRedirect = false; _response = (HttpWebResponse)_request.GetResponse(); if (_response.ToString() != "") { Stream streamReceive = _response.GetResponseStream(); Encoding encoding = Encoding.GetEncoding("UTF-8");//乱码处理 StreamReader streamReader = new StreamReader(streamReceive, encoding); content = streamReader.ReadToEnd(); } } catch (Exception ex) { string WebLogPath = HttpContext.Current.Server.MapPath("~/Log/"); if (!Directory.Exists(WebLogPath)) { DirectoryInfo dir = new DirectoryInfo(WebLogPath); dir.Create(); } string logPath = WebLogPath + "PO(PDF)生成_" + PurchaseOrderID.ToString() + "_" + DateTime.Now.ToString("yyMMddHHmm") + ".txt"; Toolkits.WriteLog(logPath, "用户名:" + _cred.UserName + ";密码:" + _cred.Password + "\r\n" + ex.Message.ToString()); content = ""; } return(Html2PDF(content, "PO")); }
/// <summary> /// /// </summary> /// <param name="model">工时记录</param> /// <param name="mName">机器名称</param> /// <param name="tyName">任务类型名称</param> public WHReportRowModelA(TaskHour model, string taskName, string mName, string tyName) { cell = new string[14]; cell[0] = model.TaskHourID.ToString(); cell[1] = model.TaskID.ToString(); cell[2] = taskName; cell[3] = model.MoldNumber; cell[4] = model.MachineCode; cell[5] = mName; cell[6] = model.Operater; //0正常开始 1暂停后重启 -1取消/删除任务 2 外发 3返工 string rType = string.Empty; switch (model.RecordType) { case 0: rType = "正常开始"; break; case 1: rType = "暂停重启"; break; case -1: rType = "任务取消"; break; case 2: rType = "外发工时"; break; case 3: rType = "返工工时"; break; } cell[7] = rType; cell[8] = model.TaskType.ToString(); cell[9] = tyName; cell[10] = model.SemiTaskFlag; cell[11] = model.Time.ToString(); cell[12] = model.StartTime.ToString("yyyy-MM-dd HH:mm"); cell[13] = Toolkits.CheckZero(model.FinishTime)?"-" : model.FinishTime.ToString("yyyy-MM-dd HH:mm"); }
public void LogRecord(string filename, string content) { string logPath = Server.MapPath("~/Log/") + filename + "_" + DateTime.Now.ToString("yyMMddHH") + ".txt"; Toolkits.WriteLog(logPath, content); }
/// <summary> /// Excel表格导出 /// </summary> /// <typeparam name="T">实体类</typeparam> /// <param name="_excelPath">excel模板路径</param> /// <param name="_headList">excel列头</param> /// <param name="_excelContent">excel内容</param> /// <param name="sheetName">excel sheet名</param> /// <param name="isColumnWritten">是否导入列名</param> /// <returns></returns> public MemoryStream ExportExcelStream <T>(List <T> _excelContent, string _excelPath, string sheetName, List <string> _headList, bool isColumnWritten) { HttpContext _httpcontext = HttpContext.Current; string TempletFileName = _httpcontext.Server.MapPath(_excelPath); int i = 0; int j = 0; int count = 0; ISheet sheet = null; //IWorkbook workbook = null; int _count; Type type = typeof(T); PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); var propByOrder = Toolkits.GetPropsArrayByOrder(props); if (_headList != null) { _count = _headList.Count; } else { _count = propByOrder.Count(); } using (FileStream fs = System.IO.File.Open(TempletFileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)) { //把xls文件读入workbook变量里,之后就可以关闭了 if (TempletFileName.IndexOf(".xlsx") > 0) // 2007版本 { workbook = new XSSFWorkbook(fs); } else if (TempletFileName.IndexOf(".xls") > 0) // 2003版本 { workbook = new HSSFWorkbook(fs); } //workbook = new XSSFWorkbook(fs); fs.Close(); } try { //ExcelOperations eo = new ExcelOperations(); if (workbook != null) { //sheet = workbook.CreateSheet(sheetName); sheet = workbook.GetSheetAt(0); } else { return(null); } if (isColumnWritten == true) //写入列名 { IRow row = sheet.GetRow(0); if (_headList != null) { for (j = 0; j < _count; ++j) { ICell _cell = row.CreateCell(j); _cell.SetCellValue(_headList[j].ToString()); //row.GetCell(j).SetCellValue(_headList[j]); } } else { for (j = 0; j < _count; ++j) { string name = propByOrder[j].Name; ICell _cell = row.CreateCell(j); _cell.SetCellValue(name.ToString()); //row.GetCell(j).SetCellValue(name); } } count = 1; } else { count = 0; } for (i = 0; i < _excelContent.Count; ++i) { IRow _formatRow; if (count % 2 == 1) { //_formatRow = sheet.GetRow(1); } else { //_formatRow = sheet.GetRow(2); } //eo.InsertRow(sheet, 2+count, 1, _formatRow); IRow row = sheet.CreateRow(count); T _t = _excelContent[i]; for (j = 0; j < _count; ++j) { string name = propByOrder[j].Name; PropertyInfo p = typeof(T).GetProperty(name); string value = p.GetValue(_t, null) == null ? "" : p.GetValue(_t, null).ToString(); row.CreateCell(j).SetCellValue(value); } ++count; } MemoryStream _ms = new MemoryStream(); workbook.Write(_ms); //写入到excel _ms.Flush(); _ms.Position = 0; return(_ms); } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); return(null); } }