/// <summary> /// 更新 /// </summary> /// <param name="allinone_operaterecordview"></param> /// <returns>是否成功</returns> public string GetUpdateStr(AllInOne_OperateRecordView allinone_operaterecordview) { StringBuilder part1 = new StringBuilder(); part1.Append("update allinone_operaterecordview set "); if (allinone_operaterecordview.content != null) { part1.Append("content = @content,"); } if (allinone_operaterecordview.operatorId != null) { part1.Append("operatorId = @operatorId,"); } if (allinone_operaterecordview.autherId != null) { part1.Append("autherId = @autherId,"); } if (allinone_operaterecordview.operateTime != null) { part1.Append("operateTime = @operateTime,"); } if (allinone_operaterecordview.operatorName != null) { part1.Append("operatorName = @operatorName,"); } int n = part1.ToString().LastIndexOf(","); part1.Remove(n, 1); part1.Append(" where id= @id "); return(part1.ToString()); }
/// <summary> /// 插入 /// </summary> /// <param name="allinone_operaterecordview"></param> /// <returns>是否成功</returns> public string GetInsertStr(AllInOne_OperateRecordView allinone_operaterecordview) { StringBuilder part1 = new StringBuilder(); StringBuilder part2 = new StringBuilder(); if (allinone_operaterecordview.content != null) { part1.Append("content,"); part2.Append("@content,"); } if (allinone_operaterecordview.operatorId != null) { part1.Append("operatorId,"); part2.Append("@operatorId,"); } if (allinone_operaterecordview.autherId != null) { part1.Append("autherId,"); part2.Append("@autherId,"); } if (allinone_operaterecordview.operateTime != null) { part1.Append("operateTime,"); part2.Append("@operateTime,"); } if (allinone_operaterecordview.operatorName != null) { part1.Append("operatorName,"); part2.Append("@operatorName,"); } StringBuilder sql = new StringBuilder(); sql.Append("insert into allinone_operaterecordview(").Append(part1.ToString().Remove(part1.Length - 1)).Append(") values (").Append(part2.ToString().Remove(part2.Length - 1)).Append(")"); return(sql.ToString()); }
/// <summary> /// update /// </summary> /// <param name="AllInOne_OperateRecordView"></param> /// <returns></returns> public void Update(AllInOne_OperateRecordView model) { var str = GetUpdateStr(model); var dict = GetParameters(model); SqlHelper.Instance.ExcuteNon(str, dict); }
/// <summary> /// 获取参数 /// </summary> /// <param name="allinone_operaterecordview"></param> /// <returns></returns> public Dictionary <string, string> GetParameters(AllInOne_OperateRecordView allinone_operaterecordview) { Dictionary <string, string> dict = new Dictionary <string, string>(); if (allinone_operaterecordview.id != null) { dict.Add("@id", allinone_operaterecordview.id.ToString()); } if (allinone_operaterecordview.content != null) { dict.Add("@content", allinone_operaterecordview.content.ToString()); } if (allinone_operaterecordview.operatorId != null) { dict.Add("@operatorId", allinone_operaterecordview.operatorId.ToString()); } if (allinone_operaterecordview.autherId != null) { dict.Add("@autherId", allinone_operaterecordview.autherId.ToString()); } if (allinone_operaterecordview.operateTime != null) { dict.Add("@operateTime", allinone_operaterecordview.operateTime.ToString()); } if (allinone_operaterecordview.operatorName != null) { dict.Add("@operatorName", allinone_operaterecordview.operatorName.ToString()); } return(dict); }
/// <summary> /// add /// </summary> /// <param name="AllInOne_OperateRecordView"></param> /// <returns></returns> public int Add(AllInOne_OperateRecordView model) { var str = GetInsertStr(model) + " select @@identity"; var dict = GetParameters(model); return(Convert.ToInt32(SqlHelper.Instance.ExecuteScalar(str, dict))); }