private DataTable method_0(string string_0) { DataTable result = null; string commandText = string.Format("Select * FROM {0}", string_0); try { DbConnection connection = this.baseContext.Database.Connection; if (connection.State != ConnectionState.Open) { connection.Open(); } using (DbCommand dbCommand = connection.CreateCommand()) { dbCommand.CommandText = commandText; dbCommand.CommandType = CommandType.Text; using (DbDataReader dbDataReader = dbCommand.ExecuteReader()) { result = dbDataReader.GetSchemaTable(); } } } catch (Exception ex) { LogTextHelper.Error(ex); } return(result); }
/// <summary> /// 初始化模板引擎 /// </summary> protected virtual void InitTemplateEngine() { try { //Velocity.Init(NVELOCITY_PROPERTY); VelocityEngine templateEngine = new VelocityEngine(); templateEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file"); templateEngine.SetProperty(RuntimeConstants.INPUT_ENCODING, "utf-8"); templateEngine.SetProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8"); //如果设置了FILE_RESOURCE_LOADER_PATH属性,那么模板文件的基础路径就是基于这个设置的目录,否则默认当前运行目录 templateEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, AppDomain.CurrentDomain.BaseDirectory); templateEngine.Init(); template = templateEngine.GetTemplate(templateFile); } catch (ResourceNotFoundException re) { string error = string.Format("Cannot find template " + templateFile); LogTextHelper.Error(error); throw new Exception(error, re); } catch (ParseErrorException pee) { string error = string.Format("Syntax error in template " + templateFile + ":" + pee.StackTrace); LogTextHelper.Error(error); throw new Exception(error, pee); } }
public void AddLoginLog(UserInfo info, string systemType, string ip, string macAddr, string note) { if (info != null) { try { LoginLogInfo info2 = new LoginLogInfo { IPAddress = ip, MacAddress = macAddr, LastUpdated = DateTime.Now, Note = note, SystemType_ID = systemType, User_ID = info.ID.ToString(), FullName = info.FullName, LoginName = info.Name, Company_ID = info.Company_ID, CompanyName = info.CompanyName }; BLLFactory <LoginLog> .Instance.Insert(info2); } catch (Exception exception) { LogTextHelper.Error(exception); } } }
public override bool OnApply() { bool result = false; try { LoginParameter parameter = settings.GetSettings <LoginParameter>(); if (parameter != null) { parameter.LoginId = this.txtLoginId.Text; parameter.Password = this.txtPassword.Text; parameter.RememberPassword = this.chkRememberPasssword.Checked; parameter.InternalWcfPort = Convert.ToInt32(this.txtInternalPort.Value); parameter.InternalWcfHost = this.txtInternalHost.Text; parameter.ExternalWcfPort = Convert.ToInt32(this.txtExternalPort.Value); parameter.ExternalWcfHost = this.txtExternalHost.Text; parameter.IsLocalDatabase = this.txtUseLocalType.Checked; parameter.WcfMode = this.txtUseLocalType.Checked?"": this.rdgWCFMode.EditValue.ToString(); settings.SaveSettings <LoginParameter>(parameter); } result = true; } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } return(result); }
/// <summary> /// 记录用户操作日志 /// </summary> /// <param name="info">用户信息</param> /// <param name="systemType">系统类型ID</param> /// <param name="ip">IP地址</param> /// <param name="macAddr">Mac地址</param> /// <param name="note">备注说明</param> public void AddLoginLog(UserInfo info, string systemType, string ip, string macAddr, string note) { if (info == null) { return; } #region 记录用户登录操作 try { LoginLogInfo logInfo = new LoginLogInfo(); logInfo.IPAddress = ip; logInfo.MacAddress = macAddr; logInfo.LastUpdated = DateTime.Now; logInfo.Note = note; logInfo.SystemType_ID = systemType; logInfo.User_ID = info.ID.ToString(); logInfo.FullName = info.FullName; logInfo.LoginName = info.Name; logInfo.Company_ID = info.Company_ID; logInfo.CompanyName = info.CompanyName; BLLFactory <LoginLog> .Instance.Insert(logInfo); } catch (Exception ex) { LogTextHelper.Error(ex); } #endregion }
bool drager_ProcessDragNode(TreeNode dragNode, TreeNode dropNode) { if (dragNode != null && dragNode.Text == "数据字典管理") { return(false); } if (dropNode != null && dropNode.Tag != null) { string dropTypeId = dropNode.Tag.ToString(); string dragTypeId = dragNode.Tag.ToString(); //MessageDxUtil.ShowTips(string.Format("dropTypeId:{0} dragTypeId:{1}", dropTypeId, drageTypeId)); try { DictTypeInfo dragTypeInfo = BLLFactory <DictType> .Instance.FindByID(dragTypeId); if (dragTypeInfo != null) { dragTypeInfo.PID = dropTypeId; BLLFactory <DictType> .Instance.Update(dragTypeInfo, dragTypeInfo.ID); } } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); return(false); } } return(true); }
public override ActionResult Insert(YH_DeviceInfoInfo info) { //检查用户是否有权限,否则抛出MyDenyAccessException异常 base.CheckAuthorized(AuthorizeKey.InsertKey); CommonResult result = new CommonResult(); if (info != null) { try { OnBeforeInsert(info); var exist = baseBLL.IsExistRecord(string.Format("Deviceid='{0}'", info.DeviceId)); if (exist) { result.ErrorMessage = "仪器编号已存在!"; } else { result.Success = baseBLL.Insert(info); } } catch (Exception ex) { LogTextHelper.Error(ex);//错误记录 result.ErrorMessage = ex.Message; } } return(ToJsonContent(result)); }
public override bool OnApply() { bool result = false; try { ReportParameter parameter = settings.GetSettings <ReportParameter>(); if (parameter != null) { int otherType = 2;//2代表其他类型 if (this.radReport.SelectedIndex < otherType) { parameter.CarSendReportFile = this.radReport.Properties.Items[this.radReport.SelectedIndex].Value.ToString(); } else { parameter.CarSendReportFile = this.txtOtherReport.Text; } settings.SaveSettings <ReportParameter>(parameter); } result = true; } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } return(result); }
/// <summary> /// 新增状态下的数据保存 /// </summary> /// <returns></returns> public override bool SaveAddNew() { CardInfo info = tempInfo;//必须使用存在的局部变量,因为部分信息可能被附件使用 SetInfo(info); try { #region 新增数据 //检查是否还有其他相同关键字的记录 bool exist = BLLFactory <Card> .Instance.IsExistKey("CardID", info.CardID); if (exist) { MessageDxUtil.ShowTips("指定的【车卡号】已经存在,不能重复添加,请修改"); return(false); } bool succeed = BLLFactory <Card> .Instance.Insert(info); if (succeed) { //可添加其他关联操作 return(true); } #endregion } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } return(false); }
private void Auth() { #region 获取关键参数 if (string.IsNullOrEmpty(token)) { LogTextHelper.Error(string.Format("CorpToken 配置项没有配置!")); } if (string.IsNullOrEmpty(encodingAESKey)) { LogTextHelper.Error(string.Format("EncodingAESKey 配置项没有配置!")); } if (string.IsNullOrEmpty(corpId)) { LogTextHelper.Error(string.Format("CorpId 配置项没有配置!")); } #endregion string echoString = HttpContext.Current.Request.QueryString["echoStr"]; string signature = HttpContext.Current.Request.QueryString["msg_signature"];//企业号的 msg_signature string timestamp = HttpContext.Current.Request.QueryString["timestamp"]; string nonce = HttpContext.Current.Request.QueryString["nonce"]; string decryptEchoString = ""; if (new CorpBasicApi().CheckSignature(token, signature, timestamp, nonce, corpId, encodingAESKey, echoString, ref decryptEchoString)) { if (!string.IsNullOrEmpty(decryptEchoString)) { HttpContext.Current.Response.Write(decryptEchoString); HttpContext.Current.Response.End(); } } }
public ActionResult ApproveData() { CommonResult result = new CommonResult(); try { var arrFeeID = Request["ArrFeeID"].Split(','); var list = new List <int>(); foreach (var item in arrFeeID) { list.Add(item.ToIntOrZero()); } var sql = "update ArcCalcReading set IntStatus=1 where IntFeeID in ({0}) and IntStatus=0 " .FormatWith(string.Join(",", list)); result.Success = BLLFactory <Core.DALSQL.ArcCalcReading> .Instance.SqlExecute(sql) > 0; if (result.Success == false) { result.ErrorMessage = "审核失败!请检查您的输入是否正确后重试!"; } } catch (Exception ex) { LogTextHelper.Error(ex);//错误记录 result.ErrorMessage = ex.Message; } return(ToJsonContent(result)); }
private void button2_Click(object sender, EventArgs e) { var file = FileDialogHelper.SaveExcel( $"{dateTimePicker1.Value.Date.ToString("yyyyMMdd") + "-" + dateTimePicker2.Value.Date.ToString("yyyyMMdd")}.xlsx"); if (string.IsNullOrEmpty(file)) { return; } //var dt = (dataGridView1.DataSource as DataTable); var dt = DataTableHelper.GetDgvToTable(dataGridView1); try { string error; AsposeExcelTools.DataTableToExcel2(dt, file, out error); if (!string.IsNullOrEmpty(error)) { MessageDxUtil.ShowError($"导出Excel出现错误:{error}"); } else { if (MessageDxUtil.ShowYesNoAndTips("导出成功,是否打开文件?") == DialogResult.Yes) { Process.Start(file); } } } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } }
private void menuDelete_Click(object sender, EventArgs e) { bool sucess = false; string lastError = ""; try { foreach (ListViewItem item in this.listView1.CheckedItems) { if (item != null && item.Tag != null) { string id = item.Tag.ToString(); sucess = BLLFactory <FileUpload> .Instance.Delete(id); } } } catch (Exception ex) { lastError += ex.Message + "\r\n"; LogTextHelper.Error(ex); } MessageDxUtil.ShowTips(sucess ? "操作成功" : "操作失败"); //ProcessDataSaved(this.btnDelete, new EventArgs()); BindData(); }
private void btnDelete_Click(object sender, EventArgs e) { if (this.listView1.CheckedItems.Count == 0) { MessageDxUtil.ShowTips("请勾选删除的文件!"); return; } string lastError = ""; bool sucess = false; foreach (ListViewItem item in this.listView1.CheckedItems) { if (item != null && item.Tag != null) { string id = item.Tag.ToString(); try { sucess = BLLFactory <FileUpload> .Instance.Delete(id); } catch (Exception ex) { lastError += ex.Message + "\r\n"; LogTextHelper.Error(ex); } } } MessageDxUtil.ShowTips(sucess ? "操作成功" : "操作失败"); BindData(); }
/// <summary> /// 编辑状态下的数据保存 /// </summary> /// <returns></returns> public override bool SaveUpdated() { WeightInfo info = BLLFactory <Weight> .Instance.FindByID(ID); if (info != null) { SetInfo(info); try { #region 更新数据 bool succeed = BLLFactory <Weight> .Instance.Update(info, info.ID); if (succeed) { //可添加其他关联操作 return(true); } #endregion } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } } return(false); }
private void btnExportBill_Click(object sender, EventArgs e) { //装备单据数据 DataTable dt = PrepareBillData(); #region 导出数据 try { SpecialDirectories sp = new SpecialDirectories(); string fileName = FileDialogHelper.SaveExcel(string.Format("入库单({0})", DateTime.Now.ToString("yyyy-MM-dd")), sp.Desktop); if (string.IsNullOrEmpty(fileName)) { return; } string outError = ""; AsposeExcelTools.DataTableToExcel2(dt, fileName, out outError); if (!string.IsNullOrEmpty(outError)) { MessageDxUtil.ShowError(outError); LogTextHelper.Error(outError); } else { Process.Start(fileName); } } catch (Exception ex) { MessageDxUtil.ShowError(ex.Message); LogTextHelper.Error(ex); } #endregion }
/// <summary> /// 删除订单及订单明细信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteOrderRelated(string id) { bool result = false; DbTransaction trans = CreateTransaction(); if (trans != null) { SellInfo info = baseDal.FindByID(id, trans); if (info != null) { List <OrderDetailInfo> detailList = BLLFactory <OrderDetail> .Instance.FindByOrderNo(info.OrderNo, trans); foreach (OrderDetailInfo detailInfo in detailList) { BLLFactory <OrderDetail> .Instance.Delete(detailInfo.ID, trans); } //最后删除主表订单数据 baseDal.Delete(id, trans); try { trans.Commit(); result = true; } catch (Exception ex) { trans.Rollback(); LogTextHelper.Error(ex); throw; } } } return(result); }
/// <summary> /// 覆盖基类控制器的异常处理 /// </summary> /// <param name="filterContext"></param> protected override void OnException(ExceptionContext filterContext) { if (filterContext.Exception is MyDenyAccessException) { base.OnException(filterContext); //自定义非授权的异常处理,可记录用户操作 // 当自定义显示错误 mode = On,显示友好错误页面 if (filterContext.HttpContext.IsCustomErrorEnabled) { filterContext.ExceptionHandled = true; this.View("Error").ExecuteResult(this.ControllerContext); Response.StatusCode = (int)HttpStatusCode.Unauthorized; } } else { base.OnException(filterContext); LogTextHelper.Error(filterContext.Exception);//错误记录 // 当自定义显示错误 mode = On,显示友好错误页面 if (filterContext.HttpContext.IsCustomErrorEnabled) { filterContext.ExceptionHandled = true; this.View("Error").ExecuteResult(this.ControllerContext); //Response.StatusCode = (int)HttpStatusCode.BadRequest; } } }
private void menu_ClearData_Click(object sender, EventArgs e) { TreeNode selectedNode = this.treeView1.SelectedNode; if (selectedNode != null && selectedNode.Tag != null) { string typeId = selectedNode.Tag.ToString(); int count = BLLFactory <DictData> .Instance.GetDictByTypeID(typeId).Count; var format = "您确定要删除节点:{0},该节点下面有【{1}】项数据"; format = JsonLanguage.Default.GetString(format); string message = string.Format(format, selectedNode.Text, count); if (MessageDxUtil.ShowYesNoAndWarning(message) == DialogResult.Yes) { try { BLLFactory <DictData> .Instance.DeleteByCondition(string.Format("DictType_ID='{0}'", typeId)); InitTreeView(); BindData(); } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } } } }
/// <summary> /// 测试拨号连接 /// </summary> public void Connect(string RasName) { try { if (OnHandle != null) { OnHandle(string.Format("正在拨号 {0}...", RasName)); } RasDialer dialer = new RasDialer(); dialer.EntryName = RasName; dialer.PhoneNumber = " "; dialer.AllowUseStoredCredentials = true; dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); dialer.Timeout = 1000; dialer.Dial(); Thread.Sleep(100); if (OnHandle != null) { OnHandle(string.Format("拨号完成")); } } catch (Exception ex) { LogTextHelper.WriteLine(ex.ToString()); throw; } }
protected override CommonResult Update(string id, YH_DeviceInfoInfo info) { CommonResult result = new CommonResult(); try { OnBeforeUpdate(info); //非当前记录不能重复设备ID var exist = baseBLL.IsExistRecord(string.Format("Deviceid='{0}' AND ID <> '{1}'", info.DeviceId, info.ID)); if (exist) { result.ErrorMessage = "仪器编号已存在!"; } else { result.Success = baseBLL.Update(info, id); } } catch (Exception ex) { LogTextHelper.Error(ex);//错误记录 result.ErrorMessage = ex.Message; } return(result); }
public virtual List <T> Find(string condition, string orderBy, IDbDataParameter[] paramList, DbTransaction trans = null) { if (HasInjectionData(condition)) { LogTextHelper.Error(string.Format("检测出SQL注入的恶意数据, {0}", condition)); throw new Exception("检测出SQL注入的恶意数据"); } string sql = string.Format("Select {0} From {1}", selectedFields, tableName); if (!string.IsNullOrEmpty(condition)) { sql += string.Format(" Where {0} ", condition); } if (!string.IsNullOrEmpty(orderBy)) { sql += " " + orderBy; } else { sql += string.Format(" Order by {0} {1}", GetSafeFileName(sortField), IsDescending?"DESC":"ASC"); } List <T> list = GetList(sql, paramList, trans); return(list); }
private void btnOK_Click(object sender, EventArgs e) { tempInfo.DistrictName = this.txtDistrict.Text; tempInfo.CityID = Convert.ToInt32(this.txtCity.Tag.ToString()); try { bool succeed = false; if (string.IsNullOrEmpty(ID)) { succeed = BLLFactory <District> .Instance.Insert(tempInfo); } else { succeed = BLLFactory <District> .Instance.Update(tempInfo, tempInfo.ID); } ProcessDataSaved(this.btnOK, new EventArgs()); this.DialogResult = System.Windows.Forms.DialogResult.OK; } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } }
/// <summary> /// 根据指定条件,从数据库中删除指定对象 /// </summary> /// <param name="condition">删除记录的条件语句</param> /// <param name="trans">事务对象</param> /// <param name="paramList">Sql参数列表</param> /// <param name="trans">事务对象</param> /// <returns>执行成功返回<c>true</c>,否则为<c>false</c>。</returns> public virtual bool DeleteByCondition(string condition, DbTransaction trans = null, IDbDataParameter[] paramList = null) { if (HasInjectionData(condition)) { LogTextHelper.Error(string.Format("检测出SQL注入的恶意数据, {0}", condition)); throw new Exception("检测出SQL注入的恶意数据"); } string sql = string.Format("DELETE FROM {0} WHERE {1} ", tableName, condition); Database db = CreateDatabase(); DbCommand command = db.GetSqlStringCommand(sql); if (paramList != null) { command.Parameters.AddRange(paramList); } bool result = false; if (trans != null) { result = db.ExecuteNonQuery(command, trans) > 0; } else { result = db.ExecuteNonQuery(command) > 0; } return(result); }
/// <summary> /// 上传文件 /// </summary> /// <param name="inputStream">流对象</param> /// <param name="fileName">保存文件名,可包含文件夹(test/test.txt)</param> /// <returns>bool[true:成功,false:失败]</returns> public bool UploadFile(Stream inputStream, string fileName) { if (inputStream == null || string.IsNullOrEmpty(fileName)) { return(false); } WebClient client = new WebClient(); client.Credentials = this.myCredentialCache; int length = (int)inputStream.Length; byte[] buffer = new byte[length]; inputStream.Read(buffer, 0, length); try { string urlFile = GetUrlFile(this.URL, fileName); using (Stream stream = client.OpenWrite(urlFile, "PUT")) { stream.Write(buffer, 0, length); } } catch (WebException ex) { LogTextHelper.Error(ex); return(false); } return(true); }
private void btnOK_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(ID)) { StockInfo info = BLLFactory <Stock> .Instance.FindByID(ID); if (info != null) { SetInfo(info); try { bool succeed = BLLFactory <Stock> .Instance.Update(info, info.ID.ToString()); if (succeed) { MessageDxUtil.ShowTips("保存成功"); this.DialogResult = DialogResult.OK; } } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } } } }
/// <summary> /// 删除多个ID的记录 /// </summary> /// <param name="ids">多个id组合,逗号分开(1,2,3,4,5)</param> /// <returns></returns> public virtual ActionResult DeleteByIds(string ids) { //检查用户是否有权限,否则抛出MyDenyAccessException异常 base.CheckAuthorized(AuthorizeKey.DeleteKey); CommonResult result = new CommonResult(); try { if (!string.IsNullOrEmpty(ids)) { List <string> idArray = ids.ToDelimitedList <string>(","); foreach (string strId in idArray) { if (!string.IsNullOrEmpty(strId)) { baseBLL.Delete(strId); } } result.Success = true; } } catch (Exception ex) { LogTextHelper.Error(ex);//错误记录 result.ErrorMessage = ex.Message; } return(ToJsonContent(result)); }
/// <summary> /// 新增状态下的数据保存 /// </summary> /// <returns></returns> public override bool SaveAddNew() { WeightInfo info = tempInfo;//必须使用存在的局部变量,因为部分信息可能被附件使用 SetInfo(info); try { #region 新增数据 bool succeed = BLLFactory <Weight> .Instance.Insert(info); if (succeed) { //可添加其他关联操作 return(true); } #endregion } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } return(false); }
/// <summary> /// 查看Excel文件并显示在界面上操作 /// </summary> private void ViewData() { if (this.txtFilePath.Text == "") { MessageDxUtil.ShowTips("请选择指定的Excel文件"); return; } try { myDs.Tables.Clear(); myDs.Clear(); this.gridControl1.DataSource = null; string error = ""; AsposeExcelTools.ExcelFileToDataSet(this.txtFilePath.Text, out myDs, out error); this.gridControl1.DataSource = myDs.Tables[0]; this.gridView1.PopulateColumns(); } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } }
public virtual DataTable SqlTable(string sql, params object[] parameters) { if (this.HasInjectionData(sql)) { LogTextHelper.Error(string.Format("检测出SQL注入的恶意数据, {0}", sql)); throw new Exception("检测出SQL注入的恶意数据"); } DataTable dataTable = new DataTable(); try { DbConnection connection = this.baseContext.Database.Connection; if (connection.State != ConnectionState.Open) { connection.Open(); } using (DbCommand dbCommand = connection.CreateCommand()) { dbCommand.CommandText = sql; dbCommand.CommandType = CommandType.Text; dbCommand.Parameters.AddRange(parameters); using (DbDataReader dbDataReader = dbCommand.ExecuteReader()) { dataTable.Load(dbDataReader); } } } catch (Exception ex) { LogTextHelper.Error(ex); throw ex; } return(dataTable); }