/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.Depts DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.Depts model = new WebDemo.Model.WebDemo.Depts(); if (row != null) { if (row["DeptID"] != null) { model.DeptID = row["DeptID"].ToString(); } if (row["DeptName"] != null) { model.DeptName = row["DeptName"].ToString(); } if (row["UpperDept"] != null) { model.UpperDept = row["UpperDept"].ToString(); } if (row["Address"] != null) { model.Address = row["Address"].ToString(); } if (row["imgIndex"] != null && row["imgIndex"].ToString() != "") { model.imgIndex = int.Parse(row["imgIndex"].ToString()); } if (row["SelectimgIndex"] != null && row["SelectimgIndex"].ToString() != "") { model.SelectimgIndex = int.Parse(row["SelectimgIndex"].ToString()); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } if (row["CustomCode"] != null) { model.CustomCode = row["CustomCode"].ToString(); } if (row["DeptType"] != null && row["DeptType"].ToString() != "") { model.DeptType = int.Parse(row["DeptType"].ToString()); } if (row["LocationX"] != null && row["LocationX"].ToString() != "") { model.LocationX = decimal.Parse(row["LocationX"].ToString()); } if (row["LocationY"] != null && row["LocationY"].ToString() != "") { model.LocationY = decimal.Parse(row["LocationY"].ToString()); } if (row["UpdateTime"] != null && row["UpdateTime"].ToString() != "") { model.UpdateTime = DateTime.Parse(row["UpdateTime"].ToString()); } if (row["OrderNum"] != null && row["OrderNum"].ToString() != "") { model.OrderNum = int.Parse(row["OrderNum"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.Depts model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Depts set "); strSql.Append("DeptName=@DeptName,"); strSql.Append("UpperDept=@UpperDept,"); strSql.Append("Address=@Address,"); strSql.Append("imgIndex=@imgIndex,"); strSql.Append("SelectimgIndex=@SelectimgIndex,"); strSql.Append("Remark=@Remark,"); strSql.Append("CustomCode=@CustomCode,"); strSql.Append("DeptType=@DeptType,"); strSql.Append("LocationX=@LocationX,"); strSql.Append("LocationY=@LocationY,"); strSql.Append("UpdateTime=@UpdateTime,"); strSql.Append("OrderNum=@OrderNum"); strSql.Append(" where DeptID=@DeptID "); SqlParameter[] parameters = { new SqlParameter("@DeptName", SqlDbType.VarChar, 50), new SqlParameter("@UpperDept", SqlDbType.VarChar, 50), new SqlParameter("@Address", SqlDbType.VarChar, 100), new SqlParameter("@imgIndex", SqlDbType.Int, 4), new SqlParameter("@SelectimgIndex", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.VarChar, 500), new SqlParameter("@CustomCode", SqlDbType.VarChar, 50), new SqlParameter("@DeptType", SqlDbType.Int, 4), new SqlParameter("@LocationX", SqlDbType.Decimal, 9), new SqlParameter("@LocationY", SqlDbType.Decimal, 9), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@OrderNum", SqlDbType.Int, 4), new SqlParameter("@DeptID", SqlDbType.VarChar, 50) }; parameters[0].Value = model.DeptName; parameters[1].Value = model.UpperDept; parameters[2].Value = model.Address; parameters[3].Value = model.imgIndex; parameters[4].Value = model.SelectimgIndex; parameters[5].Value = model.Remark; parameters[6].Value = model.CustomCode; parameters[7].Value = model.DeptType; parameters[8].Value = model.LocationX; parameters[9].Value = model.LocationY; parameters[10].Value = model.UpdateTime; parameters[11].Value = model.OrderNum; parameters[12].Value = model.DeptID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(WebDemo.Model.WebDemo.Depts model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Depts("); strSql.Append("DeptID,DeptName,UpperDept,Address,imgIndex,SelectimgIndex,Remark,CustomCode,DeptType,LocationX,LocationY,UpdateTime,OrderNum)"); strSql.Append(" values ("); strSql.Append("@DeptID,@DeptName,@UpperDept,@Address,@imgIndex,@SelectimgIndex,@Remark,@CustomCode,@DeptType,@LocationX,@LocationY,@UpdateTime,@OrderNum)"); SqlParameter[] parameters = { new SqlParameter("@DeptID", SqlDbType.VarChar, 50), new SqlParameter("@DeptName", SqlDbType.VarChar, 50), new SqlParameter("@UpperDept", SqlDbType.VarChar, 50), new SqlParameter("@Address", SqlDbType.VarChar, 100), new SqlParameter("@imgIndex", SqlDbType.Int, 4), new SqlParameter("@SelectimgIndex", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.VarChar, 500), new SqlParameter("@CustomCode", SqlDbType.VarChar, 50), new SqlParameter("@DeptType", SqlDbType.Int, 4), new SqlParameter("@LocationX", SqlDbType.Decimal, 9), new SqlParameter("@LocationY", SqlDbType.Decimal, 9), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@OrderNum", SqlDbType.Int, 4) }; parameters[0].Value = model.DeptID; parameters[1].Value = model.DeptName; parameters[2].Value = model.UpperDept; parameters[3].Value = model.Address; parameters[4].Value = model.imgIndex; parameters[5].Value = model.SelectimgIndex; parameters[6].Value = model.Remark; parameters[7].Value = model.CustomCode; parameters[8].Value = model.DeptType; parameters[9].Value = model.LocationX; parameters[10].Value = model.LocationY; parameters[11].Value = model.UpdateTime; parameters[12].Value = model.OrderNum; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(string DeptID) { WebDemo.BLL.WebDemo.Depts bll = new WebDemo.BLL.WebDemo.Depts(); WebDemo.Model.WebDemo.Depts model = bll.GetModel(DeptID); this.lblDeptID.Text = model.DeptID; this.lblDeptName.Text = model.DeptName; this.lblUpperDept.Text = model.UpperDept; this.lblAddress.Text = model.Address; this.lblimgIndex.Text = model.imgIndex.ToString(); this.lblSelectimgIndex.Text = model.SelectimgIndex.ToString(); this.lblRemark.Text = model.Remark; this.lblCustomCode.Text = model.CustomCode; this.lblDeptType.Text = model.DeptType.ToString(); this.lblLocationX.Text = model.LocationX.ToString(); this.lblLocationY.Text = model.LocationY.ToString(); this.lblUpdateTime.Text = model.UpdateTime.ToString(); this.lblOrderNum.Text = model.OrderNum.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.Depts GetModel(string DeptID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 DeptID,DeptName,UpperDept,Address,imgIndex,SelectimgIndex,Remark,CustomCode,DeptType,LocationX,LocationY,UpdateTime,OrderNum from Depts "); strSql.Append(" where DeptID=@DeptID "); SqlParameter[] parameters = { new SqlParameter("@DeptID", SqlDbType.VarChar, 50) }; parameters[0].Value = DeptID; WebDemo.Model.WebDemo.Depts model = new WebDemo.Model.WebDemo.Depts(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtDeptID.Text.Trim().Length == 0) { strErr += "部门编号(编码由数字组成不能为空!\\n"; } if (this.txtDeptName.Text.Trim().Length == 0) { strErr += "部门名称不能为空!\\n"; } if (this.txtUpperDept.Text.Trim().Length == 0) { strErr += "上级部门代码(为空说明为第一级不能为空!\\n"; } if (this.txtAddress.Text.Trim().Length == 0) { strErr += "Address不能为空!\\n"; } if (!PageValidate.IsNumber(txtimgIndex.Text)) { strErr += "imgIndex格式错误!\\n"; } if (!PageValidate.IsNumber(txtSelectimgIndex.Text)) { strErr += "SelectimgIndex格式错误!\\n"; } if (this.txtRemark.Text.Trim().Length == 0) { strErr += "备注不能为空!\\n"; } if (this.txtCustomCode.Text.Trim().Length == 0) { strErr += "CustomCode不能为空!\\n"; } if (!PageValidate.IsNumber(txtDeptType.Text)) { strErr += "DeptType格式错误!\\n"; } if (!PageValidate.IsDecimal(txtLocationX.Text)) { strErr += "LocationX格式错误!\\n"; } if (!PageValidate.IsDecimal(txtLocationY.Text)) { strErr += "LocationY格式错误!\\n"; } if (!PageValidate.IsDateTime(txtUpdateTime.Text)) { strErr += "UpdateTime格式错误!\\n"; } if (!PageValidate.IsNumber(txtOrderNum.Text)) { strErr += "OrderNum格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string DeptID = this.txtDeptID.Text; string DeptName = this.txtDeptName.Text; string UpperDept = this.txtUpperDept.Text; string Address = this.txtAddress.Text; int imgIndex = int.Parse(this.txtimgIndex.Text); int SelectimgIndex = int.Parse(this.txtSelectimgIndex.Text); string Remark = this.txtRemark.Text; string CustomCode = this.txtCustomCode.Text; int DeptType = int.Parse(this.txtDeptType.Text); decimal LocationX = decimal.Parse(this.txtLocationX.Text); decimal LocationY = decimal.Parse(this.txtLocationY.Text); DateTime UpdateTime = DateTime.Parse(this.txtUpdateTime.Text); int OrderNum = int.Parse(this.txtOrderNum.Text); WebDemo.Model.WebDemo.Depts model = new WebDemo.Model.WebDemo.Depts(); model.DeptID = DeptID; model.DeptName = DeptName; model.UpperDept = UpperDept; model.Address = Address; model.imgIndex = imgIndex; model.SelectimgIndex = SelectimgIndex; model.Remark = Remark; model.CustomCode = CustomCode; model.DeptType = DeptType; model.LocationX = LocationX; model.LocationY = LocationY; model.UpdateTime = UpdateTime; model.OrderNum = OrderNum; WebDemo.BLL.WebDemo.Depts bll = new WebDemo.BLL.WebDemo.Depts(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }