public static bool Insert(Evaluator[] model, ref string e) { int count = model.Length; for (int i = 0; i < count; i++) { string sql = "insert into tb_Evaluator values(" + "@uiID,@EvaluatedID,@relation,@pass,@status)"; SqlParameter[] parameters = { new SqlParameter("@uiID", SqlDbType.VarChar,10), new SqlParameter("@EvaluatedID",SqlDbType.VarChar,10), new SqlParameter("@relation", SqlDbType.VarChar,10), new SqlParameter("@pass", SqlDbType.Int,4), new SqlParameter("@status", SqlDbType.Int,4) }; parameters[0].Value = model[i].UiID; parameters[1].Value = model[i].EvaluatedID; parameters[2].Value = model[i].Relation; parameters[3].Value = model[i].Pass; parameters[4].Value = model[i].Status; string exception = db.InsertExec(sql, parameters); if (exception != "" && exception != null) { e = exception; return false; } } return true; }
//退回,同时要更新User Userinfo public static bool Update3(Evaluator model, ref string e) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_Evaluator set "); strSql.Append("pass=@pass"); strSql.Append(" where uiID=@uiID and EvaluatedID=@EvaluatedID"); SqlParameter[] parameters = { new SqlParameter("@uiID", SqlDbType.VarChar,10), new SqlParameter("@EvaluatedID",SqlDbType.VarChar,10), new SqlParameter("@relation", SqlDbType.VarChar,10), new SqlParameter("@pass", SqlDbType.Int,4) }; parameters[0].Value = model.UiID; parameters[1].Value = model.EvaluatedID; parameters[2].Value = model.Relation; parameters[3].Value = model.Pass; //查找Evaluator表,如果考评人姓名等于UiID只有一人,就更新user表 List<Evaluator> evaluators = new List<Evaluator>(); if (EvaluatorBLL.Select1(ref evaluators, model.UiID, 1, ref e)) { //更新User表, if (model.Pass == 0) { string UID = model.UiID; UserBLL.Delete(UID, ref e); } } //更新Evaluator表 e = db.QueryExec(strSql.ToString(), parameters); if (e != "" && e != null) { return false; } return true; }
//更新考评人名单 public static bool Update2(Evaluator model, ref string e) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_Evaluator set "); strSql.Append("relation=@relation,"); strSql.Append("uiID=@uiID"); strSql.Append(" where EvaluatedID=@EvaluatedID and pass=@pass"); SqlParameter[] parameters = { new SqlParameter("@uiID", SqlDbType.VarChar,10), new SqlParameter("@EvaluatedID",SqlDbType.VarChar,10), new SqlParameter("@relation", SqlDbType.VarChar,10), new SqlParameter("@pass", SqlDbType.Int,4), }; parameters[0].Value = model.UiID; parameters[1].Value = model.EvaluatedID; parameters[2].Value = model.Relation; parameters[3].Value = model.Pass; e = db.QueryExec(strSql.ToString(), parameters); if (e != "" && e != null) { return false; } return true; }
//更新通过,同时要更新User public static bool Update1(Evaluator model, ref string e) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_Evaluator set "); strSql.Append("pass=@pass"); strSql.Append(" where uiID=@uiID and EvaluatedID=@EvaluatedID"); SqlParameter[] parameters = { new SqlParameter("@pass", SqlDbType.Int,4), new SqlParameter("@uiID", SqlDbType.VarChar,10), new SqlParameter("@EvaluatedID",SqlDbType.VarChar,10) }; parameters[0].Value = model.Pass; parameters[1].Value = model.UiID; parameters[2].Value = model.EvaluatedID; //更新Evaluator表 e = db.QueryExec(strSql.ToString(), parameters); if (e != "" && e != null) { return false; } //更新User表 if (model.Pass == 1) { List<User> users = new List<User>(); if (UserBLL.Select(model.UiID, ref users, ref e)) { e = ""; User user = new Model.User(); user = users.ElementAt(0); user.UType = user.UType.Remove(3, 1).Insert(3, "1"); if (!UserBLL.Update(user, ref e)) { return false; } } else { e = ""; User[] user = new User[1]; user[0] = new User(); user[0].UID = model.UiID; user[0].UType = "00010";//考评者 if (!UserBLL.Insert(user, ref e)) { return false; } } if (e != "" && e != null) { return false; } } else { List<Evaluator> evaluators = new List<Evaluator>(); if (EvaluatorBLL.Select1(ref evaluators, model.UiID, 1, ref e)) { //更新User表, string UID = model.UiID; UserBLL.Delete(UID, ref e); } } return true; }
public static bool Select(ref List<Evaluator> model, ref string e, string sql) { DataTable table = new DataTable(); table = db.QueryDataTable(sql, ref e); if (table != null && table.Rows.Count > 0) { for (int i = 0; i < table.Rows.Count; i++) { Evaluator evaluator = new Evaluator(); evaluator.UiID = (string)table.Rows[i][0]; evaluator.EvaluatedID = (string)table.Rows[i][1]; evaluator.Relation = (string)table.Rows[i][2]; evaluator.Pass = (int)table.Rows[i][3]; evaluator.Status = (int)table.Rows[i][4]; model.Add(evaluator); } return true; } else { if (e != "" && e != null) return false; e = "考评人名单尚未制定"; return false; } }
protected void Submit(object sender, EventArgs e) { exception = ""; string strData = JsonChose.Value; List<tempui> userData = JSON.ScriptDeserialize<List<tempui>>(strData); Evaluator[] model = new Evaluator[userData.Count]; for (int i = 0; i < userData.Count; i++) { tempui userinfo = new tempui(); userinfo = userData.ElementAt(i); model[i] = new Evaluator(); model[i].UiID = userinfo.EvID; model[i].EvaluatedID = UserID.Value; model[i].Pass = 0; model[i].Relation = userinfo.Relation; } if (EvaluatorBLL.Insert(model, ref exception)) { Errors.Value = "提交成功!"; this.Chose.Value = "submit"; ClientScript.RegisterStartupScript(this.GetType(), "", "tanchuang()", true); return; } else { if (exception != "" || exception != null) { Errors.Value = exception; this.Chose.Value = "submit"; ClientScript.RegisterStartupScript(this.GetType(), "", "tanchuang()", true); return; } } }