Naireclass.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Services;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. using ServiceReference;
  9. /// <summary>
  10. ///Naireclass 的摘要说明
  11. /// </summary>
  12. public class Naireclass
  13. {
  14. private static string constr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["constr"].ToString();
  15. public Naireclass()
  16. {
  17. //
  18. //TODO: 在此处添加构造函数逻辑
  19. //
  20. }
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. /// <param name="uid"></param>
  25. /// <param name="nid"></param>
  26. /// <returns></returns>
  27. public static bool IsHasCarry(string uid, string nid)
  28. {
  29. SqlConnection con = new SqlConnection(constr);
  30. con.Open();
  31. DataTable dt = new DataTable();
  32. SqlDataAdapter sda = new SqlDataAdapter("SELECT ID FROM Q_Answer WHERE Uid=" + uid + " AND Nid=" + nid + "", con);
  33. sda.Fill(dt);
  34. con.Close();
  35. if (dt.Rows.Count > 0)
  36. {
  37. return true;
  38. }
  39. else
  40. {
  41. return false;
  42. }
  43. }
  44. /// <summary>
  45. ///
  46. /// </summary>
  47. /// <param name="uid"></param>
  48. /// <param name="nid"></param>
  49. /// <returns></returns>
  50. public static string backnum(string sqls)
  51. {
  52. SqlConnection con = new SqlConnection(constr);
  53. con.Open();
  54. DataTable dt = new DataTable();
  55. SqlDataAdapter sda = new SqlDataAdapter(sqls, con);
  56. sda.Fill(dt);
  57. con.Close();
  58. if (dt.Rows.Count > 0)
  59. {
  60. return dt.Rows[0]["count"].ToString() ;
  61. }
  62. else
  63. {
  64. return "0";
  65. }
  66. }
  67. /// <summary>
  68. ///
  69. /// </summary>
  70. /// <param name="sqls"></param>
  71. /// <returns></returns>
  72. public static DataTable backdatas(string sqls)
  73. {
  74. SqlConnection con = new SqlConnection(constr);
  75. con.Open();
  76. DataTable dt = new DataTable();
  77. SqlDataAdapter sda = new SqlDataAdapter(sqls, con);
  78. sda.Fill(dt);
  79. con.Close();
  80. return dt;
  81. }
  82. /// <summary>
  83. ///
  84. /// </summary>
  85. /// <param name="username"></param>
  86. /// <param name="password"></param>
  87. /// <returns></returns>
  88. public static bool checkusername(string username, string password)
  89. {
  90. SqlConnection con = new SqlConnection(constr);
  91. con.Open();
  92. DataTable dt = new DataTable();
  93. SqlDataAdapter sda = new SqlDataAdapter("SELECT ID FROM Q_User WHERE name='" + username + "' AND psword='" + password + "'", con);
  94. sda.Fill(dt);
  95. con.Close();
  96. if (dt.Rows.Count > 0)
  97. {
  98. return true;
  99. }
  100. else
  101. {
  102. return false;
  103. }
  104. }
  105. public static int RecordResult(string uid, string nid, string val)
  106. {
  107. SqlConnection con = new SqlConnection(constr);
  108. con.Open();
  109. SqlCommand cmd = new SqlCommand("exec sp_NaireAnswer " + uid + "," + nid + ",'" + val + "'", con);
  110. int i = cmd.ExecuteNonQuery();
  111. con.Close();
  112. return i;
  113. }
  114. /// <summary>
  115. ///
  116. /// </summary>
  117. /// <param name="ROWGUID"></param>
  118. /// <returns></returns>
  119. public static string CheckROWGUID(string ROWGUID)
  120. {
  121. SqlConnection con = new SqlConnection(constr);
  122. con.Open();
  123. DataTable dt = new DataTable();
  124. SqlDataAdapter sda = new SqlDataAdapter("SELECT ID,ROWGUID FROM Q_Naire WHERE ROWGUID='" + ROWGUID + "'", con);
  125. sda.Fill(dt);
  126. con.Close();
  127. if (dt.Rows.Count > 0)
  128. {
  129. return dt.Rows[0]["ID"].ToString();
  130. }
  131. else
  132. {
  133. IPowerMettersService services= new PowerMettersServiceClient();
  134. con.Open();
  135. SqlCommand cmd = new SqlCommand("insert into Q_Naire(ROWGUID,title,descr) values('" + ROWGUID + "','" + services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "") + "','" + services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "") + "')", con); ///services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "")
  136. //SqlCommand cmd = new SqlCommand("insert into Q_Naire(ROWGUID,title,descr) values('" + ROWGUID + "','" + ROWGUID + "','" + ROWGUID + "')", con); ///services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "")
  137. int num= cmd.ExecuteNonQuery();
  138. con.Close();
  139. if (num > 0)
  140. {
  141. con.Open();
  142. DataTable dts = new DataTable();
  143. SqlDataAdapter sdas = new SqlDataAdapter("SELECT ID,ROWGUID FROM Q_Naire WHERE ROWGUID='" + ROWGUID + "'", con);
  144. sdas.Fill(dts);
  145. con.Close();
  146. return dts.Rows[0]["ID"].ToString();
  147. }
  148. else
  149. {
  150. return "0";
  151. }
  152. }
  153. }
  154. public static string CheckROWGUIDone(string ROWGUID)
  155. {
  156. SqlConnection con = new SqlConnection(constr);
  157. con.Open();
  158. DataTable dt = new DataTable();
  159. SqlDataAdapter sda = new SqlDataAdapter("SELECT ID,ROWGUID FROM Q_Naire WHERE ROWGUID='" + ROWGUID + "'", con);
  160. sda.Fill(dt);
  161. con.Close();
  162. if (dt.Rows.Count > 0)
  163. {
  164. return dt.Rows[0]["ID"].ToString();
  165. }
  166. else
  167. {
  168. IPowerMettersService services = new PowerMettersServiceClient();
  169. con.Open();
  170. //SqlCommand cmd = new SqlCommand("insert into Q_Naire(ROWGUID,title,descr) values('" + ROWGUID + "','" + services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "") + "','" + services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "") + "')", con); ///services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "")
  171. SqlCommand cmd = new SqlCommand("insert into Q_Naire(ROWGUID,title,descr) values('" + ROWGUID + "','" + ROWGUID + "','" + ROWGUID + "')", con); ///services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "")
  172. int num = cmd.ExecuteNonQuery();
  173. con.Close();
  174. if (num > 0)
  175. {
  176. con.Open();
  177. DataTable dts = new DataTable();
  178. SqlDataAdapter sdas = new SqlDataAdapter("SELECT ID,ROWGUID FROM Q_Naire WHERE ROWGUID='" + ROWGUID + "'", con);
  179. sdas.Fill(dts);
  180. con.Close();
  181. return dts.Rows[0]["ID"].ToString();
  182. }
  183. else
  184. {
  185. return "0";
  186. }
  187. }
  188. }
  189. public static string CheckROWGUIDones(string ROWGUID,string q_name)
  190. {
  191. SqlConnection con = new SqlConnection(constr);
  192. con.Open();
  193. DataTable dt = new DataTable();
  194. SqlDataAdapter sda = new SqlDataAdapter("SELECT ID,ROWGUID FROM Q_Naire WHERE ROWGUID='" + ROWGUID + "'", con);
  195. sda.Fill(dt);
  196. con.Close();
  197. if (dt.Rows.Count > 0)
  198. {
  199. return dt.Rows[0]["ID"].ToString();
  200. }
  201. else
  202. {
  203. IPowerMettersService services = new PowerMettersServiceClient();
  204. con.Open();
  205. //SqlCommand cmd = new SqlCommand("insert into Q_Naire(ROWGUID,title,descr) values('" + ROWGUID + "','" + services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "") + "','" + services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "") + "')", con); ///services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "")
  206. SqlCommand cmd = new SqlCommand("insert into Q_Naire(ROWGUID,title,descr) values('" + ROWGUID + "','" + q_name + "','" + q_name + "')", con); ///services.GetPowerMattersDetailByRowID(ROWGUID).QL_NAME.Replace("$", "")
  207. int num = cmd.ExecuteNonQuery();
  208. con.Close();
  209. if (num > 0)
  210. {
  211. con.Open();
  212. DataTable dts = new DataTable();
  213. SqlDataAdapter sdas = new SqlDataAdapter("SELECT ID,ROWGUID FROM Q_Naire WHERE ROWGUID='" + ROWGUID + "'", con);
  214. sdas.Fill(dts);
  215. con.Close();
  216. return dts.Rows[0]["ID"].ToString();
  217. }
  218. else
  219. {
  220. return "0";
  221. }
  222. }
  223. }
  224. public static string CheckROWGUIDS(string ROWGUID)
  225. {
  226. SqlConnection con = new SqlConnection(constr);
  227. con.Open();
  228. DataTable dt = new DataTable();
  229. SqlDataAdapter sda = new SqlDataAdapter("SELECT ID,ROWGUID FROM Q_Naire WHERE ROWGUID='" + ROWGUID + "'", con);
  230. sda.Fill(dt);
  231. con.Close();
  232. if (dt.Rows.Count > 0)
  233. {
  234. return dt.Rows[0]["ID"].ToString();
  235. }
  236. else
  237. {
  238. return "0";
  239. }
  240. }
  241. public static string getcutnum(string nid)
  242. {
  243. string cutnum="";
  244. SqlConnection con = new SqlConnection(constr);
  245. con.Open();
  246. DataTable dt = new DataTable();
  247. SqlDataAdapter sda = new SqlDataAdapter("SELECT floor(count(id)/6) as cutnum FROM Q_Answer WHERE Nid=" + nid + "", con);
  248. sda.Fill(dt);
  249. con.Close();
  250. if (dt.Rows.Count > 0)
  251. {
  252. cutnum=dt.Rows[0]["cutnum"].ToString();
  253. }
  254. else
  255. {
  256. cutnum="";
  257. }
  258. return cutnum;
  259. }
  260. }