/// <summary> /// 得到一个对象实体 /// </summary> public AdvUserMod GetModel(int SysNo) { StringBuilder strSql = new StringBuilder(); strSql.Append("select SysNo, Name, CellPhone, FirstRequestUrl, SSQianSysNo, BirthTime, Gender, DistrictSysNo, DR, TS from AdvUser"); strSql.Append(" where SysNo=@SysNo "); SqlParameter[] parameters = { new SqlParameter("@SysNo", SqlDbType.Int, 4) }; parameters[0].Value = SysNo; AdvUserMod model = new AdvUserMod(); DataSet ds = SqlHelper.ExecuteDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["SysNo"].ToString() != "") { model.SysNo = int.Parse(ds.Tables[0].Rows[0]["SysNo"].ToString()); } model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); model.CellPhone = ds.Tables[0].Rows[0]["CellPhone"].ToString(); model.FirstRequestUrl = ds.Tables[0].Rows[0]["FirstRequestUrl"].ToString(); if (ds.Tables[0].Rows[0]["SSQianSysNo"].ToString() != "") { model.SSQianSysNo = int.Parse(ds.Tables[0].Rows[0]["SSQianSysNo"].ToString()); } if (ds.Tables[0].Rows[0]["BirthTime"].ToString() != "") { model.BirthTime = DateTime.Parse(ds.Tables[0].Rows[0]["BirthTime"].ToString()); } if (ds.Tables[0].Rows[0]["Gender"].ToString() != "") { model.Gender = int.Parse(ds.Tables[0].Rows[0]["Gender"].ToString()); } if (ds.Tables[0].Rows[0]["DistrictSysNo"].ToString() != "") { model.DistrictSysNo = int.Parse(ds.Tables[0].Rows[0]["DistrictSysNo"].ToString()); } if (ds.Tables[0].Rows[0]["DR"].ToString() != "") { model.DR = int.Parse(ds.Tables[0].Rows[0]["DR"].ToString()); } if (ds.Tables[0].Rows[0]["TS"].ToString() != "") { model.TS = DateTime.Parse(ds.Tables[0].Rows[0]["TS"].ToString()); } return(model); } else { return(null); } }
public AdvUserMod GetModel(string phonenum) { AdvUserMod model = new AdvUserMod(); using (SQLData data = new SQLData()) { StringBuilder builder = new StringBuilder(); builder.Append("select SysNo from AdvUser where CellPhone='").Append(SQLData.SQLFilter(phonenum)).Append("' and DR=").Append((int)AppEnum.State.normal); try { model.SysNo = int.Parse(data.CmdtoDataRow(builder.ToString())["SysNo"].ToString()); } catch (Exception exception) { //throw exception; } } if (model.SysNo != AppConst.IntNull) { model = this.GetModel(model.SysNo); } return model; }
/// <summary> /// 更新一条数据 /// </summary> public void Update(AdvUserMod model) { dal.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(AdvUserMod model) { return dal.Add(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(AdvUserMod model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into AdvUser("); strSql.Append("Name,CellPhone,FirstRequestUrl,SSQianSysNo,BirthTime,Gender,DistrictSysNo,DR,TS)"); strSql.Append(" values ("); strSql.Append("@Name,@CellPhone,@FirstRequestUrl,@SSQianSysNo,@BirthTime,@Gender,@DistrictSysNo,@DR,@TS)"); strSql.Append(";select SCOPE_IDENTITY()"); SqlCommand cmd = new SqlCommand(strSql.ToString()); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.NVarChar, 40), new SqlParameter("@CellPhone", SqlDbType.VarChar, 20), new SqlParameter("@FirstRequestUrl", SqlDbType.NVarChar, 600), new SqlParameter("@SSQianSysNo", SqlDbType.Int, 4), new SqlParameter("@BirthTime", SqlDbType.DateTime), new SqlParameter("@Gender", SqlDbType.Int, 4), new SqlParameter("@DistrictSysNo", SqlDbType.Int, 4), new SqlParameter("@DR", SqlDbType.Int, 4), new SqlParameter("@TS", SqlDbType.DateTime), }; if (model.Name != AppConst.StringNull) { parameters[0].Value = model.Name; } else { parameters[0].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[0]); if (model.CellPhone != AppConst.StringNull) { parameters[1].Value = model.CellPhone; } else { parameters[1].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[1]); if (model.FirstRequestUrl != AppConst.StringNull) { parameters[2].Value = model.FirstRequestUrl; } else { parameters[2].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[2]); if (model.SSQianSysNo != AppConst.IntNull) { parameters[3].Value = model.SSQianSysNo; } else { parameters[3].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[3]); if (model.BirthTime != AppConst.DateTimeNull) { parameters[4].Value = model.BirthTime; } else { parameters[4].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[4]); if (model.Gender != AppConst.IntNull) { parameters[5].Value = model.Gender; } else { parameters[5].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[5]); if (model.DistrictSysNo != AppConst.IntNull) { parameters[6].Value = model.DistrictSysNo; } else { parameters[6].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[6]); if (model.DR != AppConst.IntNull) { parameters[7].Value = model.DR; } else { parameters[7].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[7]); if (model.TS != AppConst.DateTimeNull) { parameters[8].Value = model.TS; } else { parameters[8].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[8]); return(Convert.ToInt32(SqlHelper.ExecuteScalar(cmd, parameters))); }
/// <summary> /// 更新一条数据 /// </summary> public int Update(AdvUserMod model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update AdvUser set "); strSql.Append("Name=@Name,"); strSql.Append("CellPhone=@CellPhone,"); strSql.Append("FirstRequestUrl=@FirstRequestUrl,"); strSql.Append("SSQianSysNo=@SSQianSysNo,"); strSql.Append("BirthTime=@BirthTime,"); strSql.Append("Gender=@Gender,"); strSql.Append("DistrictSysNo=@DistrictSysNo,"); strSql.Append("DR=@DR,"); strSql.Append("TS=@TS"); strSql.Append(" where SysNo=@SysNo "); SqlCommand cmd = new SqlCommand(strSql.ToString()); SqlParameter[] parameters = { new SqlParameter("@SysNo", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.NVarChar, 40), new SqlParameter("@CellPhone", SqlDbType.VarChar, 20), new SqlParameter("@FirstRequestUrl", SqlDbType.NVarChar, 600), new SqlParameter("@SSQianSysNo", SqlDbType.Int, 4), new SqlParameter("@BirthTime", SqlDbType.DateTime), new SqlParameter("@Gender", SqlDbType.Int, 4), new SqlParameter("@DistrictSysNo", SqlDbType.Int, 4), new SqlParameter("@DR", SqlDbType.Int, 4), new SqlParameter("@TS", SqlDbType.DateTime) }; if (model.SysNo != AppConst.IntNull) { parameters[0].Value = model.SysNo; } else { parameters[0].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[0]); if (model.Name != AppConst.StringNull) { parameters[1].Value = model.Name; } else { parameters[1].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[1]); if (model.CellPhone != AppConst.StringNull) { parameters[2].Value = model.CellPhone; } else { parameters[2].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[2]); if (model.FirstRequestUrl != AppConst.StringNull) { parameters[3].Value = model.FirstRequestUrl; } else { parameters[3].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[3]); if (model.SSQianSysNo != AppConst.IntNull) { parameters[4].Value = model.SSQianSysNo; } else { parameters[4].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[4]); if (model.BirthTime != AppConst.DateTimeNull) { parameters[5].Value = model.BirthTime; } else { parameters[5].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[5]); if (model.Gender != AppConst.IntNull) { parameters[6].Value = model.Gender; } else { parameters[6].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[6]); if (model.DistrictSysNo != AppConst.IntNull) { parameters[7].Value = model.DistrictSysNo; } else { parameters[7].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[7]); if (model.DR != AppConst.IntNull) { parameters[8].Value = model.DR; } else { parameters[8].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[8]); if (model.TS != AppConst.DateTimeNull) { parameters[9].Value = model.TS; } else { parameters[9].Value = System.DBNull.Value; } cmd.Parameters.Add(parameters[9]); return(SqlHelper.ExecuteNonQuery(cmd, parameters)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(AdvUserMod model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into AdvUser("); strSql.Append("Name,CellPhone,FirstRequestUrl,SSQianSysNo,BirthTime,Gender,DistrictSysNo,DR,TS)"); strSql.Append(" values ("); strSql.Append("@Name,@CellPhone,@FirstRequestUrl,@SSQianSysNo,@BirthTime,@Gender,@DistrictSysNo,@DR,@TS)"); strSql.Append(";select SCOPE_IDENTITY()"); SqlCommand cmd = new SqlCommand(strSql.ToString()); SqlParameter[] parameters = { new SqlParameter("@Name",SqlDbType.NVarChar,40), new SqlParameter("@CellPhone",SqlDbType.VarChar,20), new SqlParameter("@FirstRequestUrl",SqlDbType.NVarChar,600), new SqlParameter("@SSQianSysNo",SqlDbType.Int,4), new SqlParameter("@BirthTime",SqlDbType.DateTime), new SqlParameter("@Gender",SqlDbType.Int,4), new SqlParameter("@DistrictSysNo",SqlDbType.Int,4), new SqlParameter("@DR",SqlDbType.Int,4), new SqlParameter("@TS",SqlDbType.DateTime), }; if (model.Name != AppConst.StringNull) parameters[0].Value = model.Name; else parameters[0].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[0]); if (model.CellPhone != AppConst.StringNull) parameters[1].Value = model.CellPhone; else parameters[1].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[1]); if (model.FirstRequestUrl != AppConst.StringNull) parameters[2].Value = model.FirstRequestUrl; else parameters[2].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[2]); if (model.SSQianSysNo != AppConst.IntNull) parameters[3].Value = model.SSQianSysNo; else parameters[3].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[3]); if (model.BirthTime != AppConst.DateTimeNull) parameters[4].Value = model.BirthTime; else parameters[4].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[4]); if (model.Gender != AppConst.IntNull) parameters[5].Value = model.Gender; else parameters[5].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[5]); if (model.DistrictSysNo != AppConst.IntNull) parameters[6].Value = model.DistrictSysNo; else parameters[6].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[6]); if (model.DR != AppConst.IntNull) parameters[7].Value = model.DR; else parameters[7].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[7]); if (model.TS != AppConst.DateTimeNull) parameters[8].Value = model.TS; else parameters[8].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[8]); return Convert.ToInt32(SqlHelper.ExecuteScalar(cmd, parameters)); }
/// <summary> /// 更新一条数据 /// </summary> public int Update(AdvUserMod model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update AdvUser set "); strSql.Append("Name=@Name,"); strSql.Append("CellPhone=@CellPhone,"); strSql.Append("FirstRequestUrl=@FirstRequestUrl,"); strSql.Append("SSQianSysNo=@SSQianSysNo,"); strSql.Append("BirthTime=@BirthTime,"); strSql.Append("Gender=@Gender,"); strSql.Append("DistrictSysNo=@DistrictSysNo,"); strSql.Append("DR=@DR,"); strSql.Append("TS=@TS"); strSql.Append(" where SysNo=@SysNo "); SqlCommand cmd = new SqlCommand(strSql.ToString()); SqlParameter[] parameters = { new SqlParameter("@SysNo",SqlDbType.Int,4), new SqlParameter("@Name",SqlDbType.NVarChar,40), new SqlParameter("@CellPhone",SqlDbType.VarChar,20), new SqlParameter("@FirstRequestUrl",SqlDbType.NVarChar,600), new SqlParameter("@SSQianSysNo",SqlDbType.Int,4), new SqlParameter("@BirthTime",SqlDbType.DateTime), new SqlParameter("@Gender",SqlDbType.Int,4), new SqlParameter("@DistrictSysNo",SqlDbType.Int,4), new SqlParameter("@DR",SqlDbType.Int,4), new SqlParameter("@TS",SqlDbType.DateTime) }; if (model.SysNo != AppConst.IntNull) parameters[0].Value = model.SysNo; else parameters[0].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[0]); if (model.Name != AppConst.StringNull) parameters[1].Value = model.Name; else parameters[1].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[1]); if (model.CellPhone != AppConst.StringNull) parameters[2].Value = model.CellPhone; else parameters[2].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[2]); if (model.FirstRequestUrl != AppConst.StringNull) parameters[3].Value = model.FirstRequestUrl; else parameters[3].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[3]); if (model.SSQianSysNo != AppConst.IntNull) parameters[4].Value = model.SSQianSysNo; else parameters[4].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[4]); if (model.BirthTime != AppConst.DateTimeNull) parameters[5].Value = model.BirthTime; else parameters[5].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[5]); if (model.Gender != AppConst.IntNull) parameters[6].Value = model.Gender; else parameters[6].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[6]); if (model.DistrictSysNo != AppConst.IntNull) parameters[7].Value = model.DistrictSysNo; else parameters[7].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[7]); if (model.DR != AppConst.IntNull) parameters[8].Value = model.DR; else parameters[8].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[8]); if (model.TS != AppConst.DateTimeNull) parameters[9].Value = model.TS; else parameters[9].Value = System.DBNull.Value; cmd.Parameters.Add(parameters[9]); return SqlHelper.ExecuteNonQuery(cmd,parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public AdvUserMod GetModel(int SysNo) { StringBuilder strSql = new StringBuilder(); strSql.Append("select SysNo, Name, CellPhone, FirstRequestUrl, SSQianSysNo, BirthTime, Gender, DistrictSysNo, DR, TS from AdvUser"); strSql.Append(" where SysNo=@SysNo "); SqlParameter[] parameters = { new SqlParameter("@SysNo", SqlDbType.Int,4 ) }; parameters[0].Value = SysNo; AdvUserMod model = new AdvUserMod(); DataSet ds = SqlHelper.ExecuteDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["SysNo"].ToString() != "") { model.SysNo = int.Parse(ds.Tables[0].Rows[0]["SysNo"].ToString()); } model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); model.CellPhone = ds.Tables[0].Rows[0]["CellPhone"].ToString(); model.FirstRequestUrl = ds.Tables[0].Rows[0]["FirstRequestUrl"].ToString(); if (ds.Tables[0].Rows[0]["SSQianSysNo"].ToString() != "") { model.SSQianSysNo = int.Parse(ds.Tables[0].Rows[0]["SSQianSysNo"].ToString()); } if (ds.Tables[0].Rows[0]["BirthTime"].ToString() != "") { model.BirthTime = DateTime.Parse(ds.Tables[0].Rows[0]["BirthTime"].ToString()); } if (ds.Tables[0].Rows[0]["Gender"].ToString() != "") { model.Gender = int.Parse(ds.Tables[0].Rows[0]["Gender"].ToString()); } if (ds.Tables[0].Rows[0]["DistrictSysNo"].ToString() != "") { model.DistrictSysNo = int.Parse(ds.Tables[0].Rows[0]["DistrictSysNo"].ToString()); } if (ds.Tables[0].Rows[0]["DR"].ToString() != "") { model.DR = int.Parse(ds.Tables[0].Rows[0]["DR"].ToString()); } if (ds.Tables[0].Rows[0]["TS"].ToString() != "") { model.TS = DateTime.Parse(ds.Tables[0].Rows[0]["TS"].ToString()); } return model; } else { return null; } }
private string SearchTopic(string PhoneNum) { string ret = ""; AdvUserMod m_user = AdvUserBll.GetInstance().GetModel(PhoneNum); if (m_user.SysNo == AppConst.IntNull)//该手机号未发送过主题 { m_user.CellPhone = PhoneNum; m_user.DR = (int)AppEnum.State.normal; m_user.TS = DateTime.Now; m_user.SysNo = AdvUserBll.GetInstance().Add(m_user); DataTable m_dt = AdvTopicBll.GetInstance().GetTopicList(); int ran = CommonTools.ThrowRandom(0, m_dt.Rows.Count - 1); ret = m_dt.Rows[ran]["Title"].ToString(); TopicSendRecordMod m_record = new TopicSendRecordMod(); m_record.IsReturn = (int)AppEnum.BOOL.False; m_record.TopicSysNo = int.Parse(m_dt.Rows[ran]["SysNo"].ToString()); m_record.UserSysNo = m_user.SysNo; m_record.TS = DateTime.Now; TopicSendRecordBll.GetInstance().Add(m_record); } else//该手机号已发送过主题 { DataTable m_dt = TopicSendRecordBll.GetInstance().GetRecentRecordByUser(m_user.SysNo); DataTable m_total = AdvTopicBll.GetInstance().GetTopicList().Copy(); if (m_dt.Rows.Count < m_total.Rows.Count)//还有没有给该用户发送过的主题 { int choise = 0; string returned = "|"; DataTable m_return = TopicSendRecordBll.GetInstance().GetReturnRecordByUser(m_user.SysNo); for (int i = 0; i < m_return.Rows.Count; i++) { returned += m_return.Rows[i]["Group"].ToString() + "|"; } for (int i = 0; i < m_total.Rows.Count; i++) { bool exsit = false; for (int j = 0; j < m_dt.Rows.Count; j++) { if (m_dt.Rows[j]["TopicSysNo"].ToString() == m_total.Rows[i]["SysNo"].ToString()) { exsit = true; break; } } if (exsit) { continue; } else { choise = i; if (returned.Contains("|" + m_total.Rows[i]["Group"].ToString() + "|")) { break;//如果有之前该用户点击进入过的同类型内容直接选中推送 } } } ret = m_total.Rows[choise]["Title"].ToString(); TopicSendRecordMod m_record = new TopicSendRecordMod(); m_record.IsReturn = (int)AppEnum.BOOL.False; m_record.TopicSysNo = int.Parse(m_total.Rows[choise]["SysNo"].ToString()); m_record.UserSysNo = m_user.SysNo; m_record.TS = DateTime.Now; TopicSendRecordBll.GetInstance().Add(m_record); } else//所有主题都给该用户发送过了 { ret = m_dt.Rows[0]["Title"].ToString();//可优化 TopicSendRecordMod m_record = new TopicSendRecordMod(); m_record.IsReturn = (int)AppEnum.BOOL.False; m_record.TopicSysNo = int.Parse(m_dt.Rows[0]["SysNo"].ToString()); m_record.UserSysNo = m_user.SysNo; m_record.TS = DateTime.Now; TopicSendRecordBll.GetInstance().Add(m_record); } } return(ret); }