public JsonResult SaveExaminationLogging(ExaminationLog examinationLog) { try { var token = _tokenValidator.Validate(HttpContext); if (!token.Success) { return(Json(new ReturnData <string> { Success = false, NotAuthenticated = true, Message = $"Unauthorized:-{token.Message}", })); } _context.ExaminationLogs.Add(examinationLog); _context.SaveChanges(); return(Json(new ReturnData <string> { Success = true, Message = "Logs save successfully" })); } catch (Exception ex) { return(Json(new ReturnData <string> { Success = false, Message = "There was a problem when saving logs " + ex.Message })); } }
/// <summary> /// 编辑员工考试成绩信息 /// </summary> /// <param name="user"></param> /// <param name="error"></param> /// <returns></returns> public static bool EditExaminationLog(ExaminationLog examinationlog, ref string error) { sql = string.Format(@" select user_id from pm_user where user_name='{0}'", examinationlog.Name); string name = SqlHelper.GetScalar(sql); sql = string.Format(@" update ExaminationLog set Score='{0}', LeaderScore='{1}',TotalScore='{2}',Operation='{3}',WorkAttendance='{4}',WorkState='{5}', Teamwork='{6}',RejectsProduct='{7}',Security='{8}',Remark='{9}' where year='{10}' and month='{11}' and name='{12}' ", examinationlog.Score, examinationlog.LeaderScore, examinationlog.TotalScore, examinationlog.Operation, examinationlog.WorkAttendance, examinationlog.WorkState, examinationlog.Teamwork, examinationlog.RejectsProduct, examinationlog.Security, examinationlog.Remark, examinationlog.Year, examinationlog.Month, name); return(SqlHelper.ExecuteSql(sql, ref error)); }
private void LoadPage() { string sql = string.Empty; string error = string.Empty; if (ToolManager.CheckQueryString("Name") && ToolManager.CheckQueryString("Year") && ToolManager.CheckQueryString("Month")) { string name = Server.UrlDecode(ToolManager.GetQueryString("Name")); sql = string.Format(@" select e.Year,e.Month,pu.USER_NAME as Name,e.Score,e.LeaderScore, e.Operation,e.WorkAttendance,e.WorkState,e.Teamwork, e.RejectsProduct,e.Security, e.TotalScore,e.Remark from ExaminationLog e left join PM_USER pu on e.Name=pu.USER_ID where year='{0}' and month='{1}' and pu.USER_NAME='{2}' ", ToolManager.GetQueryString("Year"), ToolManager.GetQueryString("Month"), name); ExaminationLog examinationlog = ExaminationLogManager.ConvertDataTableToModel(sql); this.lblYear.Text = examinationlog.Year; this.lblMonth.Text = examinationlog.Month; this.lblName.Text = examinationlog.Name; this.drpName.SelectedValue = examinationlog.Name; this.txtScore.Text = examinationlog.Score.ToString(); this.txtLeaderScore.Text = examinationlog.LeaderScore.ToString(); this.txtTotalScore.Text = examinationlog.TotalScore.ToString(); this.txtOperation.Text = examinationlog.Operation.ToString(); this.lbWorkAttendance.Text = examinationlog.WorkAttendance.ToString(); this.txtWorkState.Text = examinationlog.WorkState.ToString(); this.txtTeamwork.Text = examinationlog.Teamwork.ToString(); this.txtRejectsProduct.Text = examinationlog.RejectsProduct.ToString(); this.txtSecurity.Text = examinationlog.Security.ToString(); this.txtRemark.Text = examinationlog.Remark; btnSubmit.Text = "修改"; this.txtWorkAttendance.Visible = false; drpYear.Visible = false; drpMonth.Visible = false; drpName.Visible = false; lblMonth.Visible = false; lblMonth.Visible = true; lblYear.Visible = true; lblName.Visible = true; } else { btnSubmit.Text = "添加"; lblMonth.Visible = false; lblYear.Visible = false; lblName.Visible = false; } }
/// <summary> /// DataTable 转对象 /// </summary> /// <param name="sql"></param> /// <returns></returns> public static ExaminationLog ConvertDataTableToModel(string sql) { error = string.Empty; DataTable dt = SqlHelper.GetTable(sql, ref error); DataRow dr = dt.Rows[0]; ExaminationLog examinationlog = new ExaminationLog(); examinationlog.Year = dr["Year"] == null ? "" : dr["Year"].ToString(); examinationlog.Month = dr["Month"] == null ? "" : dr["Month"].ToString(); examinationlog.Name = dr["Name"] == null ? "" : dr["Name"].ToString(); examinationlog.Score = Convert.ToDecimal(dr["Score"] == null ? "" : dr["Score"].ToString()); examinationlog.LeaderScore = Convert.ToDecimal(dr["LeaderScore"] == null ? "" : dr["LeaderScore"].ToString()); examinationlog.TotalScore = Convert.ToDecimal(dr["TotalScore"] == null ? "" : dr["TotalScore"].ToString()); examinationlog.Operation = Convert.ToDecimal(dr["Operation"] == null ? "" : dr["Operation"].ToString()); examinationlog.WorkAttendance = Convert.ToDecimal(dr["WorkAttendance"] == null ? "" : dr["WorkAttendance"].ToString()); examinationlog.WorkState = Convert.ToDecimal(dr["WorkState"] == null ? "" : dr["WorkState"].ToString()); examinationlog.Teamwork = Convert.ToDecimal(dr["Teamwork"] == null ? "" : dr["Teamwork"].ToString()); examinationlog.RejectsProduct = Convert.ToDecimal(dr["RejectsProduct"] == null ? "" : dr["RejectsProduct"].ToString()); examinationlog.Security = Convert.ToDecimal(dr["Security"] == null ? "" : dr["Security"].ToString()); examinationlog.Remark = dr["Remark"] == null ? "" : dr["Remark"].ToString(); return(examinationlog); }
protected void btnSubmit_Click(object sender, EventArgs e) { string error = string.Empty; Model.ExaminationLog examinationlog = new ExaminationLog(); //examinationlog.Year = this.drpYear.SelectedValue; //examinationlog.Month = this.drpMonth.SelectedValue; //examinationlog.Name = this.drpName.SelectedValue; //examinationlog.WorkAttendance = Convert.ToDecimal(this.txtWorkAttendance.Text); examinationlog.Score = Convert.ToDecimal(this.txtScore.Text); examinationlog.LeaderScore = Convert.ToDecimal(this.txtLeaderScore.Text); examinationlog.TotalScore = Convert.ToDecimal(this.txtTotalScore.Text); examinationlog.TotalScore = Convert.ToDecimal(Request.Form["txtTotalScore"].ToString()); examinationlog.Operation = Convert.ToDecimal(this.txtOperation.Text); examinationlog.WorkState = Convert.ToDecimal(this.txtWorkState.Text); examinationlog.Teamwork = Convert.ToDecimal(this.txtTeamwork.Text); examinationlog.RejectsProduct = Convert.ToDecimal(this.txtRejectsProduct.Text); examinationlog.Security = Convert.ToDecimal(this.txtSecurity.Text); examinationlog.Remark = this.txtRemark.Text; bool result = false; if (btnSubmit.Text.Equals("添加")) { if (string.IsNullOrEmpty(this.drpYear.Text) || string.IsNullOrEmpty(this.drpMonth.Text) || string.IsNullOrEmpty(this.drpName.Text)) { lbSubmit.Text = "请将带*号的内容填写完整!"; return; } string sql = string.Format(@" select * from ExaminationLog where YEAR='{0}' and MONTH='{1}' and Name='{2}'", examinationlog.Year, examinationlog.Month, examinationlog.Name); DataTable dt = SqlHelper.GetTable(sql); if (dt.Rows.Count > 0) { lbSubmit.Text = "当前年份、月份,已有该用户信息,请重新填写!"; return; } result = ExaminationLogManager.AddExaminationLog(examinationlog, ref error); lbSubmit.Text = result == true ? "添加成功!" : "添加失败,原因:" + error; if (result) { Tool.WriteLog(Tool.LogType.Operating, "增加员工考试成绩信息" + examinationlog.Id, "增加成功"); ToolCode.Tool.ResetControl(this.Controls); return; } else { Tool.WriteLog(Tool.LogType.Operating, "增加员工考试成绩信息" + examinationlog.Id, "增加失败!原因:" + error); return; } } else { examinationlog.Year = this.lblYear.Text.Trim(); examinationlog.Month = this.lblMonth.Text.Trim(); examinationlog.Name = this.lblName.Text.Trim(); examinationlog.WorkAttendance = Convert.ToDecimal(this.lbWorkAttendance.Text.Trim()); result = ExaminationLogManager.EditExaminationLog(examinationlog, ref error); lbSubmit.Text = result == true ? "修改成功!" : "修改失败:原因:" + error; if (result) { Tool.WriteLog(Tool.LogType.Operating, "编辑员工考试成绩信息维护" + examinationlog.Id, "编辑成功"); return; } else { Tool.WriteLog(Tool.LogType.Operating, "编辑员工考试成绩信息维护" + examinationlog.Id, "编辑失败!原因:" + error); return; } } }