/// <summary> /// 获得数据列表 /// </summary> public List <tb_document> GetList(tb_document model, ref int total) { List <tb_document> list; StringBuilder strSql = new StringBuilder(); StringBuilder whereSql = new StringBuilder(" where 1 = 1 "); strSql.Append(" select ROW_NUMBER() OVER(ORDER BY id desc) AS RID, * from tb_document "); if (!String.IsNullOrEmpty(model.title)) { whereSql.Append(" and title=@title"); } if (!String.IsNullOrEmpty(model.content)) { whereSql.Append(" and content=@content"); } if (model.addtime != null) { whereSql.Append(" and addtime=@addtime"); } strSql.Append(whereSql); string CountSql = "SELECT COUNT(1) as RowsCount FROM (" + strSql.ToString() + ") AS CountList"; string pageSqlStr = "select * from ( " + strSql.ToString() + " ) as Temp_PageData where Temp_PageData.RID BETWEEN {0} AND {1}"; pageSqlStr = string.Format(pageSqlStr, (model.PageSize * (model.PageIndex - 1) + 1).ToString(), (model.PageSize * model.PageIndex).ToString()); using (IDbConnection conn = DapperHelper.OpenConnection()) { list = conn.Query <tb_document>(pageSqlStr, model)?.ToList(); total = conn.ExecuteScalar <int>(CountSql, model); } return(list); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(tb_document model) { StringBuilder strSql = new StringBuilder(); StringBuilder setSql = new StringBuilder(); strSql.Append("update tb_document set "); if (!String.IsNullOrEmpty(model.title)) { setSql.Append("title=@title,"); } if (!String.IsNullOrEmpty(model.content)) { setSql.Append("content=@content,"); } if (model.addtime != null) { setSql.Append("addtime=@addtime,"); } strSql.Append(setSql.ToString().TrimEnd(',')); strSql.Append(" where id=@id "); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
/// <summary> /// 内容管理 列表 /// </summary> public ActionResult documentList(tb_document model) { int count = 0; ViewBag.documentList = ddocument.GetList(model, ref count); ViewBag.page = Utils.ShowPage(count, model.PageSize, model.PageIndex, 5); return(View()); }
/// <summary> /// 得到一个对象实体 /// </summary> public tb_document GetInfo(tb_document model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from tb_document"); strSql.Append(" where id=@id "); using (IDbConnection conn = DapperHelper.OpenConnection()) { model = conn.Query <tb_document>(strSql.ToString(), model)?.FirstOrDefault(); } return(model); }
/// <summary> /// 更新数据 /// 作者:章建国 /// </summary> /// <param name="model">需要更新的模型</param> /// <returns></returns> public string UpdateDoc(tb_document model) { string flag = "0"; try { if (model != null && model.id > 0) { model.doc_UpdateDate = DateTime.Now; model.doc_UpdateUser = CurrentUserInfo.PersonnelID; #region tb_documentHistory添加历史数据 var documentHistory = new tb_document_History(); documentHistory.direct_Id = model.direct_Id; documentHistory.doc_Code = model.doc_Code; documentHistory.doc_CreateDate = model.doc_CreateDate; documentHistory.doc_CreateUser = model.doc_CreateUser; documentHistory.doc_Guid = model.doc_Guid; documentHistory.doc_Id = model.id; documentHistory.doc_KeyWord = model.doc_KeyWord; documentHistory.doc_Name = model.doc_Name; documentHistory.doc_Path = model.doc_Path; documentHistory.doc_Revo = model.doc_Revo; documentHistory.doc_Size = model.doc_Size; documentHistory.doc_Source = model.doc_Source; documentHistory.doc_Status = model.doc_Status; documentHistory.doc_Type = model.doc_Type; documentHistory.doc_UpdateDate = model.doc_UpdateDate; documentHistory.doc_UpdateUser = model.doc_UpdateUser; documentHistory.doc_URL = model.doc_URL; documentHistory.isDelete = model.isDelete; documentHistory.remark = model.remark; documentHistory.temp1 = model.temp1; documentHistory.temp2 = model.temp2; tb_document_HistoryBLL _docbllhistory = new tb_document_HistoryBLL(); _docbllhistory.Add(documentHistory); #endregion if (_docbll.Update(model)) { flag = "1"; } } } catch { flag = "0"; } return(flag); }
/// <summary> /// 跳转至更新页面 /// 作者:章建国 /// </summary> /// <param name="id">主键ID</param> /// <returns></returns> public ActionResult surfUpdateDoc(int id) { tb_document model = new tb_document(); try { if (id == 0) { string _code = ""; try { string doc_Type = Session["doc_Type"].ToString(); int count = _docbll.GetModelList(" doc_Type = '" + doc_Type + "'").Count + 1; switch (doc_Type) { case "体系文件": _code = "TX000" + count; break; case "工作手册": _code = "GZ000" + count; break; case "安全管理": _code = "AQ000" + count; break; case "成本管理": _code = "CB000" + count; break; } } catch { } model.doc_Code = _code; } else { model = _docbll.GetModel(id); } ViewData["cbo_zhuangtai"] = GetcboStatus(); return(View("UpdateDoc", model)); } catch (Exception) { return(View("UpdateDoc")); } }
public ActionResult doDocInfo(int id, int pid, string ptext) { ViewData["cbo_zhuangtai"] = GetcboStatus(); tb_document model = new tb_document(); if (id > 0) { model = _docbll.GetModel(id); } int count = _docbll.GetModelList(" doc_Type = '文档管理'").Count + 1; string _code = "WD000" + count; model.direct_Id = pid; ViewBag.ptext = ptext; ViewBag._code = _code; return(View(model)); }
/// <summary> /// 内容管理 保存 /// </summary> public JsonResult documentSave(tb_document model) { if (model == null) { return(ResultTool.jsonResult(false, "参数错误!")); } if (!String.IsNullOrEmpty(model.id)) { bool boolResult = ddocument.Update(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "更新失败!")); } else { model.id = Guid.NewGuid().ToString("N"); bool boolResult = ddocument.Add(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "添加失败!")); } }
public void UpdateDocument(tb_document doc) { using (MySqlConnection _connection = new MySqlConnection(connStr)) { MySqlCommand sqlCmd = new MySqlCommand(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = "UPDATE tbl_document SET main_procces = @main, core_proccess = @core, proccess = @proccess, lob = @lob WHERE no_doc= @no_doc"; sqlCmd.Connection = _connection; sqlCmd.Parameters.AddWithValue("@main", doc.main_proccess); sqlCmd.Parameters.AddWithValue("@core", doc.core_proccess); sqlCmd.Parameters.AddWithValue("@proccess", doc.proccess); sqlCmd.Parameters.AddWithValue("@lob", doc.lob); _connection.Open(); int rowUpdatd = sqlCmd.ExecuteNonQuery(); _connection.Close(); } }
/// <summary> /// 是否存在该记录 /// </summary> public bool Exists(tb_document model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from tb_document"); strSql.Append(" where id=@id "); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
public void AddNewDocument(tb_document doc) { using (MySqlConnection _connection = new MySqlConnection(connStr)) { MySqlCommand sqlCmd = new MySqlCommand(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = "INSERT INTO tb_document (no_doc, main_proccess, core_proccess, proccess, lob) Values (@no, @main, @core, @proccess, @lob)"; sqlCmd.Connection = _connection; sqlCmd.Parameters.AddWithValue("@no", doc.no_doc); sqlCmd.Parameters.AddWithValue("@main", doc.main_proccess); sqlCmd.Parameters.AddWithValue("@core", doc.core_proccess); sqlCmd.Parameters.AddWithValue("@proccess", doc.proccess); sqlCmd.Parameters.AddWithValue("@lob", doc.lob); _connection.Open(); int rowInserted = sqlCmd.ExecuteNonQuery(); _connection.Close(); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(tb_document model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_document("); strSql.Append("id,title,content,addtime)"); strSql.Append(" values ("); strSql.Append("@id,@title,@content,@addtime)"); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
public string NewDoc(tb_document model) { string flag = "0"; try { model.doc_CreateDate = DateTime.Now; model.doc_CreateUser = CurrentUserInfo.PersonnelID; model.doc_UpdateDate = DateTime.Now; model.doc_UpdateUser = CurrentUserInfo.PersonnelID; //model.doc_Size = (Convert.ToInt32(model.doc_Size) / 1000).ToString(); model.doc_Type = "文档管理"; if (_docbll.Add(model) > 0) { flag = "1"; } } catch { flag = "0"; } return(flag); }
/// <summary> /// 得到一个对象实体 /// </summary> public tb_document GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,doc_Code,doc_Name,doc_Guid,direct_Id,doc_Type,doc_URL,doc_Size,doc_CreateUser,doc_UpdateUser,doc_CreateDate,doc_UpdateDate,isDelete,doc_Revo,doc_Source,doc_Path,temp1,temp2,remark,doc_Status,doc_KeyWord from tb_document "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; tb_document model = new tb_document(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 内容管理 详情 /// </summary> public ActionResult documentInfo(tb_document model) { model = ddocument.GetInfo(model); return(View(model ?? new tb_document())); }
/// <summary> /// 内容管理 删除 /// </summary> public JsonResult documentDelete(tb_document model) { bool boolResult = ddocument.Delete(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "删除失败!")); }
public string doDocCU(tb_document model) { string flag = "0"; try { if (model != null && model.id > 0) { model.doc_UpdateDate = DateTime.Now; model.doc_UpdateUser = CurrentUserInfo.PersonnelID; #region tb_documentHistory添加历史数据 var documentHistory = new tb_document_History(); documentHistory.direct_Id = model.direct_Id; documentHistory.doc_Code = model.doc_Code; documentHistory.doc_CreateDate = model.doc_CreateDate; documentHistory.doc_CreateUser = model.doc_CreateUser; documentHistory.doc_Guid = model.doc_Guid; documentHistory.doc_Id = model.id; documentHistory.doc_KeyWord = model.doc_KeyWord; documentHistory.doc_Name = model.doc_Name; documentHistory.doc_Path = model.doc_Path; documentHistory.doc_Revo = model.doc_Revo; documentHistory.doc_Size = model.doc_Size; documentHistory.doc_Source = model.doc_Source; documentHistory.doc_Status = model.doc_Status; documentHistory.doc_Type = model.doc_Type; documentHistory.doc_UpdateDate = model.doc_UpdateDate; documentHistory.doc_UpdateUser = model.doc_UpdateUser; documentHistory.doc_URL = model.doc_URL; documentHistory.isDelete = model.isDelete; documentHistory.remark = model.remark; documentHistory.temp1 = model.temp1; documentHistory.temp2 = model.temp2; tb_document_HistoryBLL _docbllhistory = new tb_document_HistoryBLL(); documentHistory.doc_Revo = (_docbllhistory.GetDocHistoryCountByDocID(documentHistory.doc_Id) + 1).ToString(); _docbllhistory.Add(documentHistory); #endregion if (_docbll.Update(model)) { flag = "1"; } } else { //model.doc_CreateDate = DateTime.Now; model.doc_CreateUser = CurrentUserInfo.PersonnelID; model.doc_UpdateDate = DateTime.Now; model.doc_UpdateUser = CurrentUserInfo.PersonnelID; //model.doc_Size = (Convert.ToInt32(model.doc_Size) / 1000).ToString(); model.doc_Type = Session["doc_Type"].ToString(); if (_docbll.Add(model) > 0) { flag = "1"; } } } catch { flag = "0"; } return(flag); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(tb_document model) { return(dal.Add(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(tb_document model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_document("); strSql.Append("doc_Code,doc_Name,doc_Guid,direct_Id,doc_Type,doc_URL,doc_Size,doc_CreateUser,doc_UpdateUser,doc_CreateDate,doc_UpdateDate,isDelete,doc_Revo,doc_Source,doc_Path,temp1,temp2,remark,doc_Status,doc_KeyWord)"); strSql.Append(" values ("); strSql.Append("@doc_Code,@doc_Name,@doc_Guid,@direct_Id,@doc_Type,@doc_URL,@doc_Size,@doc_CreateUser,@doc_UpdateUser,@doc_CreateDate,@doc_UpdateDate,@isDelete,@doc_Revo,@doc_Source,@doc_Path,@temp1,@temp2,@remark,@doc_Status,@doc_KeyWord)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@doc_Code", SqlDbType.NVarChar, 100), new SqlParameter("@doc_Name", SqlDbType.NVarChar, 100), new SqlParameter("@doc_Guid", SqlDbType.VarChar, 100), new SqlParameter("@direct_Id", SqlDbType.Int, 4), new SqlParameter("@doc_Type", SqlDbType.VarChar, 10), new SqlParameter("@doc_URL", SqlDbType.NVarChar, -1), new SqlParameter("@doc_Size", SqlDbType.VarChar, 100), new SqlParameter("@doc_CreateUser", SqlDbType.Int, 4), new SqlParameter("@doc_UpdateUser", SqlDbType.Int, 4), new SqlParameter("@doc_CreateDate", SqlDbType.DateTime), new SqlParameter("@doc_UpdateDate", SqlDbType.DateTime), new SqlParameter("@isDelete", SqlDbType.Bit, 1), new SqlParameter("@doc_Revo", SqlDbType.VarChar, 100), new SqlParameter("@doc_Source", SqlDbType.VarChar, 300), new SqlParameter("@doc_Path", SqlDbType.NVarChar, -1), new SqlParameter("@temp1", SqlDbType.NVarChar, 300), new SqlParameter("@temp2", SqlDbType.NVarChar, 300), new SqlParameter("@remark", SqlDbType.Text), new SqlParameter("@doc_Status", SqlDbType.Int, 4), new SqlParameter("@doc_KeyWord", SqlDbType.NVarChar, 100) }; parameters[0].Value = model.doc_Code; parameters[1].Value = model.doc_Name; parameters[2].Value = model.doc_Guid; parameters[3].Value = model.direct_Id; parameters[4].Value = model.doc_Type; parameters[5].Value = model.doc_URL; parameters[6].Value = model.doc_Size; parameters[7].Value = model.doc_CreateUser; parameters[8].Value = model.doc_UpdateUser; parameters[9].Value = model.doc_CreateDate; parameters[10].Value = model.doc_UpdateDate; parameters[11].Value = model.isDelete; parameters[12].Value = model.doc_Revo; parameters[13].Value = model.doc_Source; parameters[14].Value = model.doc_Path; parameters[15].Value = model.temp1; parameters[16].Value = model.temp2; parameters[17].Value = model.remark; parameters[18].Value = model.doc_Status; parameters[19].Value = model.doc_KeyWord; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public tb_document DataRowToModel(DataRow row) { tb_document model = new tb_document(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["doc_Code"] != null) { model.doc_Code = row["doc_Code"].ToString(); } if (row["doc_Name"] != null) { model.doc_Name = row["doc_Name"].ToString(); } if (row["doc_Guid"] != null) { model.doc_Guid = row["doc_Guid"].ToString(); } if (row["direct_Id"] != null && row["direct_Id"].ToString() != "") { model.direct_Id = int.Parse(row["direct_Id"].ToString()); } if (row["doc_Type"] != null) { model.doc_Type = row["doc_Type"].ToString(); } if (row["doc_URL"] != null) { model.doc_URL = row["doc_URL"].ToString(); } if (row["doc_Size"] != null) { model.doc_Size = row["doc_Size"].ToString(); } if (row["doc_CreateUser"] != null && row["doc_CreateUser"].ToString() != "") { model.doc_CreateUser = int.Parse(row["doc_CreateUser"].ToString()); } if (row["doc_UpdateUser"] != null && row["doc_UpdateUser"].ToString() != "") { model.doc_UpdateUser = int.Parse(row["doc_UpdateUser"].ToString()); } if (row["doc_CreateDate"] != null && row["doc_CreateDate"].ToString() != "") { model.doc_CreateDate = DateTime.Parse(row["doc_CreateDate"].ToString()); } if (row["doc_UpdateDate"] != null && row["doc_UpdateDate"].ToString() != "") { model.doc_UpdateDate = DateTime.Parse(row["doc_UpdateDate"].ToString()); } if (row["isDelete"] != null && row["isDelete"].ToString() != "") { if ((row["isDelete"].ToString() == "1") || (row["isDelete"].ToString().ToLower() == "true")) { model.isDelete = true; } else { model.isDelete = false; } } if (row["doc_Revo"] != null) { model.doc_Revo = row["doc_Revo"].ToString(); } if (row["doc_Source"] != null) { model.doc_Source = row["doc_Source"].ToString(); } if (row["doc_Path"] != null) { model.doc_Path = row["doc_Path"].ToString(); } if (row["temp1"] != null) { model.temp1 = row["temp1"].ToString(); } if (row["temp2"] != null) { model.temp2 = row["temp2"].ToString(); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } if (row["doc_Status"] != null && row["doc_Status"].ToString() != "") { model.doc_Status = int.Parse(row["doc_Status"].ToString()); } if (row["doc_KeyWord"] != null) { model.doc_KeyWord = row["doc_KeyWord"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(tb_document model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_document set "); strSql.Append("doc_Code=@doc_Code,"); strSql.Append("doc_Name=@doc_Name,"); strSql.Append("doc_Guid=@doc_Guid,"); strSql.Append("direct_Id=@direct_Id,"); strSql.Append("doc_Type=@doc_Type,"); strSql.Append("doc_URL=@doc_URL,"); strSql.Append("doc_Size=@doc_Size,"); strSql.Append("doc_CreateUser=@doc_CreateUser,"); strSql.Append("doc_UpdateUser=@doc_UpdateUser,"); strSql.Append("doc_CreateDate=@doc_CreateDate,"); strSql.Append("doc_UpdateDate=@doc_UpdateDate,"); strSql.Append("isDelete=@isDelete,"); strSql.Append("doc_Revo=@doc_Revo,"); strSql.Append("doc_Source=@doc_Source,"); strSql.Append("doc_Path=@doc_Path,"); strSql.Append("temp1=@temp1,"); strSql.Append("temp2=@temp2,"); strSql.Append("remark=@remark,"); strSql.Append("doc_Status=@doc_Status,"); strSql.Append("doc_KeyWord=@doc_KeyWord"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@doc_Code", SqlDbType.NVarChar, 100), new SqlParameter("@doc_Name", SqlDbType.NVarChar, 100), new SqlParameter("@doc_Guid", SqlDbType.VarChar, 100), new SqlParameter("@direct_Id", SqlDbType.Int, 4), new SqlParameter("@doc_Type", SqlDbType.VarChar, 10), new SqlParameter("@doc_URL", SqlDbType.NVarChar, -1), new SqlParameter("@doc_Size", SqlDbType.VarChar, 100), new SqlParameter("@doc_CreateUser", SqlDbType.Int, 4), new SqlParameter("@doc_UpdateUser", SqlDbType.Int, 4), new SqlParameter("@doc_CreateDate", SqlDbType.DateTime), new SqlParameter("@doc_UpdateDate", SqlDbType.DateTime), new SqlParameter("@isDelete", SqlDbType.Bit, 1), new SqlParameter("@doc_Revo", SqlDbType.VarChar, 100), new SqlParameter("@doc_Source", SqlDbType.VarChar, 300), new SqlParameter("@doc_Path", SqlDbType.NVarChar, -1), new SqlParameter("@temp1", SqlDbType.NVarChar, 300), new SqlParameter("@temp2", SqlDbType.NVarChar, 300), new SqlParameter("@remark", SqlDbType.Text), new SqlParameter("@doc_Status", SqlDbType.Int, 4), new SqlParameter("@doc_KeyWord", SqlDbType.NVarChar, 100), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.doc_Code; parameters[1].Value = model.doc_Name; parameters[2].Value = model.doc_Guid; parameters[3].Value = model.direct_Id; parameters[4].Value = model.doc_Type; parameters[5].Value = model.doc_URL; parameters[6].Value = model.doc_Size; parameters[7].Value = model.doc_CreateUser; parameters[8].Value = model.doc_UpdateUser; parameters[9].Value = model.doc_CreateDate; parameters[10].Value = model.doc_UpdateDate; parameters[11].Value = model.isDelete; parameters[12].Value = model.doc_Revo; parameters[13].Value = model.doc_Source; parameters[14].Value = model.doc_Path; parameters[15].Value = model.temp1; parameters[16].Value = model.temp2; parameters[17].Value = model.remark; parameters[18].Value = model.doc_Status; parameters[19].Value = model.doc_KeyWord; parameters[20].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(tb_document model) { return(dal.Update(model)); }