/// <summary> /// 得到一个实体对象 /// </summary> /// <param name="Id"></param> /// <returns></returns> public static Model.ServiceConfiguration GetModel(string ServerName) { string strSql = "select * from ServiceConfiguration where ServerName = '" + ServerName + "'"; Model.ServiceConfiguration model = new Model.ServiceConfiguration(); DataSet ds = DBHelperSQL.GetDataSet(strSql, connectionString); model.ServerName = ServerName; if (ds.Tables[0].Rows.Count > 0) { model.ID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"]); model.ServerName = Convert.ToString(ds.Tables[0].Rows[0]["ServerName"]); model.paymentMethod = Convert.ToString(ds.Tables[0].Rows[0]["paymentMethod"]); model.Price = Convert.ToSingle(ds.Tables[0].Rows[0]["Price"]); model.InsertDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["InsertDate"]); model.ProductDescription = Convert.ToString(ds.Tables[0].Rows[0]["ProductDescription"]); return(model); } else { return(null); } }
/// <summary> /// 增加一个服务配置信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool Add(Model.ServiceConfiguration model) { string strSql = "insert into ServiceConfiguration(ServerName,paymentMethod,Price,InsertDate,ProductDescription) values(@ServerName,@paymentMethod,@Price,@InsertDate,@ProductDescription)"; SqlParameter ServerName = new SqlParameter("ServerName", SqlDbType.NVarChar); ServerName.Value = model.ServerName; SqlParameter paymentMethod = new SqlParameter("paymentMethod", SqlDbType.NVarChar); paymentMethod.Value = model.paymentMethod; SqlParameter Price = new SqlParameter("Price", SqlDbType.NVarChar); Price.Value = model.Price; SqlParameter InsertDate = new SqlParameter("InsertDate", SqlDbType.NVarChar); InsertDate.Value = model.InsertDate; SqlParameter ProductDescription = new SqlParameter("ProductDescription", SqlDbType.NVarChar); ProductDescription.Value = model.ProductDescription; return(DBHelperSQL.GetNums(strSql, new SqlParameter[] { ServerName, paymentMethod, Price, InsertDate, ProductDescription }, connectionString) == 1 ? true : false); }
/// <summary> /// 更新一条数据,根据ID /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool Update(Model.ServiceConfiguration model) { string strSql = "update ServiceConfiguration set ServerName=@ServerName, paymentMethod=@paymentMethod, Price=@Price, InsertDate=@InsertDate, ProductDescription=@ProductDescription where ID = " + model.ID.ToString(); SqlParameter ServerName = new SqlParameter("ServerName", SqlDbType.NVarChar); ServerName.Value = model.ServerName; SqlParameter paymentMethod = new SqlParameter("paymentMethod", SqlDbType.NVarChar); paymentMethod.Value = model.paymentMethod; SqlParameter Price = new SqlParameter("Price", SqlDbType.NVarChar); Price.Value = model.Price; SqlParameter InsertDate = new SqlParameter("InsertDate", SqlDbType.NVarChar); InsertDate.Value = model.InsertDate; SqlParameter ProductDescription = new SqlParameter("ProductDescription", SqlDbType.NVarChar); ProductDescription.Value = model.ProductDescription; //WebLogger.WriteErroLog(strSql); return(DBHelperSQL.GetNums(strSql, new SqlParameter[] { ServerName, paymentMethod, Price, InsertDate, ProductDescription }, connectionString) == 1 ? true : false); }
public void save() { Model.ServiceConfiguration service = DAL.ServiceConfiguration.GetModel(Session["ServerName"].ToString()); service.ServerName = ServerName.Value; service.paymentMethod = paymentMethod.Value; service.Price = Convert.ToSingle(Price.Value); service.ProductDescription = ProductDescription.Value; DAL.ServiceConfiguration.Update(service); Response.Clear(); Response.Write("1"); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { if (Request["action"] != "" && Request["action"] == "save") { save(); } if (!IsPostBack) { if (Request["ServerName"] != null) { Session["ServerName"] = Request["ServerName"].ToString(); Model.ServiceConfiguration serviceConfiguration = DAL.ServiceConfiguration.GetModel(Session["ServerName"].ToString()); ServerName.Value = serviceConfiguration.ServerName; Price.Value = serviceConfiguration.Price.ToString(); paymentMethod.Value = serviceConfiguration.paymentMethod.ToString(); ProductDescription.Value = serviceConfiguration.ProductDescription; } } }
private void AddStas() { Model.ServiceConfiguration ServiceConfig = new Model.ServiceConfiguration(); ServiceConfig.ServerName = Request.Form["ServerName"].ToString(); ServiceConfig.Price = Convert.ToSingle(Request.Form["Price"].ToString()); ServiceConfig.ProductDescription = Request.Form["ProductDescription"].ToString(); ServiceConfig.InsertDate = DateTime.Now; ServiceConfig.paymentMethod = Request.Form["paymentMethod"].ToString(); if (DAL.ServiceConfiguration.Exists(ServiceConfig.ServerName)) { Response.Clear(); Response.Write("0"); Response.End(); } else { try { DAL.ServiceConfiguration.Add(ServiceConfig); Response.Clear(); Response.Write("1"); Response.End(); } catch (Exception) { } Model.SysLog mSysLog = new Model.SysLog(); mSysLog.LogTime = DateTime.Now; mSysLog.LogType = 0; mSysLog.UserName = Session["UserName"].ToString(); mSysLog.Remark = "管理员添加产品配置:" + ServiceConfig.ServerName + "的信息"; DAL.SysLog.Add(mSysLog); } }