/// <summary> /// 获取实体 /// </summary> public Model.contact GetContactModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from dt_contact "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; Model.contact model = new Model.contact(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { #region DATA if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "") { model.title = ds.Tables[0].Rows[0]["title"].ToString(); } if (ds.Tables[0].Rows[0]["address"] != null && ds.Tables[0].Rows[0]["address"].ToString() != "") { model.address = ds.Tables[0].Rows[0]["address"].ToString(); } if (ds.Tables[0].Rows[0]["shop_hours"] != null && ds.Tables[0].Rows[0]["shop_hours"].ToString() != "") { model.shop_hours = ds.Tables[0].Rows[0]["shop_hours"].ToString(); } if (ds.Tables[0].Rows[0]["telephone"] != null && ds.Tables[0].Rows[0]["telephone"].ToString() != "") { model.telephone = ds.Tables[0].Rows[0]["telephone"].ToString(); } if (ds.Tables[0].Rows[0]["mobile"] != null && ds.Tables[0].Rows[0]["mobile"].ToString() != "") { model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString(); } if (ds.Tables[0].Rows[0]["remark1"] != null && ds.Tables[0].Rows[0]["remark1"].ToString() != "") { model.remark1 = ds.Tables[0].Rows[0]["remark1"].ToString(); } if (ds.Tables[0].Rows[0]["remark2"] != null && ds.Tables[0].Rows[0]["remark2"].ToString() != "") { model.remark2 = int.Parse(ds.Tables[0].Rows[0]["remark2"].ToString()); } if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"] != null && ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } #endregion return model; } else { return null; } }
private bool DoAdd() { bool result = true; Model.contact model = new Model.contact() { address = txtAddress.Text.Trim(), mobile = txtMobile.Text.Trim(), remark1 = "", remark2 = 0, shop_hours = txtHours.Text.Trim(), sort_id = int.Parse(txtSortId.Text.Trim()), telephone = txtTel.Text.Trim(), title = txtTitle.Text.Trim(), add_time= DateTime.Now }; if (bll.Add(model) < 1) { result = false; } return result; }