//初始化 public override void Loaded() { DifficultyLevel = "0"; Date1 = DateTime.Now.AddMonths(-1); Date2 = DateTime.Now; Datas = GetAllQCInf(); if (MouldInfo.Key != null) { MouldName = MouldInfo.Mould_Name; //题库 List <T_Question_Collection_ex> questionResult = ExamHandle.TryGetData <T_Question_Collection_ex>( @" SELECT A.* ,B.F_SCORE,B.F_SORT,B.F_VARIABLE ,'' FROM T_QUESTION_COLLECTION A,T_INTEGRANT_QUESTION B WHERE A.F_KEY = B.F_QUESTION_KEY AND B.F_MOULD_KEY = ? ORDER BY A.F_QUESTION", MouldInfo.Key); var DatasExTemp = new List <T_Question_Collection_ex>(questionResult); foreach (T_Question_Collection_ex int_question in DatasExTemp) { DatasEx.Add(int_question); } foreach (T_Question_Collection_ex child in DatasEx) { child.OrderNo = (DatasEx.IndexOf(child) + 1).ToString(); child.Sort = (DatasEx.IndexOf(child)); } } }
//保存该模板的方法 private void SaveMould() { bool result = true; //sql语句列表 var SqlList = new Dictionary <List <string>, string>(); string mouldguid; int scoreTotal = 0; foreach (T_Question_Collection_ex item in DatasEx) { if (!System.Text.RegularExpressions.Regex.IsMatch(item.Score.Trim(), @"^[0-9]+\.{0,1}[0-9]{0,}$")) { Messenger.Default.Send("分数请使用数字!"); return; } if (string.IsNullOrEmpty(item.Variable.Trim())) { Messenger.Default.Send("存在变量未编辑!"); return; } scoreTotal += Convert.ToInt32(item.Score); } if (System.Convert.ToInt32(scoreTotal) != 100) { Messenger.Default.Send("总分不等于100分!"); return; } if (MouldInfo.Key != null) { mouldguid = MouldInfo.Key; SqlList.Add(new List <string> { mouldguid }, @"DELETE FROM T_INTEGRANT_QUESTION WHERE F_MOULD_KEY = ?"); SqlList.Add(new List <string> { MouldName, scoreTotal.ToString(), mouldguid }, @"UPDATE T_MOULD SET F_MOULD_NAME=?,F_SCORE_TOTAL=?,F_DATE=SYSDATE WHERE F_KEY =?"); } else { mouldguid = Guid.NewGuid().ToString("N").ToUpper(); SqlList.Add(new List <string> { mouldguid, MouldName, scoreTotal.ToString() }, SQL.ADDTESTPAPER); } if (DatasEx != null) { foreach (T_Question_Collection_ex item in DatasEx) { item.Sort = DatasEx.IndexOf(item) + 1; if (item.Variable == string.Empty) { item.Variable = "|"; } SqlList.Add( new List <string> { mouldguid, item.Key, item.Score, item.Sort.ToString(), item.Variable }, SQL.AddINTEGRANTQUESTION); } } else { return; } //执行事务处理 result = ExamHandle.TryExecute(SqlList.Values.ToArray(), SqlList.Keys.Select(c => c.ToArray()).ToArray()); if (result) { Messenger.Default.Send("提交成功!"); DatasEx = new ObservableCollection <T_Question_Collection_ex>(); Close(); } else { Messenger.Default.Send("提交失败!"); } }