/// <summary> /// 更新一条数据 /// </summary> public int Update(SqlTransaction sqltran, Entities.SurveyOption model) { SqlParameter[] parameters = { new SqlParameter("@SOID", SqlDbType.Int, 4), new SqlParameter("@SIID", SqlDbType.Int, 4), new SqlParameter("@SQID", SqlDbType.Int, 4), new SqlParameter("@OptionName", SqlDbType.NVarChar, 2000), new SqlParameter("@IsBlank", SqlDbType.Int, 4), new SqlParameter("@Score", SqlDbType.Int, 4), new SqlParameter("@OrderNum", SqlDbType.Int, 4), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUserID", SqlDbType.Int, 4), new SqlParameter("@ModifyTime", SqlDbType.DateTime), new SqlParameter("@ModifyUserID", SqlDbType.Int, 4) }; parameters[0].Value = model.SOID; parameters[1].Value = model.SIID; parameters[2].Value = model.SQID; parameters[3].Value = model.OptionName; parameters[4].Value = model.IsBlank; parameters[5].Value = model.Score; parameters[6].Value = model.OrderNum; parameters[7].Value = model.Status; parameters[8].Value = model.CreateTime; parameters[9].Value = model.CreateUserID; parameters[10].Value = model.ModifyTime; parameters[11].Value = model.ModifyUserID; return(SqlHelper.ExecuteNonQuery(sqltran, CommandType.StoredProcedure, P_SURVEYOPTION_UPDATE, parameters)); }
/// <summary> /// 增加一条数据 /// </summary> public int Insert(Entities.SurveyOption model) { SqlParameter[] parameters = { new SqlParameter("@SOID", SqlDbType.Int, 4), new SqlParameter("@SIID", SqlDbType.Int, 4), new SqlParameter("@SQID", SqlDbType.Int, 4), new SqlParameter("@OptionName", SqlDbType.NVarChar, 2000), new SqlParameter("@IsBlank", SqlDbType.Int, 4), new SqlParameter("@Score", SqlDbType.Int, 4), new SqlParameter("@OrderNum", SqlDbType.Int, 4), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUserID", SqlDbType.Int, 4), new SqlParameter("@ModifyTime", SqlDbType.DateTime), new SqlParameter("@ModifyUserID", SqlDbType.Int, 4) }; parameters[0].Direction = ParameterDirection.Output; parameters[1].Value = model.SIID; parameters[2].Value = model.SQID; parameters[3].Value = model.OptionName; parameters[4].Value = model.IsBlank; parameters[5].Value = model.Score; parameters[6].Value = model.OrderNum; parameters[7].Value = model.Status; parameters[8].Value = model.CreateTime; parameters[9].Value = model.CreateUserID; parameters[10].Value = model.ModifyTime; parameters[11].Value = model.ModifyUserID; SqlHelper.ExecuteNonQuery(CONNECTIONSTRINGS, CommandType.StoredProcedure, P_SURVEYOPTION_INSERT, parameters); return((int)parameters[0].Value); }
private Entities.SurveyOption LoadSingleSurveyOption(DataRow row) { Entities.SurveyOption model = new Entities.SurveyOption(); if (row["SOID"].ToString() != "") { model.SOID = int.Parse(row["SOID"].ToString()); } if (row["SIID"].ToString() != "") { model.SIID = int.Parse(row["SIID"].ToString()); } if (row["SQID"].ToString() != "") { model.SQID = int.Parse(row["SQID"].ToString()); } model.OptionName = row["OptionName"].ToString(); if (row["IsBlank"].ToString() != "") { model.IsBlank = int.Parse(row["IsBlank"].ToString()); } if (row["Score"].ToString() != "") { model.Score = int.Parse(row["Score"].ToString()); } if (row["OrderNum"].ToString() != "") { model.OrderNum = int.Parse(row["OrderNum"].ToString()); } if (row["Status"].ToString() != "") { model.Status = int.Parse(row["Status"].ToString()); } if (row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } if (row["CreateUserID"].ToString() != "") { model.CreateUserID = int.Parse(row["CreateUserID"].ToString()); } if (row["ModifyTime"].ToString() != "") { model.ModifyTime = DateTime.Parse(row["ModifyTime"].ToString()); } if (row["ModifyUserID"].ToString() != "") { model.ModifyUserID = int.Parse(row["ModifyUserID"].ToString()); } if (row["linkid"].ToString() != "") { model.linkid = int.Parse(row["linkid"].ToString()); } return(model); }
public void bindQuestion() { int _sqid; int _soid; int _spiid; int questionType = 0;//问题类型 //1-选项 if (int.TryParse(RequestSOID, out _soid) && int.TryParse(RequestSPIID, out _spiid)) { Entities.SurveyOption model1_surveyOption = BLL.SurveyOption.Instance.GetSurveyOption(_soid); if (model1_surveyOption != null) { Entities.SurveyQuestion model1_question = BLL.SurveyQuestion.Instance.GetSurveyQuestion(int.Parse(model1_surveyOption.SQID.ToString())); if (model1_question != null) { questionStr += model1_question.Ask; questionType = int.Parse(model1_question.AskCategory.ToString()); //问题类型为单选或复选 if (questionType == (int)Entities.AskCategory.RadioT || questionType == (int)Entities.AskCategory.CheckBoxT) { if (model1_surveyOption.IsBlank == 1 && model1_question.AskCategory != (int)Entities.AskCategory.TextT) { questionStr += " -- " + model1_surveyOption.OptionName; } } } } } //2-试题 if (int.TryParse(RequestSQID, out _sqid) && int.TryParse(RequestSPIID, out _spiid)) { Entities.SurveyQuestion model_question = BLL.SurveyQuestion.Instance.GetSurveyQuestion(_sqid); if (model_question != null) { questionStr += model_question.Ask; } } if (questionStr != string.Empty) { //绑定列表内容 bindData(); } }
/// <summary> /// 更新一条数据 /// </summary> public int Update(SqlTransaction sqltran, Entities.SurveyOption model) { return(Dal.SurveyOption.Instance.Update(sqltran, model)); }
/// <summary> /// 更新一条数据 /// </summary> public int Update(Entities.SurveyOption model) { return(Dal.SurveyOption.Instance.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Insert(Entities.SurveyOption model) { return(Dal.SurveyOption.Instance.Insert(model)); }
//单选统计 private string StatQuestionForMultipleChoice(int sqId, int spiId) { StringBuilder strSB = new StringBuilder(); bool isStatByScore = false; Entities.SurveyQuestion question = BLL.SurveyQuestion.Instance.GetSurveyQuestion(sqId); if (question.IsStatByScore == 1) { isStatByScore = true; } DataTable dt = BLL.SurveyQuestion.Instance.StatQuestionForMultipleChoice(sqId, spiId); strSB.Append("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><thead style=\"background:#F2F2F2;\">"); strSB.Append("<th width=\"50%\">选项</th><th width=\"23%\">小计</th><th width=\"27%\">比例</th></thead>"); int surveyPersonNum = BLL.SurveyAnswer.Instance.GetAnswerUserCountBySQID(sqId, spiId); int j = 0; foreach (DataRow dr in dt.Rows) { if (j % 2 == 0) { strSB.Append("<tr>"); } else { strSB.Append("<tr style='background:#F2F2F2;'>"); } Entities.SurveyOption optionInfo = BLL.SurveyOption.Instance.GetSurveyOption(int.Parse(dr["SOID"].ToString())); string blankStr = string.Empty; if ((int)optionInfo.IsBlank == 1) { blankStr = "<a href=\"TextQuestionDetail.aspx?SPIID=" + spiId + "&SOID=" + dr["SOID"].ToString() + "\" target=\"_blank\">【详情】</a>"; } //如果是按分数统计,每个选项后边显示分数 if (isStatByScore) { strSB.Append("<td>" + dr["OptionName"].ToString() + blankStr + "(" + dr["Score"] + "分)" + "</td>"); } else { strSB.Append("<td>" + dr["OptionName"].ToString() + blankStr + "</td>"); } int num = int.Parse(dr["ExamNum"].ToString()); strSB.Append("<td>" + num.ToString() + "</td>"); decimal perOf = 0; if (surveyPersonNum > 0) { perOf = ((decimal)num / (decimal)surveyPersonNum) * 100; } strSB.Append("<td>" + perOf.ToString("0.00") + "%</td>"); strSB.Append("</tr>"); j++; } strSB.Append("<tr style=\"background:#F2F2F2;\"><td style=\"font-weight:bold\">本题有效填写人次</td><td>" + surveyPersonNum + "</td><td> </td></tr>"); //如果是按分数统计,计算此试题的平均分 if (isStatByScore) { int totalScore = BLL.SurveyQuestion.Instance.GetChoiceTotalScoreBySQID(sqId); decimal avgScore = 0; if (surveyPersonNum > 0) { avgScore = (decimal)totalScore / (decimal)surveyPersonNum; } strSB.Append("<tr style=\"background:#F2F2F2;\"><td style=\"font-weight:bold\">本题平均分</td><td>" + avgScore.ToString("0.00") + "</td><td> </td></tr>"); } strSB.Append("</table>"); return(strSB.ToString()); }
//生成新问卷 private void surveyCreateNewQuestionPaper(out string msg) { msg = string.Empty; int _siid; if (int.TryParse(RequestSIID, out _siid)) { //生成新的调查问卷 Entities.SurveyInfo model_newSurveyInfo = new Entities.SurveyInfo(); //生成该调查问卷新的调查问卷试题列表 List <Entities.SurveyQuestion> list_newSurveyQuestion = new List <Entities.SurveyQuestion>(); //生成该调查问卷选项列表 List <Entities.SurveyOption> list_newSurveyOption = new List <Entities.SurveyOption>(); //生成该调查问卷矩阵标题列表 List <Entities.SurveyMatrixTitle> list_newSurveyMatrixTitle = new List <Entities.SurveyMatrixTitle>(); #region 准备数据 Entities.SurveyInfo model_surveyInfo = new Entities.SurveyInfo(); model_surveyInfo = BLL.SurveyInfo.Instance.GetSurveyInfo(_siid); if (model_surveyInfo == null) { msg = "{msg:'未找到该问卷,生成新问卷失败'}"; } //准备 新调查问卷 数据 //判断该问卷是不是之前新生成问卷,如果是,就不再加(新生成问卷) if (model_surveyInfo.Name.Length >= 7) { if (model_surveyInfo.Name.Substring(model_surveyInfo.Name.Length - 7, 7) != "(新生成问卷)") { model_newSurveyInfo.Name = model_surveyInfo.Name + "(新生成问卷)"; } else { model_newSurveyInfo.Name = model_surveyInfo.Name; } } else { model_newSurveyInfo.Name = model_surveyInfo.Name + "(新生成问卷)"; } model_newSurveyInfo.BGID = model_surveyInfo.BGID; model_newSurveyInfo.SCID = model_surveyInfo.SCID; model_newSurveyInfo.Description = model_surveyInfo.Description; model_newSurveyInfo.Status = 0; //未完成 model_newSurveyInfo.IsAvailable = -1; //不可用 model_newSurveyInfo.CreateTime = DateTime.Now; model_newSurveyInfo.CreateUserID = userID; //准备 新调查问卷试题 数据 List <Entities.SurveyQuestion> list_surveyQuestion = new List <Entities.SurveyQuestion>(); list_surveyQuestion = BLL.SurveyQuestion.Instance.GetSurveyQuestionList(_siid); foreach (Entities.SurveyQuestion o in list_surveyQuestion) { Entities.SurveyQuestion model_surveyQuestion = new Entities.SurveyQuestion(); model_surveyQuestion.SQID = o.SQID; model_surveyQuestion.Ask = o.Ask; model_surveyQuestion.AskCategory = o.AskCategory; model_surveyQuestion.ShowColumnNum = o.ShowColumnNum; model_surveyQuestion.MaxTextLen = o.MaxTextLen; model_surveyQuestion.MinTextLen = o.MinTextLen; model_surveyQuestion.Status = 0; model_surveyQuestion.OrderNum = o.OrderNum; model_surveyQuestion.CreateTime = DateTime.Now; model_surveyQuestion.CreateUserID = userID; model_surveyQuestion.IsMustAnswer = o.IsMustAnswer; model_surveyQuestion.IsStatByScore = o.IsStatByScore; list_newSurveyQuestion.Add(model_surveyQuestion); } //准备 新调查问卷选项 数据 List <Entities.SurveyOption> list_surveyOption = new List <Entities.SurveyOption>(); list_surveyOption = BLL.SurveyOption.Instance.GetSurveyOptionList(_siid); foreach (Entities.SurveyOption o in list_surveyOption) { Entities.SurveyOption model_surveyOption = new Entities.SurveyOption(); model_surveyOption.SQID = o.SQID; model_surveyOption.OptionName = o.OptionName; model_surveyOption.IsBlank = o.IsBlank; model_surveyOption.Score = o.Score; model_surveyOption.OrderNum = o.OrderNum; model_surveyOption.Status = 0; model_surveyOption.CreateTime = DateTime.Now; model_surveyOption.CreateUserID = userID; list_newSurveyOption.Add(model_surveyOption); } //准备 新调查问卷矩阵标题 数据 List <Entities.SurveyMatrixTitle> list_surveyMatrixTitle = new List <Entities.SurveyMatrixTitle>(); list_surveyMatrixTitle = BLL.SurveyMatrixTitle.Instance.GetMatrixTitleList(_siid); foreach (Entities.SurveyMatrixTitle o in list_surveyMatrixTitle) { Entities.SurveyMatrixTitle model_surveyMatrixTitle = new Entities.SurveyMatrixTitle(); model_surveyMatrixTitle.SQID = o.SQID; model_surveyMatrixTitle.TitleName = o.TitleName; model_surveyMatrixTitle.Status = 0; model_surveyMatrixTitle.Type = o.Type; model_surveyMatrixTitle.CreateTime = DateTime.Now; model_surveyMatrixTitle.CreateUserID = userID; list_newSurveyMatrixTitle.Add(model_surveyMatrixTitle); } #endregion #region 事务处理 插入 string connectionstrings = ConfigurationUtil.GetAppSettingValue("ConnectionStrings_CC"); SqlConnection connection = new SqlConnection(connectionstrings); connection.Open(); SqlTransaction tran = connection.BeginTransaction("SampleTransaction"); try { //插入调查问卷 int newSIID = BLL.SurveyInfo.Instance.Insert(tran, model_newSurveyInfo); //插入调查问卷试题 int newSQID = 0; int oldSQID = 0; for (int i = 0; i < list_newSurveyQuestion.Count; i++) { oldSQID = list_newSurveyQuestion[i].SQID; list_newSurveyQuestion[i].SIID = newSIID; newSQID = BLL.SurveyQuestion.Instance.Insert(tran, list_newSurveyQuestion[i]); //插入调查问卷选项 for (int j = 0; j < list_newSurveyOption.Count; j++) { if (list_newSurveyOption[j].SQID == oldSQID) { list_newSurveyOption[j].SIID = newSIID; list_newSurveyOption[j].SQID = newSQID; BLL.SurveyOption.Instance.Insert(tran, list_newSurveyOption[j]); } } //插入调查问卷矩阵标题 for (int k = 0; k < list_newSurveyMatrixTitle.Count; k++) { if (list_newSurveyMatrixTitle[k].SQID == oldSQID) { list_newSurveyMatrixTitle[k].SIID = newSIID; list_newSurveyMatrixTitle[k].SQID = newSQID; BLL.SurveyMatrixTitle.Instance.Insert(tran, list_newSurveyMatrixTitle[k]); } } } //插入日志 BLL.Util.InsertUserLog(tran, "【生成新问卷】操作成功,生成调查名称【" + model_newSurveyInfo.Name + "】业务分组ID【" + model_newSurveyInfo.BGID + "】分类ID【" + model_newSurveyInfo.SCID + "】的新问卷"); msg = "{msg:'success'}"; tran.Commit(); } catch (Exception ex) { if (tran.Connection != null) { tran.Rollback(); } msg = ex.Message.ToString(); } finally { connection.Close(); } #endregion } }
private void Submit(out string msg, int userID, out int retSiid) { msg = ""; retSiid = 0; int retsqid = 0; string datainfoStr = DataStr; SurveyInfoData sInfoData = null; sInfoData = (SurveyInfoData)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(datainfoStr, typeof(SurveyInfoData)); #region 验证数据正确性 if (sInfoData != null) { CheckData(sInfoData, out msg); if (msg != "") { return; } } else { msg += "获取数据出错"; return; } #endregion #region 准备数据 #region 定义变量 Entities.SurveyInfo sModel = null; Entities.SurveyQuestion qModel = null; Entities.SurveyOption oModel = null; Entities.SurveyMatrixTitle mModel = null; List <Entities.SurveyQuestion> qList = null; List <Entities.SurveyOption> oList = null; List <Entities.SurveyMatrixTitle> mList = null; List <Entities.SurveyOptionSkipQuestion> skipNewList = new List <SurveyOptionSkipQuestion>(); //要新加入的 List <Entities.SurveyOptionSkipQuestion> skipUpdateList = new List <SurveyOptionSkipQuestion>(); //要更新的 List <Entities.SurveyOptionSkipQuestion> skipDeleteList = new List <SurveyOptionSkipQuestion>(); //要删除的 List <Entities.SurveyQuestion> addQudstionList = new List <SurveyQuestion>(); List <Entities.SurveyOption> addOptionList = new List <SurveyOption>(); List <Entities.SurveyMatrixTitle> addMatrixList = new List <SurveyMatrixTitle>(); List <StringBuilder> listLogStr = new List <StringBuilder>(); //用户操作日志 StringBuilder sblogstr = new StringBuilder(); string logstr = ""; int intVal = 0; int existflog = 0; OptionSkip skipTemp = null; List <OptionSkip> skipListTemp = new List <OptionSkip>(); #endregion if (sInfoData.siid != "" && int.TryParse(sInfoData.siid, out intVal)) { int siid = int.Parse(sInfoData.siid); #region 编辑 #region 获取问卷 sModel = BLL.SurveyInfo.Instance.GetSurveyInfo(siid); #region 判断状态 if ((sModel.Status != 0 && sModel.Status != 1) && Action == "sub") { msg += "当前状态下不允许提交操作"; return; } if (sModel.Status != 0 && Action == "save") { msg += "当前状态下不允许保存操作"; return; } if (sModel.Status != 0 && Action == "preview") // || Action == "preview") { msg += "当前状态下不允许预览操作"; return; } #endregion #endregion #region 获取问题 qList = BLL.SurveyQuestion.Instance.GetSurveyQuestionList(siid); #endregion #region 获取选项 oList = BLL.SurveyOption.Instance.GetSurveyOptionList(siid); #endregion #region 获取矩阵标题 mList = BLL.SurveyMatrixTitle.Instance.GetMatrixTitleList(siid); #endregion if (sModel != null) { #region 修改问卷信息 sModel.Name = sInfoData.name; sModel.BGID = int.Parse(sInfoData.bgid); sModel.SCID = int.Parse(sInfoData.scid); sModel.Description = sInfoData.desc; if (Action == "sub") { sModel.Status = 1; sModel.IsAvailable = 1;//提交后是启用状态 } else { sModel.Status = 0; sModel.IsAvailable = -1;//不是提交,可用状态为空 } #region 记日志 sblogstr = new StringBuilder(); logstr = "更新了调查问卷‘" + sInfoData.name + "’的信息【ID:" + sModel.SIID + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion #endregion #region 修改问题 #region 判断是 新增 or 编辑 or 删除 #region 判断编辑和删除的 foreach (Entities.SurveyQuestion qitem in qList) { existflog = 0; if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.sqid == qitem.SQID.ToString()) { //有,就是编辑 existflog = 1; break; } } } if (existflog == 0) { //在页面传来的对象中没有,是删除 qitem.actionFlog = -1; #region 记日志 sblogstr = new StringBuilder(); logstr = "删除了调查问卷【" + sInfoData.name + "】下的问题‘" + qitem.Ask + "’【SQID:" + qitem.SQID + ",SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } else { qitem.actionFlog = 0; } } #endregion #region 判断新加的问题 if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { existflog = 0; foreach (Entities.SurveyQuestion qitem in qList) { if (qitem.SQID.ToString() == qDataItem.sqid) { existflog = 1; } } if (existflog == 0) { //没找到,就是新加的 qModel = new SurveyQuestion(); qModel.SIID = siid; qModel.Ask = qDataItem.ask; qModel.AskCategory = int.Parse(qDataItem.askcategory); qModel.SQID = int.Parse(qDataItem.sqid); qModel.ShowColumnNum = int.Parse(qDataItem.showcolumnnum); qModel.MaxTextLen = int.Parse(qDataItem.maxtextlen); qModel.MinTextLen = int.Parse(qDataItem.mintextlen); qModel.Status = 0; qModel.OrderNum = int.Parse(qDataItem.ordernum); qModel.CreateTime = DateTime.Now; qModel.CreateUserID = userID; qModel.ModifyTime = DateTime.Now; qModel.ModifyUserID = userID; qModel.IsMustAnswer = int.Parse(qDataItem.IsMustAnswer); qModel.IsStatByScore = int.Parse(qDataItem.IsStatByScore); qModel.QuestionLinkId = int.Parse(qDataItem.QuestionLinkId); addQudstionList.Add(qModel); #region 记日志 sblogstr = new StringBuilder(); logstr = "添加了调查问卷【" + sInfoData.name + "】下的问题‘" + qDataItem.ask + "’【SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } } #endregion #endregion #region 修改编辑的问题 foreach (Entities.SurveyQuestion qitem in qList) { if (qitem.actionFlog == 0) //是编辑 { if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.sqid == qitem.SQID.ToString()) { qitem.Ask = qDataItem.ask; qitem.ShowColumnNum = int.Parse(qDataItem.showcolumnnum); qitem.MaxTextLen = int.Parse(qDataItem.maxtextlen); qitem.MinTextLen = int.Parse(qDataItem.mintextlen); qitem.OrderNum = int.Parse(qDataItem.ordernum); qitem.ModifyTime = DateTime.Now; qitem.ModifyUserID = userID; qitem.IsMustAnswer = int.Parse(qDataItem.IsMustAnswer); qitem.IsStatByScore = int.Parse(qDataItem.IsStatByScore); qitem.QuestionLinkId = int.Parse(qDataItem.QuestionLinkId); } } } } } #endregion #endregion #region 修改选项 #region 判断编辑和删除 foreach (Entities.SurveyOption oItem in oList) { existflog = 0; if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.sqid == oItem.SQID.ToString()) { if (qDataItem.option != null) { foreach (SurveyOptionInfoData oinfoItem in qDataItem.option) { if (oinfoItem.sqid == oItem.SQID.ToString() && oinfoItem.soid == oItem.SOID.ToString()) { existflog = 1;//找到了,就是编辑 break; } } } } } } if (existflog == 1) { //编辑 oItem.actionFlog = 0; } else { //没找到,就是删除 oItem.actionFlog = -1; #region 记日志 sblogstr = new StringBuilder(); logstr = "删除了调查问卷【" + sInfoData.name + "】中的选项‘" + oItem.OptionName + "’【SOID:" + oItem.SOID + ",SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } #endregion #region 判断新增 if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.option != null) { foreach (SurveyOptionInfoData oinfoItem in qDataItem.option) { if (int.Parse(oinfoItem.soid) < 0) { //新增的 oModel = new SurveyOption(); oModel.SOID = int.Parse(oinfoItem.soid); oModel.SIID = siid; oModel.SQID = int.Parse(oinfoItem.sqid); oModel.OptionName = oinfoItem.optionname; oModel.IsBlank = int.Parse(oinfoItem.isblank); oModel.Score = int.Parse(oinfoItem.score); oModel.OrderNum = int.Parse(oinfoItem.ordernum); oModel.Status = 0; oModel.CreateTime = DateTime.Now; oModel.CreateUserID = userID; oModel.ModifyTime = DateTime.Now; oModel.ModifyUserID = userID; oModel.linkid = int.Parse(oinfoItem.linkid); addOptionList.Add(oModel); #region 记日志 sblogstr = new StringBuilder(); logstr = "添加了调查问卷【" + sInfoData.name + "】中的选项‘" + oModel.OptionName + "’【SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } } } } #endregion #region 修改编辑的选项 foreach (Entities.SurveyOption oitem in oList) { if (oitem.actionFlog == 0) //是编辑 { if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.option != null) { foreach (SurveyOptionInfoData oDataItem in qDataItem.option) { if (oDataItem.soid == oitem.SOID.ToString()) { oitem.OptionName = oDataItem.optionname; oitem.IsBlank = int.Parse(oDataItem.isblank); oitem.Score = int.Parse(oDataItem.score); oitem.OrderNum = int.Parse(oDataItem.ordernum); oitem.ModifyTime = DateTime.Now; oitem.ModifyUserID = userID; oitem.linkid = int.Parse(oDataItem.linkid); } } } } } } } #endregion #endregion #region 修改矩阵 #region 判断编辑和删除 foreach (Entities.SurveyMatrixTitle mItem in mList) { existflog = 0;//从页面对象中找 if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.sqid == mItem.SQID.ToString()) { if (qDataItem.matrix != null) { foreach (SurveyMatiexInfoData minfoItem in qDataItem.matrix) { if (minfoItem.sqid == mItem.SQID.ToString() && minfoItem.smtid == mItem.SMTID.ToString()) { existflog = 1;//找到了,就是编辑 break; } } } } } } if (existflog == 1) { //编辑 mItem.actionFlog = 0; } else { //没找到,就是删除 mItem.actionFlog = -1; #region 记日志 sblogstr = new StringBuilder(); logstr = "删除了调查问卷【" + sInfoData.name + "】中的矩阵标题‘" + mItem.TitleName + "’【SMTID:" + mItem.SMTID + ",SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } #endregion #region 判断新增 if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.matrix != null) { foreach (SurveyMatiexInfoData minfoItem in qDataItem.matrix) { if (minfoItem.smtid == "") { //新增的 mModel = new SurveyMatrixTitle(); mModel.SIID = siid; mModel.SQID = int.Parse(minfoItem.sqid); mModel.TitleName = minfoItem.titlename; mModel.Status = 0; mModel.Type = int.Parse(minfoItem.type); mModel.CreateUserID = userID; mModel.CreateTime = DateTime.Now; addMatrixList.Add(mModel); #region 记日志 sblogstr = new StringBuilder(); logstr = "添加了调查问卷【" + sInfoData.name + "】中的矩阵标题‘" + mModel.TitleName + "’【SIID:" + sInfoData.siid + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion } } } } } #endregion #region 修改编辑的矩阵 foreach (Entities.SurveyMatrixTitle mitem in mList) { if (mitem.actionFlog == 0) //是编辑 { if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData qDataItem in sInfoData.questList) { if (qDataItem.matrix != null) { foreach (SurveyMatiexInfoData mDataItem in qDataItem.matrix) { if (mDataItem.smtid == mitem.SMTID.ToString()) { mitem.TitleName = mDataItem.titlename; mitem.Type = int.Parse(mDataItem.type); } } } } } } } #endregion #endregion } else { msg += "没找到相应问卷<br/>"; } #endregion } else { //新增 #region 问卷实体类 sModel = new Entities.SurveyInfo(); sModel.Name = sInfoData.name; sModel.BGID = int.Parse(sInfoData.bgid); sModel.SCID = int.Parse(sInfoData.scid); sModel.Description = sInfoData.desc; if (Action == "sub") { sModel.Status = 1; sModel.IsAvailable = 1;//提交后是启用状态 } else { sModel.Status = 0; sModel.IsAvailable = -1;//不是提交,可用状态为空 } sModel.CreateTime = DateTime.Now; sModel.CreateUserID = userID; #region 记日志 sblogstr = new StringBuilder(); logstr = "添加了调查问卷【" + sInfoData.name + "】"; sblogstr.Append(logstr); listLogStr.Add(sblogstr); #endregion #endregion #region 问卷问题 qList = new List <Entities.SurveyQuestion>(); oList = new List <Entities.SurveyOption>(); mList = new List <Entities.SurveyMatrixTitle>(); if (sInfoData.questList != null) { foreach (SurveyQuestionInfoData item in sInfoData.questList) { #region 问卷问题 qModel = new Entities.SurveyQuestion(); qModel.SQID = int.Parse(item.sqid); qModel.Ask = item.ask; qModel.AskCategory = int.Parse(item.askcategory); qModel.ShowColumnNum = int.Parse(item.showcolumnnum); qModel.MaxTextLen = int.Parse(item.maxtextlen); qModel.MinTextLen = int.Parse(item.mintextlen); qModel.Status = 0; qModel.OrderNum = int.Parse(item.ordernum); qModel.CreateTime = DateTime.Now; qModel.CreateUserID = userID; qModel.ModifyTime = DateTime.Now; qModel.ModifyUserID = userID; qModel.IsMustAnswer = int.Parse(item.IsMustAnswer); qModel.IsStatByScore = int.Parse(item.IsStatByScore); qModel.QuestionLinkId = int.Parse(item.QuestionLinkId); qList.Add(qModel); #endregion #region 问卷选项 if (item.option != null) { foreach (SurveyOptionInfoData oitem in item.option) { if (oitem.sqid == item.sqid) { oModel = new Entities.SurveyOption(); oModel.SOID = int.Parse(oitem.soid); oModel.SQID = int.Parse(oitem.sqid); oModel.OptionName = oitem.optionname; oModel.IsBlank = int.Parse(oitem.isblank); oModel.Score = int.Parse(oitem.score); oModel.OrderNum = int.Parse(oitem.ordernum); oModel.Status = 0; oModel.CreateTime = DateTime.Now; oModel.CreateUserID = userID; oModel.ModifyTime = DateTime.Now; oModel.ModifyUserID = userID; oModel.linkid = int.Parse(oitem.linkid); oList.Add(oModel); } } } #endregion #region 问卷矩阵标题 if (item.matrix != null) { foreach (SurveyMatiexInfoData mitem in item.matrix) { if (mitem.sqid == item.sqid) { mModel = new Entities.SurveyMatrixTitle(); mModel.SQID = int.Parse(mitem.sqid); mModel.TitleName = mitem.titlename; mModel.Status = 0; mModel.Type = int.Parse(mitem.type); mModel.CreateTime = DateTime.Now; mModel.CreateUserID = userID; mList.Add(mModel); } } } #endregion } } #endregion } #endregion #region 建立选项与跳题对照 if (oList != null) { foreach (Entities.SurveyOption oItem in oList) { skipTemp = new OptionSkip(); skipTemp.Soid = oItem.SOID; skipTemp.Sqid = (int)oItem.SQID; skipTemp.LinkId = oItem.linkid; skipListTemp.Add(skipTemp); } } if (addOptionList != null) { foreach (Entities.SurveyOption oItem in addOptionList) { skipTemp = new OptionSkip(); skipTemp.Soid = oItem.SOID; skipTemp.Sqid = (int)oItem.SQID; skipTemp.LinkId = oItem.linkid; skipListTemp.Add(skipTemp); } } #endregion #region 提交事务 string connectionstrings = ConfigurationUtil.GetAppSettingValue("ConnectionStrings_CC"); SqlConnection connection = new SqlConnection(connectionstrings); connection.Open(); SqlTransaction tran = connection.BeginTransaction("SampleTransaction"); try { if (sInfoData.siid != "" && int.TryParse(sInfoData.siid, out intVal)) { //编辑 retSiid = int.Parse(SIID); #region 编辑问卷 BLL.SurveyInfo.Instance.Update(tran, sModel); #endregion #region 编辑问题 #region 除、编辑问题 foreach (Entities.SurveyQuestion qitem in qList) { if (qitem.actionFlog == 0) { //编辑 BLL.SurveyQuestion.Instance.Update(tran, qitem); //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.LinkId == qitem.QuestionLinkId) { skipItem.LinkId = qitem.SQID; } } } else if (qitem.actionFlog == -1) { //删除 retsqid = BLL.SurveyQuestion.Instance.Delete(tran, qitem.SQID); } } #endregion #region 添加问题 foreach (Entities.SurveyQuestion qItem in addQudstionList) { retsqid = BLL.SurveyQuestion.Instance.Insert(tran, qItem); if (retsqid > 0) { //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.Sqid == qItem.SQID)//新增的SQID都是 临时负数 { skipItem.Sqid = retsqid; } if (skipItem.LinkId == qItem.QuestionLinkId) { skipItem.LinkId = retsqid; } } //维护选项的问卷ID foreach (Entities.SurveyOption oItem in addOptionList) { if (oItem.SQID == qItem.SQID) { oItem.SQID = retsqid; } } //维护矩阵的问卷ID foreach (Entities.SurveyMatrixTitle mItem in addMatrixList) { if (mItem.SQID == qItem.SQID) { mItem.SQID = retsqid; } } } else { msg += "添加问题失败"; return; } } #endregion #endregion #region 添加选项 #region 除、编辑选项 foreach (Entities.SurveyOption oItem in oList) { if (oItem.actionFlog == 0) { //编辑选项 BLL.SurveyOption.Instance.Update(tran, oItem); } else if (oItem.actionFlog == -1) { BLL.SurveyOption.Instance.Delete(tran, oItem.SOID); } } #endregion #region 添加选项 foreach (Entities.SurveyOption oItem in addOptionList) { int retSOID = BLL.SurveyOption.Instance.Insert(tran, oItem); if (retSOID > 0) { //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.Soid == oItem.SOID) { skipItem.Soid = retSOID; } } } } #endregion #endregion #region 添加矩阵标题 #region 除、编辑矩阵标题 foreach (Entities.SurveyMatrixTitle mItem in mList) { if (mItem.actionFlog == 0) { //编辑选项 BLL.SurveyMatrixTitle.Instance.Update(tran, mItem); } else if (mItem.actionFlog == -1) { BLL.SurveyMatrixTitle.Instance.Delete(tran, mItem.SMTID); } } #endregion #region 添加矩阵标题 foreach (Entities.SurveyMatrixTitle mItem in addMatrixList) { BLL.SurveyMatrixTitle.Instance.Insert(tran, mItem); } #endregion #endregion } else { #region 保存问卷 retSiid = BLL.SurveyInfo.Instance.Insert(tran, sModel); #endregion #region 保存问题 foreach (SurveyQuestion qitem in qList) { qitem.SIID = retSiid; retsqid = BLL.SurveyQuestion.Instance.Insert(tran, qitem); //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.Sqid == qitem.SQID)//新增的SQID都是 临时负数 { skipItem.Sqid = retsqid; } if (skipItem.LinkId == qitem.QuestionLinkId) { skipItem.LinkId = retsqid; } } #region 保存问题选项 foreach (SurveyOption oitem in oList) { if (oitem.SQID == qitem.SQID) { oitem.SIID = retSiid; oitem.SQID = retsqid; int retSoid = BLL.SurveyOption.Instance.Insert(tran, oitem); //维护临时对照表 foreach (OptionSkip skipItem in skipListTemp) { if (skipItem.Soid == oitem.SOID) { skipItem.Soid = retSoid; } } } } #endregion #region 保存矩阵标题 foreach (SurveyMatrixTitle mitem in mList) { if (mitem.SQID == qitem.SQID) { mitem.SIID = retSiid; mitem.SQID = retsqid; BLL.SurveyMatrixTitle.Instance.Insert(tran, mitem); } } #endregion } #endregion } #region 更新选项跳题对照表 foreach (OptionSkip item in skipListTemp) { Entities.SurveyOptionSkipQuestion curskipModel = null; curskipModel = BLL.SurveyOptionSkipQuestion.Instance.GetModelBySoid(item.Soid); if (curskipModel != null) { //存在跳题 if (item.LinkId == 0) { skipDeleteList.Add(curskipModel); } else { if (curskipModel.SQID != item.LinkId) { //如果跳题有改变 curskipModel.SQID = item.LinkId; skipUpdateList.Add(curskipModel); // BLL.SurveyOptionSkipQuestion.Instance.Update(tran,curskipModel); } } } else { //不存在 if (item.LinkId != 0) { //,就插入 curskipModel = new SurveyOptionSkipQuestion(); curskipModel.SOID = item.Soid; curskipModel.SQID = item.LinkId; curskipModel.Status = 0; skipNewList.Add(curskipModel); // BLL.SurveyOptionSkipQuestion.Instance.Insert(tran,curskipModel); } } } foreach (Entities.SurveyOptionSkipQuestion item in skipDeleteList) { BLL.SurveyOptionSkipQuestion.Instance.Delete(tran, item.RecID); } foreach (Entities.SurveyOptionSkipQuestion item in skipUpdateList) { BLL.SurveyOptionSkipQuestion.Instance.Update(tran, item); } foreach (Entities.SurveyOptionSkipQuestion item in skipNewList) { BLL.SurveyOptionSkipQuestion.Instance.Insert(tran, item); } #endregion #region 保存用户操作日志 foreach (StringBuilder sbStr in listLogStr) { BLL.Util.InsertUserLog(tran, sbStr.ToString()); } #endregion tran.Commit(); } catch (Exception ex) { if (tran.Connection != null) { tran.Rollback(); } msg = ex.Message.ToString(); } finally { connection.Close(); } #endregion }