You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

665 rivejä
29 KiB

  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Data.SqlClient;
  5. namespace Basic.DAL
  6. {
  7. /// <summary>
  8. /// ���ݷ��ʲ�address
  9. /// </summary>
  10. public partial class address
  11. {
  12. /// <summary>
  13. /// ����һ������
  14. /// </summary>
  15. public int Add(Basic.Model.address model)
  16. {
  17. StringBuilder strSql = new StringBuilder();
  18. strSql.Append("insert into tb_address(");
  19. strSql.Append("user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile)");
  20. strSql.Append(" values (");
  21. strSql.Append("@user_id,@name,@sheng,@shi,@xian,@ssx,@xaddress,@mobile,@phone,@email,@status,@dname,@dxaddress,@dmobile)");
  22. strSql.Append(";select @@IDENTITY");
  23. SqlParameter[] parameters = {
  24. new SqlParameter("@user_id", SqlDbType.Int,10),
  25. new SqlParameter("@name", SqlDbType.NVarChar,50),
  26. new SqlParameter("@sheng", SqlDbType.NVarChar,50),
  27. new SqlParameter("@shi", SqlDbType.NVarChar,50),
  28. new SqlParameter("@xian", SqlDbType.NVarChar,50),
  29. new SqlParameter("@ssx", SqlDbType.NVarChar,255),
  30. new SqlParameter("@xaddress", SqlDbType.NVarChar,255),
  31. new SqlParameter("@mobile", SqlDbType.NVarChar,50),
  32. new SqlParameter("@phone", SqlDbType.NVarChar,50),
  33. new SqlParameter("@email", SqlDbType.NVarChar,100),
  34. new SqlParameter("@status", SqlDbType.Int,10),
  35. new SqlParameter("@dname", SqlDbType.NVarChar,50),
  36. new SqlParameter("@dxaddress", SqlDbType.NVarChar,255),
  37. new SqlParameter("@dmobile", SqlDbType.NVarChar,50)};
  38. parameters[0].Value = model.user_id;
  39. parameters[1].Value = model.name;
  40. parameters[2].Value = model.sheng;
  41. parameters[3].Value = model.shi;
  42. parameters[4].Value = model.xian;
  43. parameters[5].Value = model.ssx;
  44. parameters[6].Value = model.xaddress;
  45. parameters[7].Value = model.mobile;
  46. parameters[8].Value = model.phone;
  47. parameters[9].Value = model.email;
  48. parameters[10].Value = model.status;
  49. parameters[11].Value = model.dname;
  50. parameters[12].Value = model.dxaddress;
  51. parameters[13].Value = model.dmobile;
  52. object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
  53. if (obj == null)
  54. {
  55. return 0;
  56. }
  57. else
  58. {
  59. return Convert.ToInt32(obj);
  60. }
  61. }
  62. /// <summary>
  63. /// ����һ������
  64. /// </summary>
  65. public bool Update(Basic.Model.address model)
  66. {
  67. StringBuilder strSql = new StringBuilder();
  68. strSql.Append("update tb_address set ");
  69. strSql.Append("user_id=@user_id,");
  70. strSql.Append("name=@name,");
  71. strSql.Append("sheng=@sheng,");
  72. strSql.Append("shi=@shi,");
  73. strSql.Append("xian=@xian,");
  74. strSql.Append("ssx=@ssx,");
  75. strSql.Append("xaddress=@xaddress,");
  76. strSql.Append("mobile=@mobile,");
  77. strSql.Append("phone=@phone,");
  78. strSql.Append("email=@email,");
  79. strSql.Append("status=@status,");
  80. strSql.Append("dname=@dname,");
  81. strSql.Append("dxaddress=@dxaddress,");
  82. strSql.Append("dmobile=@dmobile");
  83. strSql.Append(" where id=@id");
  84. SqlParameter[] parameters = {
  85. new SqlParameter("@user_id", SqlDbType.Int,10),
  86. new SqlParameter("@name", SqlDbType.NVarChar,50),
  87. new SqlParameter("@sheng", SqlDbType.NVarChar,50),
  88. new SqlParameter("@shi", SqlDbType.NVarChar,50),
  89. new SqlParameter("@xian", SqlDbType.NVarChar,50),
  90. new SqlParameter("@ssx", SqlDbType.NVarChar,255),
  91. new SqlParameter("@xaddress", SqlDbType.NVarChar,255),
  92. new SqlParameter("@mobile", SqlDbType.NVarChar,50),
  93. new SqlParameter("@phone", SqlDbType.NVarChar,50),
  94. new SqlParameter("@email", SqlDbType.NVarChar,100),
  95. new SqlParameter("@status", SqlDbType.Int,10),
  96. new SqlParameter("@dname", SqlDbType.NVarChar,50),
  97. new SqlParameter("@dxaddress", SqlDbType.NVarChar,255),
  98. new SqlParameter("@dmobile", SqlDbType.NVarChar,50),
  99. new SqlParameter("@id", SqlDbType.Int,4)};
  100. parameters[0].Value = model.user_id;
  101. parameters[1].Value = model.name;
  102. parameters[2].Value = model.sheng;
  103. parameters[3].Value = model.shi;
  104. parameters[4].Value = model.xian;
  105. parameters[5].Value = model.ssx;
  106. parameters[6].Value = model.xaddress;
  107. parameters[7].Value = model.mobile;
  108. parameters[8].Value = model.phone;
  109. parameters[9].Value = model.email;
  110. parameters[10].Value = model.status;
  111. parameters[11].Value = model.dname;
  112. parameters[12].Value = model.dxaddress;
  113. parameters[13].Value = model.dmobile;
  114. parameters[14].Value = model.id;
  115. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  116. if (rows > 0)
  117. {
  118. return true;
  119. }
  120. else
  121. {
  122. return false;
  123. }
  124. }
  125. /// <summary>
  126. /// ɾ��һ������
  127. /// </summary>
  128. public bool Delete(int id)
  129. {
  130. StringBuilder strSql = new StringBuilder();
  131. strSql.Append("delete from tb_address");
  132. strSql.Append(" where id=@id");
  133. SqlParameter[] parameters = {
  134. new SqlParameter("@id", SqlDbType.Int,4)};
  135. parameters[0].Value = id;
  136. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  137. if (rows > 0)
  138. {
  139. return true;
  140. }
  141. else
  142. {
  143. return false;
  144. }
  145. }
  146. /// <summary>
  147. /// �õ�һ������ʵ��
  148. /// </summary>
  149. public Basic.Model.address GetModel(int id)
  150. {
  151. StringBuilder strSql = new StringBuilder();
  152. strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
  153. strSql.Append(" where id=@id");
  154. SqlParameter[] parameters = {
  155. new SqlParameter("@id", SqlDbType.Int,4)};
  156. parameters[0].Value = id;
  157. Basic.Model.address model = new Basic.Model.address();
  158. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  159. if (ds.Tables[0].Rows.Count > 0)
  160. {
  161. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
  162. {
  163. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  164. }
  165. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
  166. {
  167. model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
  168. }
  169. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
  170. {
  171. model.name = ds.Tables[0].Rows[0]["name"].ToString();
  172. }
  173. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
  174. {
  175. model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
  176. }
  177. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
  178. {
  179. model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
  180. }
  181. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
  182. {
  183. model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
  184. }
  185. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
  186. {
  187. model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
  188. }
  189. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
  190. {
  191. model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
  192. }
  193. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
  194. {
  195. model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
  196. }
  197. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
  198. {
  199. model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
  200. }
  201. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
  202. {
  203. model.email = ds.Tables[0].Rows[0]["email"].ToString();
  204. }
  205. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
  206. {
  207. model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
  208. }
  209. //������
  210. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
  211. {
  212. model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
  213. }
  214. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
  215. {
  216. model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
  217. }
  218. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
  219. {
  220. model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
  221. }
  222. return model;
  223. }
  224. else
  225. {
  226. return null;
  227. }
  228. }
  229. /// <summary>
  230. /// �õ�һ������ʵ��
  231. /// </summary>
  232. public Basic.Model.address GetModel(string strUserName)
  233. {
  234. StringBuilder strSql = new StringBuilder();
  235. strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
  236. strSql.Append(" where user_id=(select top 1 id from tb_user where name=@name) and status=1 order by id desc");
  237. SqlParameter[] parameters = {
  238. new SqlParameter("@name", SqlDbType.VarChar,50)};
  239. parameters[0].Value = strUserName;
  240. Basic.Model.address model = new Basic.Model.address();
  241. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  242. if (ds.Tables[0].Rows.Count > 0)
  243. {
  244. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
  245. {
  246. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  247. }
  248. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
  249. {
  250. model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
  251. }
  252. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
  253. {
  254. model.name = ds.Tables[0].Rows[0]["name"].ToString();
  255. }
  256. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
  257. {
  258. model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
  259. }
  260. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
  261. {
  262. model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
  263. }
  264. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
  265. {
  266. model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
  267. }
  268. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
  269. {
  270. model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
  271. }
  272. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
  273. {
  274. model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
  275. }
  276. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
  277. {
  278. model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
  279. }
  280. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
  281. {
  282. model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
  283. }
  284. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
  285. {
  286. model.email = ds.Tables[0].Rows[0]["email"].ToString();
  287. }
  288. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
  289. {
  290. model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
  291. }
  292. //������
  293. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
  294. {
  295. model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
  296. }
  297. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
  298. {
  299. model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
  300. }
  301. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
  302. {
  303. model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
  304. }
  305. return model;
  306. }
  307. else
  308. {
  309. return null;
  310. }
  311. }
  312. /// <summary>
  313. /// �õ�һ������ʵ��
  314. /// </summary>
  315. public Basic.Model.address GetModelByUserId(int user_id)
  316. {
  317. StringBuilder strSql = new StringBuilder();
  318. strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
  319. strSql.Append(" where user_id=@user_id order by status desc,id desc");
  320. SqlParameter[] parameters = {
  321. new SqlParameter("@user_id", SqlDbType.Int,4)};
  322. parameters[0].Value = user_id;
  323. Basic.Model.address model = new Basic.Model.address();
  324. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  325. if (ds.Tables[0].Rows.Count > 0)
  326. {
  327. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
  328. {
  329. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  330. }
  331. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
  332. {
  333. model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
  334. }
  335. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
  336. {
  337. model.name = ds.Tables[0].Rows[0]["name"].ToString();
  338. }
  339. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
  340. {
  341. model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
  342. }
  343. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
  344. {
  345. model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
  346. }
  347. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
  348. {
  349. model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
  350. }
  351. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
  352. {
  353. model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
  354. }
  355. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
  356. {
  357. model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
  358. }
  359. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
  360. {
  361. model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
  362. }
  363. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
  364. {
  365. model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
  366. }
  367. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
  368. {
  369. model.email = ds.Tables[0].Rows[0]["email"].ToString();
  370. }
  371. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
  372. {
  373. model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
  374. }
  375. //������
  376. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
  377. {
  378. model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
  379. }
  380. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
  381. {
  382. model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
  383. }
  384. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
  385. {
  386. model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
  387. }
  388. return model;
  389. }
  390. else
  391. {
  392. return null;
  393. }
  394. }
  395. /// <summary>
  396. /// ����ǰ��������
  397. /// </summary>
  398. public DataSet GetList(int Top, string strWhere, string filedOrder)
  399. {
  400. StringBuilder strSql = new StringBuilder();
  401. strSql.Append("select ");
  402. if (Top > 0)
  403. {
  404. strSql.Append(" top " + Top.ToString());
  405. }
  406. strSql.Append("id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile");
  407. strSql.Append(" from tb_address");
  408. if (strWhere.Trim() != "")
  409. {
  410. strSql.Append(" where " + strWhere);
  411. }
  412. strSql.Append(" order by " + filedOrder);
  413. return DbHelperSQL.Query(strSql.ToString());
  414. }
  415. /// <summary>
  416. /// �Ƿ����ڸü�¼
  417. /// </summary>
  418. public bool Exists(int id)
  419. {
  420. StringBuilder strSql = new StringBuilder();
  421. strSql.Append("select count(1) from tb_address");
  422. strSql.Append(" where id=@id");
  423. SqlParameter[] parameters = {
  424. new SqlParameter("@id", SqlDbType.Int,4)};
  425. parameters[0].Value = id;
  426. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  427. }
  428. /// <summary>
  429. /// �޸�һ������
  430. /// </summary>
  431. public void UpdateField(int id, string strValue)
  432. {
  433. StringBuilder strSql = new StringBuilder();
  434. strSql.Append("update tb_address set " + strValue);
  435. strSql.Append(" where id=" + id);
  436. DbHelperSQL.ExecuteSql(strSql.ToString());
  437. }
  438. //�����ӵ�======================================================================================================================================
  439. /// <summary>
  440. /// �޸�Ĭ�ϵ�ַ
  441. /// </summary>
  442. public void UpdateStatus(int id, int _UserID)
  443. {
  444. StringBuilder strSql = new StringBuilder();
  445. strSql.Append("update tb_address set status=0");
  446. strSql.Append(" where user_id=" + _UserID);
  447. strSql.Append(" update tb_address set status=1");
  448. strSql.Append(" where id=" + id);
  449. DbHelperSQL.ExecuteSql(strSql.ToString());
  450. }
  451. /// <summary>
  452. /// �õ�һ������ʵ��
  453. /// </summary>
  454. public Basic.Model.address GetModel(int id, int user_id)
  455. {
  456. StringBuilder strSql = new StringBuilder();
  457. strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
  458. strSql.Append(" where id=@id and user_id=@user_id");
  459. SqlParameter[] parameters = {
  460. new SqlParameter("@id", SqlDbType.Int,4),
  461. new SqlParameter("@user_id", SqlDbType.Int,4)};
  462. parameters[0].Value = id;
  463. parameters[1].Value = user_id;
  464. Basic.Model.address model = new Basic.Model.address();
  465. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  466. if (ds.Tables[0].Rows.Count > 0)
  467. {
  468. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
  469. {
  470. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  471. }
  472. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
  473. {
  474. model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
  475. }
  476. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
  477. {
  478. model.name = ds.Tables[0].Rows[0]["name"].ToString();
  479. }
  480. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
  481. {
  482. model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
  483. }
  484. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
  485. {
  486. model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
  487. }
  488. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
  489. {
  490. model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
  491. }
  492. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
  493. {
  494. model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
  495. }
  496. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
  497. {
  498. model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
  499. }
  500. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
  501. {
  502. model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
  503. }
  504. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
  505. {
  506. model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
  507. }
  508. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
  509. {
  510. model.email = ds.Tables[0].Rows[0]["email"].ToString();
  511. }
  512. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
  513. {
  514. model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
  515. }
  516. //������
  517. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
  518. {
  519. model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
  520. }
  521. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
  522. {
  523. model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
  524. }
  525. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
  526. {
  527. model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
  528. }
  529. return model;
  530. }
  531. else
  532. {
  533. return null;
  534. }
  535. }
  536. /// <summary>
  537. /// �õ�һ������ʵ��
  538. /// </summary>
  539. public Basic.Model.address GetModel(int user_id, string status)
  540. {
  541. StringBuilder strSql = new StringBuilder();
  542. strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
  543. strSql.Append(" where status=@status and user_id=@user_id");
  544. SqlParameter[] parameters = {
  545. new SqlParameter("@status", SqlDbType.Int,4),
  546. new SqlParameter("@user_id", SqlDbType.Int,4)};
  547. parameters[0].Value = status;
  548. parameters[1].Value = user_id;
  549. Basic.Model.address model = new Basic.Model.address();
  550. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  551. if (ds.Tables[0].Rows.Count > 0)
  552. {
  553. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
  554. {
  555. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  556. }
  557. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
  558. {
  559. model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
  560. }
  561. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
  562. {
  563. model.name = ds.Tables[0].Rows[0]["name"].ToString();
  564. }
  565. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
  566. {
  567. model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
  568. }
  569. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
  570. {
  571. model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
  572. }
  573. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
  574. {
  575. model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
  576. }
  577. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
  578. {
  579. model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
  580. }
  581. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
  582. {
  583. model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
  584. }
  585. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
  586. {
  587. model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
  588. }
  589. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
  590. {
  591. model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
  592. }
  593. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
  594. {
  595. model.email = ds.Tables[0].Rows[0]["email"].ToString();
  596. }
  597. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
  598. {
  599. model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
  600. }
  601. //������
  602. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
  603. {
  604. model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
  605. }
  606. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
  607. {
  608. model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
  609. }
  610. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
  611. {
  612. model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
  613. }
  614. return model;
  615. }
  616. else
  617. {
  618. return null;
  619. }
  620. }
  621. /// <summary>
  622. /// ɾ��һ������
  623. /// </summary>
  624. public bool Delete(int id, int user_id)
  625. {
  626. StringBuilder strSql = new StringBuilder();
  627. strSql.Append("delete from tb_address");
  628. strSql.Append(" where id=@id and user_id=@user_id");
  629. SqlParameter[] parameters = {
  630. new SqlParameter("@id", SqlDbType.Int,4),
  631. new SqlParameter("@user_id", SqlDbType.Int,4)};
  632. parameters[0].Value = id;
  633. parameters[1].Value = user_id;
  634. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  635. if (rows > 0)
  636. {
  637. return true;
  638. }
  639. else
  640. {
  641. return false;
  642. }
  643. }
  644. }
  645. }