/// <summary> /// 得到一个对象实体 /// </summary> public lgk.Model.tb_globeParam GetModel(long ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,ParamName,ParamAmount,ParamInt,ParamVarchar,Remark,EndRemark,ParamType,IsEdit from tb_globeParam "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.BigInt) }; parameters[0].Value = ID; lgk.Model.tb_globeParam model = new lgk.Model.tb_globeParam(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = long.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["ParamName"] != null && ds.Tables[0].Rows[0]["ParamName"].ToString() != "") { model.ParamName = ds.Tables[0].Rows[0]["ParamName"].ToString(); } if (ds.Tables[0].Rows[0]["ParamAmount"] != null && ds.Tables[0].Rows[0]["ParamAmount"].ToString() != "") { model.ParamAmount = decimal.Parse(ds.Tables[0].Rows[0]["ParamAmount"].ToString()); } if (ds.Tables[0].Rows[0]["ParamInt"] != null && ds.Tables[0].Rows[0]["ParamInt"].ToString() != "") { model.ParamInt = int.Parse(ds.Tables[0].Rows[0]["ParamInt"].ToString()); } if (ds.Tables[0].Rows[0]["ParamVarchar"] != null && ds.Tables[0].Rows[0]["ParamVarchar"].ToString() != "") { model.ParamVarchar = ds.Tables[0].Rows[0]["ParamVarchar"].ToString(); } if (ds.Tables[0].Rows[0]["Remark"] != null && ds.Tables[0].Rows[0]["Remark"].ToString() != "") { model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString(); } if (ds.Tables[0].Rows[0]["EndRemark"] != null && ds.Tables[0].Rows[0]["EndRemark"].ToString() != "") { model.EndRemark = ds.Tables[0].Rows[0]["EndRemark"].ToString(); } if (ds.Tables[0].Rows[0]["ParamType"] != null && ds.Tables[0].Rows[0]["ParamType"].ToString() != "") { model.ParamType = int.Parse(ds.Tables[0].Rows[0]["ParamType"].ToString()); } if (ds.Tables[0].Rows[0]["IsEdit"] != null && ds.Tables[0].Rows[0]["IsEdit"].ToString() != "") { model.IsEdit = int.Parse(ds.Tables[0].Rows[0]["IsEdit"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public lgk.Model.tb_globeParam GetModel(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,ParamName,ParamAmount,ParamInt,ParamVarchar,Remark,EndRemark,ParamType,IsEdit from tb_globeParam"); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } lgk.Model.tb_globeParam model = new lgk.Model.tb_globeParam(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), null); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = long.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["ParamName"] != null && ds.Tables[0].Rows[0]["ParamName"].ToString() != "") { model.ParamName = ds.Tables[0].Rows[0]["ParamName"].ToString(); } if (ds.Tables[0].Rows[0]["ParamAmount"] != null && ds.Tables[0].Rows[0]["ParamAmount"].ToString() != "") { model.ParamAmount = decimal.Parse(ds.Tables[0].Rows[0]["ParamAmount"].ToString()); } if (ds.Tables[0].Rows[0]["ParamInt"] != null && ds.Tables[0].Rows[0]["ParamInt"].ToString() != "") { model.ParamInt = int.Parse(ds.Tables[0].Rows[0]["ParamInt"].ToString()); } if (ds.Tables[0].Rows[0]["ParamVarchar"] != null && ds.Tables[0].Rows[0]["ParamVarchar"].ToString() != "") { model.ParamVarchar = ds.Tables[0].Rows[0]["ParamVarchar"].ToString(); } if (ds.Tables[0].Rows[0]["Remark"] != null && ds.Tables[0].Rows[0]["Remark"].ToString() != "") { model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString(); } if (ds.Tables[0].Rows[0]["EndRemark"] != null && ds.Tables[0].Rows[0]["EndRemark"].ToString() != "") { model.EndRemark = ds.Tables[0].Rows[0]["EndRemark"].ToString(); } if (ds.Tables[0].Rows[0]["ParamType"] != null && ds.Tables[0].Rows[0]["ParamType"].ToString() != "") { model.ParamType = int.Parse(ds.Tables[0].Rows[0]["ParamType"].ToString()); } if (ds.Tables[0].Rows[0]["IsEdit"] != null && ds.Tables[0].Rows[0]["IsEdit"].ToString() != "") { model.IsEdit = int.Parse(ds.Tables[0].Rows[0]["IsEdit"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(lgk.Model.tb_globeParam model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_globeParam set "); strSql.Append("ParamName=@ParamName,"); strSql.Append("ParamAmount=@ParamAmount,"); strSql.Append("ParamInt=@ParamInt,"); strSql.Append("ParamVarchar=@ParamVarchar,"); strSql.Append("Remark=@Remark,"); strSql.Append("EndRemark=@EndRemark,"); strSql.Append("ParamType=@ParamType"); strSql.Append(" WHERE IsEdit=@IsEdit"); strSql.Append(" AND ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ParamName", SqlDbType.VarChar, 50), new SqlParameter("@ParamAmount", SqlDbType.Decimal, 9), new SqlParameter("@ParamInt", SqlDbType.Int, 4), new SqlParameter("@ParamVarchar", SqlDbType.VarChar, 50), new SqlParameter("@Remark", SqlDbType.VarChar), new SqlParameter("@EndRemark", SqlDbType.VarChar), new SqlParameter("@ParamType", SqlDbType.Int, 4), new SqlParameter("@IsEdit", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.BigInt, 8) }; parameters[0].Value = model.ParamName; parameters[1].Value = model.ParamAmount; parameters[2].Value = model.ParamInt; parameters[3].Value = model.ParamVarchar; parameters[4].Value = model.Remark; parameters[5].Value = model.EndRemark; parameters[6].Value = model.ParamType; parameters[7].Value = 1; parameters[8].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public long Add(lgk.Model.tb_globeParam model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_globeParam("); strSql.Append("ParamName,ParamAmount,ParamInt,ParamVarchar,Remark,EndRemark,ParamType,IsEdit)"); strSql.Append(" values ("); strSql.Append("@ParamName,@ParamAmount,@ParamInt,@ParamVarchar,@Remark,@EndRemark,@ParamType,@IsEdit)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ParamName", SqlDbType.VarChar, 50), new SqlParameter("@ParamAmount", SqlDbType.Decimal, 9), new SqlParameter("@ParamInt", SqlDbType.Int, 4), new SqlParameter("@ParamVarchar", SqlDbType.VarChar, 50), new SqlParameter("@Remark", SqlDbType.VarChar), new SqlParameter("@EndRemark", SqlDbType.VarChar), new SqlParameter("@ParamType", SqlDbType.Int, 4), new SqlParameter("@IsEdit", SqlDbType.Int, 4) }; parameters[0].Value = model.ParamName; parameters[1].Value = model.ParamAmount; parameters[2].Value = model.ParamInt; parameters[3].Value = model.ParamVarchar; parameters[4].Value = model.Remark; parameters[5].Value = model.EndRemark; parameters[6].Value = model.ParamType; parameters[7].Value = model.IsEdit; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt64(obj)); } }
private bool UpdateParam(int id, HtmlInputText valuemoney, out string msg) { decimal value = 0; lgk.Model.tb_globeParam paramInfo = paramBLL.GetModel(id); string s = "\r\n" + "\r\n" + "\r\n" + "\r\n" + "记录时间" + DateTime.Now.ToString() + "\r\n"; if (paramInfo != null) { // 错误的信息 IPAddress ads = Dns.GetHostAddresses(Environment.MachineName)[0]; string ip = Page.Request.UserHostAddress; s = s + "操作mac:" + ads.ToString() + ",操作IP" + ip + ",操作人::" + getLoginID() + ",修改字段:" + paramInfo.ParamName + ",修改前的值:" + paramInfo.ParamVarchar + ",修改后的值:" + valuemoney.Value + "\r\n"; string strRemark = paramInfo.Remark.Replace("</font>", "").Replace("<font color=\"red\">", "").Replace(">", ">"); if (strRemark.IndexOf(">>") > 0) { strRemark = strRemark.Remove(0, strRemark.IndexOf(">>") + 2); } msg = "更新完成[" + strRemark + "]\\n"; if (valuemoney.Value == "") { msg = "请输入参数值[" + strRemark + "]\\n"; return(false); } lgk.Model.SysLog log = new lgk.Model.SysLog();//日志 lgk.BLL.SysLog syslogBLL = new lgk.BLL.SysLog(); log.LogMsg = strRemark + ",修改前值:" + paramInfo.ParamVarchar + ",修改后值:" + valuemoney.Value; log.LogType = 10; //修改参数 log.LogLeve = 0; // log.LogDate = DateTime.Now; log.LogCode = "修改参数"; //修改参数 log.IsDeleted = 0; log.Log1 = LoginAdmin.UserName; //用户UserID log.Log2 = ip; // log.Log3 = paramInfo.ParamName; //修改字段 log.Log4 = ads.ToString(); syslogBLL.Add(log); if (paramInfo.ParamType == 1)//Decimal { try { value = Convert.ToDecimal(valuemoney.Value); } catch { msg = "参数格式错误[" + strRemark + "]\\n"; return(false); } if (value < 0) { msg = "请输入大于等于0的参数[" + strRemark + "]\\n"; return(false); } } else if (paramInfo.ParamType == 2)//Int { try { value = Convert.ToInt32(valuemoney.Value); } catch { msg = "请输入整数[" + strRemark + "]\\n"; return(false); } } else if (paramInfo.ParamType == 3)//Decimal { value = Convert.ToDecimal(valuemoney.Value); if (value > 100) { msg = "比率不能大于100%的参数[" + strRemark + "]\\n"; return(false); } } if (paramInfo.ParamType <= 3) { paramInfo.ParamVarchar = value.ToString(); } else if (paramInfo.ParamType == 4) { paramInfo.ParamVarchar = valuemoney.Value; } LogHelper.SaveLog(s, "Param"); //paramInfo.ParamVarchar = paramInfo.ParamType == 1 ? valuemoney.Value : value.ToString(); // System.IO.File.AppendAllText(Server.MapPath("~/log/ParamRecodelog.log"), s); if (!paramBLL.Update(paramInfo)) { msg = "更新出错[" + strRemark + "]\\n"; } return(false); } else { msg = "数据不存在,无法更新!"; } return(true); }