UserManage.asmx.cs
上传用户:jxqhsy
上传日期:2020-12-31
资源大小:1793k
文件大小:35k
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Text;
- namespace SFGS.Web
- {
- /// <summary>
- /// UserManage 的摘要说明
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
- // [System.Web.Script.Services.ScriptService]
- public class UserManage : System.Web.Services.WebService
- {
- /// <summary>
- /// 创建管理员用户
- /// </summary>
- /// <param name="userName"></param>
- /// <param name="userPwd"></param>
- /// <param name="beizhu"></param>
- /// <returns></returns>
- [WebMethod]
- public bool AddUser(string userName, string userPwd, string beizhu)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Admin where UserName='" + userName.ToString().Replace("'", "''") + "'");
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- cmd.Dispose();
- if (count > 0) return false;//如果已存用户返回false;
- cmd = db.GetSqlStringCommond(
- "INSERT INTO Admin VALUES ('" +
- userName.ToString().Replace("'", "''") + "','" +
- userPwd.ToString().Replace("'", "''") + "','" +
- beizhu.ToString().Replace("'", "''") + "')");
- db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 管理员登录
- /// </summary>
- /// <returns></returns>
- [WebMethod]
- public bool LoginAdmin(string userName, string userPwd)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Admin where UserName='" + userName.ToString().Replace("'", "''") + "' AND PassWord='" + userPwd.ToString().Replace("'", "''") + "'");
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- if (count > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- dr.Close();
- dr.Dispose();
- db.Close();
- cmd.Dispose();
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 更新用户表
- /// </summary>
- /// <param name="userName"></param>
- /// <param name="userPwd"></param>
- /// <returns></returns>
- [WebMethod]
- public bool UpdateUser(string userName, string userPwd)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Admin where UserName='" + userName.ToString().Replace("'", "''") + "'");
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- cmd.Dispose();
- if (count <= 0) return false;//如果用户不存在则返回false;
- cmd = db.GetSqlStringCommond("update admin set PassWord='" + userPwd.ToString().Replace("'", "''") + "' where UserName='" + userName.ToString().Replace("'", "''") + "'");
- int number = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- if (number > 0)
- return true;
- else
- return false;
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 删除指定用户
- /// </summary>
- /// <param name="userName"></param>
- /// <returns></returns>
- [WebMethod]
- public bool DeleteUser(string userName)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Admin where UserName='" + userName.ToString().Replace("'", "''") + "'");
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- cmd.Dispose();
- if (count <= 0) return false;//如果用户不存在则返回false;
- cmd = db.GetSqlStringCommond("delete from Admin where UserName='" + userName.ToString().Replace("'", "''") + "'");
- int number = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- if (number > 0)
- return true;
- else
- return false;
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 更新题目表
- /// </summary>
- /// <param name="ID"></param>
- /// <param name="SurveyID"></param>
- /// <param name="text"></param>
- /// <param name="OptionA"></param>
- /// <param name="OptionB"></param>
- /// <param name="OptionC"></param>
- /// <param name="OptionD"></param>
- /// <returns></returns>
- [WebMethod]
- public bool UpdateQuestion(string ID, string SurveyID, string text, string OptionA, string OptionB, string OptionC, string OptionD)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Question where ID=" + ID.ToString().Replace("'", "''"));
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- cmd.Dispose();
- if (count <= 0) return false;//如果问题不存在返回false;
- cmd = db.GetSqlStringCommond("update Question set " +
- "SurveyID=" + SurveyID.ToString().Replace("'", "''") + "," +
- "Text='" + text.ToString().Replace("'", "''") + "'," +
- "OptionA='" + OptionA.ToString().Replace("'", "''") + "'," +
- "OptionB='" + OptionB.ToString().Replace("'", "''") + "'," +
- "OptionC='" + OptionC.ToString().Replace("'", "''") + "'," +
- "OptionD='" + OptionD.ToString().Replace("'", "''") + "' " +
- "where ID=" + ID.ToString().Replace("'", "''")
- );
- int number = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- if (number > 0)
- return true;
- else
- return false;
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 添加新问题
- /// </summary>
- /// <param name="SurveyID"></param>
- /// <param name="text"></param>
- /// <param name="OptionA"></param>
- /// <param name="OptionB"></param>
- /// <param name="OptionC"></param>
- /// <param name="OptionD"></param>
- /// <returns></returns>
- [WebMethod]
- public bool AddQuestion(string SurveyID, string text, string OptionA, string OptionB, string OptionC, string OptionD)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Survey where ID=" + SurveyID.ToString().Replace("'", "''"));
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- dr = null;
- cmd.Dispose();
- if (count <= 0) return false;//如果调查表中不存在ID为SurveyID的记录则返回false;
- count = 0;
- cmd = db.GetSqlStringCommond("select * from Question where SurveyID=" + SurveyID.ToString().Replace("'", "''") + " and Text='" + text.ToString().Replace("'", "''") + "'");
- dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- cmd.Dispose();
- if (count > 0) return false;//如果问题已存在则返回false;
- cmd = db.GetSqlStringCommond("insert into Question values(" +
- SurveyID.ToString().Replace("'", "''") + ",'" +
- text.ToString().Replace("'", "''") + "','" +
- OptionA.ToString().Replace("'", "''") + "','" +
- OptionB.ToString().Replace("'", "''") + "','" +
- OptionC.ToString().Replace("'", "''") + "','" +
- OptionD.ToString().Replace("'", "''") + "')");
- int number = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- if (number > 0)
- return true;
- else
- return false;
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 删除指定题目
- /// </summary>
- /// <param name="ID"></param>
- /// <returns></returns>
- [WebMethod]
- public bool DeleteQuestion(string ID)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Question where ID=" + ID.ToString().Replace("'", "''"));
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- dr = null;
- cmd.Dispose();
- if (count <= 0) return false;//如果调查表中不存在ID为SurveyID的记录则返回false;
- cmd = db.GetSqlStringCommond("delete from Question where ID=" + ID.ToString().Replace("'", "''"));
- int number = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- if (number > 0)
- return true;
- else
- return false;
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 读取指定调查的问题
- /// </summary>
- /// <param name="SurveyID"></param>
- /// <returns></returns>
- [WebMethod]
- public string ReadQuestion(string SurveyID)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Question where SurveyID=" + SurveyID.ToString().Replace("'", "''"));
- System.Data.DataSet ds = db.ExecuteDataSet(cmd);
- if (ds.Tables[0].Rows.Count <= 0)
- {
- return "";
- }
- System.Text.StringBuilder sb = new StringBuilder();
- sb.Append("<?xml version="1.0" encoding="utf-8" ?>");
- sb.Append("<Questions>");
- foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
- {
- sb.Append("<Question>");
- sb.Append("<ID>");
- sb.Append(dr["ID"].ToString());
- sb.Append("</ID>");
- sb.Append("<SurveyID>");
- sb.Append(dr["SurveyID"].ToString());
- sb.Append("</SurveyID>");
- sb.Append("<Text>");
- sb.Append(dr["Text"].ToString());
- sb.Append("</Text>");
- sb.Append("<OptionA>");
- sb.Append(dr["OptionA"].ToString());
- sb.Append("</OptionA>");
- sb.Append("<OptionB>");
- sb.Append(dr["OptionB"].ToString());
- sb.Append("</OptionB>");
- sb.Append("<OptionC>");
- sb.Append(dr["OptionC"].ToString());
- sb.Append("</OptionC>");
- sb.Append("<OptionD>");
- sb.Append(dr["OptionD"].ToString());
- sb.Append("</OptionD>");
- sb.Append("</Question>");
- }
- sb.Append("</Questions>");
- ds.Dispose();
- cmd.Dispose();
- db.Close();
- return sb.ToString();
- }
- catch (System.Exception ex)
- {
- return "";
- }
- }
- /// <summary>
- /// 更新指定ID的调查表
- /// </summary>
- /// <param name="ID"></param>
- /// <param name="Name"></param>
- /// <param name="Description"></param>
- /// <param name="Date"></param>
- /// <param name="IsCurrentSurvey"></param>
- /// <returns></returns>
- [WebMethod]
- public bool UpdateSurvey(string ID, string Name, string Description, string Date, string IsCurrentSurvey)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Survey where ID=" + ID.ToString().Replace("'", "''"));
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- cmd.Dispose();
- cmd = null;
- if (count <= 0) return false;
- cmd = db.GetSqlStringCommond("update Survey set " +
- "Name='" + Name.ToString().Replace("'", "''") + "'," +
- "Description='" + Description.ToString().Replace("'", "''") + "'," +
- "Date='" + Date.ToString().Replace("'", "''") + "'," +
- "IsCurrentSurvey='" + IsCurrentSurvey.ToString().Replace("'", "''") + "'" +
- " where ID=" + ID.ToString().Replace("'", "''"));
- int number = db.ExecuteNonQuery(cmd);
- if (number > 0)
- return true;
- else
- return false;
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 添加新的调查
- /// </summary>
- /// <param name="Name"></param>
- /// <param name="Description"></param>
- /// <param name="Date"></param>
- /// <param name="IsCurrentSurvey"></param>
- /// <returns></returns>
- [WebMethod]
- public bool AddSurvey(string Name, string Description, string Date, string IsCurrentSurvey)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Survey where Name='" + Name.ToString().Replace("'", "''") + "'");
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- cmd.Dispose();
- cmd = null;
- if (count > 0) return false;//如果该记录已经存在
- cmd = db.GetSqlStringCommond("insert into Survey values(" +
- "'" + Name.ToString().Replace("'", "''") + "'," +
- "'" + Description.ToString().Replace("'", "''") + "'," +
- "'" + Date.ToString().Replace("'", "''") + "'," +
- "'" + IsCurrentSurvey.ToString().Replace("'", "''") + "')" +
- "");
- int number = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- if (number > 0)
- return true;
- else
- return false;
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 删除指定ID的调查记录,及其关联的题目记录
- /// </summary>
- /// <param name="ID"></param>
- /// <returns></returns>
- [WebMethod]
- public bool DeleteSurvey(string ID)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Survey where ID=" + ID.ToString().Replace("'", "''"));
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- cmd.Dispose();
- cmd = null;
- if (count <= 0) return false;
- cmd = db.GetSqlStringCommond("delete from Survey where ID=" + ID.ToString().Replace("'", "''"));
- int number1 = db.ExecuteNonQuery(cmd);
- cmd.Dispose();
- cmd = db.GetSqlStringCommond("delete from Question where SurveyID=" + ID.ToString().Replace("'", "''"));
- int number2 = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- if (number1 > 0 || number2 > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 取指定ID的调查
- /// </summary>
- /// <param name="ID"></param>
- /// <returns></returns>
- [WebMethod]
- public string ReadSurvey(string ID)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Survey where ID=" + ID.ToString().Replace("'", "''"));
- System.Data.DataSet ds = db.ExecuteDataSet(cmd);
- if (ds.Tables[0].Rows.Count <= 0)
- {
- return "";
- }
- System.Text.StringBuilder sb = new StringBuilder();
- sb.Append("<?xml version="1.0" encoding="utf-8" ?>");
- sb.Append("<Surveys>");
- foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
- {
- sb.Append("<Survey>");
- sb.Append("<ID>");
- sb.Append(dr["ID"].ToString());
- sb.Append("</ID>");
- sb.Append("<Name>");
- sb.Append(dr["Name"].ToString());
- sb.Append("</Name>");
- sb.Append("<Description>");
- sb.Append(dr["Description"].ToString());
- sb.Append("</Description>");
- sb.Append("<Date>");
- sb.Append(dr["Date"].ToString());
- sb.Append("</Date>");
- sb.Append("<IsCurrentSurvey>");
- sb.Append(dr["IsCurrentSurvey"].ToString());
- sb.Append("</IsCurrentSurvey>");
- sb.Append("</Survey>");
- }
- sb.Append("</Surveys>");
- ds.Dispose();
- cmd.Dispose();
- db.Close();
- return sb.ToString();
- }
- catch (System.Exception ex)
- {
- return "";
- }
- }
- /// <summary>
- /// 取指定ID的调查
- /// </summary>
- /// <param name="ID"></param>
- /// <returns></returns>
- [WebMethod]
- public string ReadAllSurvey()
- {
- try
- {
- int count = 0;
- string response = "";
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Survey");
- System.Data.DataSet ds = db.ExecuteDataSet(cmd);
- if (ds.Tables[0].Rows.Count <= 0)
- {
- return "";
- }
- System.Text.StringBuilder sb = new StringBuilder();
- sb.Append("<?xml version="1.0" encoding="utf-8" ?>");
- sb.Append("<Surveys>");
- foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
- {
- cmd = db.GetSqlStringCommond("select count(*) from Response where QuestionID =(select TOP 1 ID from Question where SurveyID =" + dr["ID"].ToString() + ")");
- System.Data.DataSet ds1= db.ExecuteDataSet(cmd);
- if (ds1.Tables[0].Rows.Count<=0)
- {
- response = "0";
- }
- else
- {
- response = ds1.Tables[0].Rows[0][0].ToString();
- }
- sb.Append("<Survey>");
- sb.Append("<ID>");
- sb.Append(dr["ID"].ToString());
- sb.Append("</ID>");
- sb.Append("<Name>");
- sb.Append(dr["Name"].ToString());
- sb.Append("</Name>");
- sb.Append("<Description>");
- sb.Append(dr["Description"].ToString());
- sb.Append("</Description>");
- sb.Append("<Responses>");
- sb.Append(response);
- sb.Append("</Responses>");
- sb.Append("<Date>");
- sb.Append(dr["Date"].ToString());
- sb.Append("</Date>");
- sb.Append("<IsCurrentSurvey>");
- sb.Append(dr["IsCurrentSurvey"].ToString());
- sb.Append("</IsCurrentSurvey>");
- sb.Append("</Survey>");
- }
- sb.Append("</Surveys>");
- ds.Dispose();
- cmd.Dispose();
- db.Close();
- return sb.ToString();
- }
- catch (System.Exception ex)
- {
- return "";
- }
- }
- [WebMethod]
- public bool UpdateResponse()
- {
- return false;
- }
- /// <summary>
- /// 添加记录
- /// </summary>
- /// <param name="QuestionID"></param>
- /// <param name="Selection"></param>
- /// <returns></returns>
- [WebMethod]
- public bool AddResponse(string QuestionID, string Selection)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Question where ID=" + QuestionID.ToString());
- System.Data.Common.DbDataReader dr = db.ExecuteReader(cmd);
- while (dr.Read() == true)
- {
- count++;
- }
- dr.Close();
- dr.Dispose();
- cmd.Dispose();
- cmd = null;
- if (count <= 0) return false;
- cmd = db.GetSqlStringCommond("insert into Response values(" +
- QuestionID.ToString() + ",'" +
- Selection.ToString().Replace("'", "''") +
- "')");
- int number = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- if (number > 0) return true;
- else return false;
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 删除指定ID的记录
- /// </summary>
- /// <param name="ID"></param>
- /// <returns></returns>
- [WebMethod]
- public bool DeleteResponse(string ID)
- {
- try
- {
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("delete from Response where ID=" + ID.ToString());
- int number = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- if (number > 0) return true;
- else return false;
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- [WebMethod]
- public string PercentResponse(string SurveyID)
- {
- try
- {
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select * from Question where SurveyID=" + SurveyID.ToString());
- System.Data.DataSet ds = db.ExecuteDataSet(cmd);
- if (ds.Tables[0].Rows.Count <= 0)
- {
- return "";//如果没有找到,则返回空
- }
- System.Text.StringBuilder sb = new StringBuilder();
- sb.Append("<?xml version="1.0" encoding="utf-8" ?>");
- sb.Append("<Percents>");
- foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
- {
- int count = 0;
- int countA = 0;
- int countB = 0;
- int countC = 0;
- int countD = 0;
- System.Data.DataSet tmpDs;
- sb.Append("<Percent>");
- sb.Append("<ID>");
- sb.Append(dr["ID"].ToString());
- sb.Append("</ID>");
- cmd = db.GetSqlStringCommond("select * from Response where QuestionID=" + dr["ID"].ToString());
- tmpDs = db.ExecuteDataSet(cmd);
- count = tmpDs.Tables[0].Rows.Count;
- if (count <= 0)
- {
- sb.Append("<A>0</A><B>0</B><C>0</C><D>0</D>");
- }
- else
- {
- cmd = db.GetSqlStringCommond("select * from Response where QuestionID=" + dr["ID"].ToString() + " and (Selection='a' or Selection='A')");
- tmpDs = db.ExecuteDataSet(cmd);
- countA = tmpDs.Tables[0].Rows.Count;
- cmd = db.GetSqlStringCommond("select * from Response where QuestionID=" + dr["ID"].ToString() + " and (Selection='b' or Selection='B')");
- tmpDs = db.ExecuteDataSet(cmd);
- countB = tmpDs.Tables[0].Rows.Count;
- cmd = db.GetSqlStringCommond("select * from Response where QuestionID=" + dr["ID"].ToString() + " and (Selection='c' or Selection='C')");
- tmpDs = db.ExecuteDataSet(cmd);
- countC = tmpDs.Tables[0].Rows.Count;
- cmd = db.GetSqlStringCommond("select * from Response where QuestionID=" + dr["ID"].ToString() + " and (Selection='d' or Selection='D')");
- tmpDs = db.ExecuteDataSet(cmd);
- countD = tmpDs.Tables[0].Rows.Count;
- sb.Append("<A>");
- sb.Append(Convert.ToString((float)countA / count * 100));
- sb.Append("</A>");
- sb.Append("<B>");
- sb.Append(Convert.ToString((float)countB / count * 100));
- sb.Append("</B>");
- sb.Append("<C>");
- sb.Append(Convert.ToString((float)countC / count * 100));
- sb.Append("</C>");
- sb.Append("<D>");
- sb.Append(Convert.ToString((float)countD / count * 100));
- sb.Append("</D>");
- }
- sb.Append("</Percent>");
- }
- sb.Append("</Percents>");
- return sb.ToString();
- }
- catch (System.Exception ex)
- {
- return "";
- }
- }
- /// <summary>
- /// 读当前调查名
- /// </summary>
- /// <returns></returns>
- [WebMethod]
- public string ReadCurrentSurvey()
- {
- try
- {
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select TOP 1 Name from Survey where IsCurrentSurvey='1'");
- System.Data.DataSet ds = db.ExecuteDataSet(cmd);
- if (ds.Tables[0].Rows.Count<=0)
- {
- return "";
- }
- return ds.Tables[0].Rows[0]["Name"].ToString();
- }
- catch (System.Exception ex)
- {
- return "";
- }
- }
- /// <summary>
- /// 根据调查标题设置当前调查
- /// </summary>
- /// <param name="Name"></param>
- /// <returns></returns>
- [WebMethod]
- public bool WriteCurrentSurvey(string Name)
- {
- try
- {
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("update Survey set IsCurrentSurvey='0'");
- db.ExecuteNonQuery(cmd);
- cmd = db.GetSqlStringCommond("update Survey set IsCurrentSurvey='1' where Name='" + Name.ToString().Replace("'", "''") + "'");
- int number=db.ExecuteNonQuery(cmd);
- cmd.Dispose();
- db.Close();
- if (number>0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (System.Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 联系我们
- /// </summary>
- /// <param name="userName"></param>
- /// <param name="userPwd"></param>
- /// <param name="beizhu"></param>
- /// <returns></returns>
- [WebMethod]
- public bool ContactUS(string name, string age, string query)
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = null;
- if (count > 0) return false;//如果已存用户返回false;
- cmd = db.GetSqlStringCommond(
- "INSERT INTO ContactUS VALUES ('" +
- name.ToString().Replace("'", "''") + "','" +
- age.ToString().Replace("'", "''") + "','" +
- query.ToString().Replace("'", "''") + "')");
- int i = db.ExecuteNonQuery(cmd);
- db.Close();
- cmd.Dispose();
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- [WebMethod]
- public string ReadMaxSurvey()
- {
- try
- {
- int count = 0;
- DAL.DBHelper db = new DAL.DBHelper();
- System.Data.Common.DbCommand cmd = db.GetSqlStringCommond("select max(id) as id from Survey");
- System.Data.DataSet ds = db.ExecuteDataSet(cmd);
- if (ds.Tables[0].Rows.Count < 1)
- {
- return "";
- }
- ds.Dispose();
- cmd.Dispose();
- db.Close();
- string id = "";
- try
- {
- id = ds.Tables[0].Rows[0]["id"].ToString();
- }
- catch
- {
- return "";
- }
- return id;
- }
- catch (System.Exception ex)
- {
- return "false";
- }
- }
- }
- }