/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.tb_KuCun DataRowToModel(DataRow row) { Maticsoft.Model.tb_KuCun model = new Maticsoft.Model.tb_KuCun(); if (row != null) { if (row["HuoJiaHao"] != null) { model.HuoJiaHao = row["HuoJiaHao"].ToString(); } if (row["CengHao"] != null) { model.CengHao = row["CengHao"].ToString(); } if (row["LieHao"] != null) { model.LieHao = row["LieHao"].ToString(); } if (row["BianMa"] != null) { model.BianMa = row["BianMa"].ToString(); } if (row["MingCheng"] != null) { model.MingCheng = row["MingCheng"].ToString(); } if (row["GuiGe"] != null) { model.GuiGe = row["GuiGe"].ToString(); } if (row["XingHao"] != null) { model.XingHao = row["XingHao"].ToString(); } if (row["HeTongHao"] != null) { model.HeTongHao = row["HeTongHao"].ToString(); } if (row["ShuLiang"] != null) { model.ShuLiang = row["ShuLiang"].ToString(); } if (row["X"] != null) { model.X = row["X"].ToString(); } if (row["Y"] != null) { model.Y = row["Y"].ToString(); } if (row["Z"] != null) { model.Z = row["Z"].ToString(); } if (row["CaoZuoYuan"] != null) { model.CaoZuoYuan = row["CaoZuoYuan"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.tb_KuCun GetModel(string HuoJiaHao, string CengHao, string LieHao) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 HuoJiaHao,CengHao,LieHao,BianMa,MingCheng,GuiGe,XingHao,HeTongHao,ShuLiang,X,Y,Z,CaoZuoYuan from tb_KuCun "); strSql.Append(" where HuoJiaHao=@HuoJiaHao and CengHao=@CengHao and LieHao=@LieHao "); SqlParameter[] parameters = { new SqlParameter("@HuoJiaHao", SqlDbType.NChar, 10), new SqlParameter("@CengHao", SqlDbType.NChar, 10), new SqlParameter("@LieHao", SqlDbType.NChar, 10) }; parameters[0].Value = HuoJiaHao; parameters[1].Value = CengHao; parameters[2].Value = LieHao; Maticsoft.Model.tb_KuCun model = new Maticsoft.Model.tb_KuCun(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.tb_KuCun model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_KuCun set "); strSql.Append("BianMa=@BianMa,"); strSql.Append("MingCheng=@MingCheng,"); strSql.Append("GuiGe=@GuiGe,"); strSql.Append("XingHao=@XingHao,"); strSql.Append("HeTongHao=@HeTongHao,"); strSql.Append("ShuLiang=@ShuLiang,"); strSql.Append("X=@X,"); strSql.Append("Y=@Y,"); strSql.Append("Z=@Z,"); strSql.Append("CaoZuoYuan=@CaoZuoYuan"); strSql.Append(" where HuoJiaHao=@HuoJiaHao and CengHao=@CengHao and LieHao=@LieHao "); SqlParameter[] parameters = { new SqlParameter("@BianMa", SqlDbType.NChar, 50), new SqlParameter("@MingCheng", SqlDbType.NChar, 50), new SqlParameter("@GuiGe", SqlDbType.NChar, 50), new SqlParameter("@XingHao", SqlDbType.NChar, 50), new SqlParameter("@HeTongHao", SqlDbType.NChar, 50), new SqlParameter("@ShuLiang", SqlDbType.NChar, 10), new SqlParameter("@X", SqlDbType.NChar, 50), new SqlParameter("@Y", SqlDbType.NChar, 50), new SqlParameter("@Z", SqlDbType.NChar, 50), new SqlParameter("@CaoZuoYuan", SqlDbType.NChar, 50), new SqlParameter("@HuoJiaHao", SqlDbType.NChar, 10), new SqlParameter("@CengHao", SqlDbType.NChar, 10), new SqlParameter("@LieHao", SqlDbType.NChar, 10) }; parameters[0].Value = model.BianMa; parameters[1].Value = model.MingCheng; parameters[2].Value = model.GuiGe; parameters[3].Value = model.XingHao; parameters[4].Value = model.HeTongHao; parameters[5].Value = model.ShuLiang; parameters[6].Value = model.X; parameters[7].Value = model.Y; parameters[8].Value = model.Z; parameters[9].Value = model.CaoZuoYuan; parameters[10].Value = model.HuoJiaHao; parameters[11].Value = model.CengHao; parameters[12].Value = model.LieHao; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.tb_KuCun model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_KuCun("); strSql.Append("HuoJiaHao,CengHao,LieHao,BianMa,MingCheng,GuiGe,XingHao,HeTongHao,ShuLiang,X,Y,Z,CaoZuoYuan)"); strSql.Append(" values ("); strSql.Append("@HuoJiaHao,@CengHao,@LieHao,@BianMa,@MingCheng,@GuiGe,@XingHao,@HeTongHao,@ShuLiang,@X,@Y,@Z,@CaoZuoYuan)"); SqlParameter[] parameters = { new SqlParameter("@HuoJiaHao", SqlDbType.NChar, 10), new SqlParameter("@CengHao", SqlDbType.NChar, 10), new SqlParameter("@LieHao", SqlDbType.NChar, 10), new SqlParameter("@BianMa", SqlDbType.NChar, 50), new SqlParameter("@MingCheng", SqlDbType.NChar, 50), new SqlParameter("@GuiGe", SqlDbType.NChar, 50), new SqlParameter("@XingHao", SqlDbType.NChar, 50), new SqlParameter("@HeTongHao", SqlDbType.NChar, 50), new SqlParameter("@ShuLiang", SqlDbType.NChar, 10), new SqlParameter("@X", SqlDbType.NChar, 50), new SqlParameter("@Y", SqlDbType.NChar, 50), new SqlParameter("@Z", SqlDbType.NChar, 50), new SqlParameter("@CaoZuoYuan", SqlDbType.NChar, 50) }; parameters[0].Value = model.HuoJiaHao; parameters[1].Value = model.CengHao; parameters[2].Value = model.LieHao; parameters[3].Value = model.BianMa; parameters[4].Value = model.MingCheng; parameters[5].Value = model.GuiGe; parameters[6].Value = model.XingHao; parameters[7].Value = model.HeTongHao; parameters[8].Value = model.ShuLiang; parameters[9].Value = model.X; parameters[10].Value = model.Y; parameters[11].Value = model.Z; parameters[12].Value = model.CaoZuoYuan; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(string HuoJiaHao, string CengHao, string LieHao) { Maticsoft.BLL.tb_KuCun bll = new Maticsoft.BLL.tb_KuCun(); Maticsoft.Model.tb_KuCun model = bll.GetModel(HuoJiaHao, CengHao, LieHao); this.lblHuoJiaHao.Text = model.HuoJiaHao; this.lblCengHao.Text = model.CengHao; this.lblLieHao.Text = model.LieHao; this.txtBianMa.Text = model.BianMa; this.txtMingCheng.Text = model.MingCheng; this.txtGuiGe.Text = model.GuiGe; this.txtXingHao.Text = model.XingHao; this.txtHeTongHao.Text = model.HeTongHao; this.txtShuLiang.Text = model.ShuLiang; this.txtX.Text = model.X; this.txtY.Text = model.Y; this.txtZ.Text = model.Z; this.txtCaoZuoYuan.Text = model.CaoZuoYuan; }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtBianMa.Text.Trim().Length == 0) { strErr += "BianMa不能为空!\\n"; } if (this.txtMingCheng.Text.Trim().Length == 0) { strErr += "MingCheng不能为空!\\n"; } if (this.txtGuiGe.Text.Trim().Length == 0) { strErr += "GuiGe不能为空!\\n"; } if (this.txtXingHao.Text.Trim().Length == 0) { strErr += "XingHao不能为空!\\n"; } if (this.txtHeTongHao.Text.Trim().Length == 0) { strErr += "HeTongHao不能为空!\\n"; } if (this.txtShuLiang.Text.Trim().Length == 0) { strErr += "ShuLiang不能为空!\\n"; } if (this.txtX.Text.Trim().Length == 0) { strErr += "X不能为空!\\n"; } if (this.txtY.Text.Trim().Length == 0) { strErr += "Y不能为空!\\n"; } if (this.txtZ.Text.Trim().Length == 0) { strErr += "Z不能为空!\\n"; } if (this.txtCaoZuoYuan.Text.Trim().Length == 0) { strErr += "CaoZuoYuan不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string HuoJiaHao = this.lblHuoJiaHao.Text; string CengHao = this.lblCengHao.Text; string LieHao = this.lblLieHao.Text; string BianMa = this.txtBianMa.Text; string MingCheng = this.txtMingCheng.Text; string GuiGe = this.txtGuiGe.Text; string XingHao = this.txtXingHao.Text; string HeTongHao = this.txtHeTongHao.Text; string ShuLiang = this.txtShuLiang.Text; string X = this.txtX.Text; string Y = this.txtY.Text; string Z = this.txtZ.Text; string CaoZuoYuan = this.txtCaoZuoYuan.Text; Maticsoft.Model.tb_KuCun model = new Maticsoft.Model.tb_KuCun(); model.HuoJiaHao = HuoJiaHao; model.CengHao = CengHao; model.LieHao = LieHao; model.BianMa = BianMa; model.MingCheng = MingCheng; model.GuiGe = GuiGe; model.XingHao = XingHao; model.HeTongHao = HeTongHao; model.ShuLiang = ShuLiang; model.X = X; model.Y = Y; model.Z = Z; model.CaoZuoYuan = CaoZuoYuan; Maticsoft.BLL.tb_KuCun bll = new Maticsoft.BLL.tb_KuCun(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }