/// <summary> /// Hàm lấy tất cả khoa phòng /// </summary> /// <returns>Return List<ProposalTypeInfo></returns> /// public List <ProposalTypeInfo> GetAllProposalType(SqlConnection connection) { var result = new List <ProposalTypeInfo>(); using (var command = new SqlCommand("Select * " + " from tbl_ProposalType where 1 = 1 order by TypeID ", connection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { var info = new ProposalTypeInfo(); info.TypeID = GetDbReaderValue <int>(reader["TypeID"]); info.TypeCode = GetDbReaderValue <string>(reader["TypeCode"]); info.TypeName = GetDbReaderValue <string>(reader["TypeName"]); info.UserI = GetDbReaderValue <string>(reader["UserI"]); info.InTime = GetDbReaderValue <DateTime?>(reader["InTime"]); info.UserU = GetDbReaderValue <string>(reader["UserU"]); info.UpdateTime = GetDbReaderValue <DateTime>(reader["UpdateTime"]); result.Add(info); } } return(result); } }
public ProposalTypeInfo getProposalTypebyId(int _ID) { SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); using (SqlConnection connection = sqlConnection.GetConnection()) { List <ProposalTypeInfo> ListProposalType = ProposalTypeDataLayer.GetInstance().GetAllProposalType(connection); ProposalTypeInfo findProposalType = ListProposalType.Where(i => i.TypeID == _ID).First(); return(findProposalType); } }
public void UpdateProposalType(SqlConnection connection, int _id, ProposalTypeInfo _ProposalType, string _userU) { using (var command = new SqlCommand("UPDATE tbl_ProposalType \n" + "SET TypeCode = @TypeCode, TypeName = @TypeName, UserU=@UserU,UpdateTime=getdate() \n" + "WHERE (TypeID = @TypeID)", connection)) { AddSqlParameter(command, "@TypeID", _id, System.Data.SqlDbType.Int); AddSqlParameter(command, "@TypeCode", _ProposalType.TypeCode, System.Data.SqlDbType.VarChar); AddSqlParameter(command, "@TypeName", _ProposalType.TypeName, System.Data.SqlDbType.NVarChar); AddSqlParameter(command, "@UserU", _userU, System.Data.SqlDbType.VarChar); WriteLogExecutingCommand(command); command.ExecuteScalar(); } }
public int getNewId() { SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); using (SqlConnection connection = sqlConnection.GetConnection()) { List <ProposalTypeInfo> ListProposalType = ProposalTypeDataLayer.GetInstance().GetAllProposalType(connection); ProposalTypeInfo lastProposalType = ListProposalType.Last(); if (lastProposalType != null) { return(lastProposalType.TypeID + 1); } return(1); } }
public ActionMessage Put(int id, [FromBody] ProposalTypeInfo _department) { ActionMessage ret = new ActionMessage(); try { ret = ProposalTypeService.GetInstance().editProposalType(id, _department, GetUserId()); } catch (Exception ex) { ret.isSuccess = false; ret.err.msgCode = "001"; ret.err.msgString = ex.ToString(); } return(ret); }
public ActionMessage Post([FromBody] ProposalTypeInfo _proposalType) { ActionMessage ret = new ActionMessage(); try { ret = ProposalTypeService.GetInstance().createProposalType(_proposalType, GetUserId()); } catch (Exception ex) { ret.isSuccess = false; ret.err.msgCode = "001"; ret.err.msgString = ex.ToString(); } return(ret); }
public int InsertProposalType(SqlConnection connection, ProposalTypeInfo _ProposalType, string _userI) { int lastestInserted = 0; using (var command = new SqlCommand("Insert into [dbo].[tbl_ProposalType] (TypeCode, TypeName, UserI)" + "VALUES(@ProposalTypeCode, @ProposalTypeName, @UserI) ", connection)) { AddSqlParameter(command, "@ProposalTypeCode", _ProposalType.TypeCode, System.Data.SqlDbType.VarChar); AddSqlParameter(command, "@ProposalTypeName", _ProposalType.TypeName, System.Data.SqlDbType.NVarChar); AddSqlParameter(command, "@UserI", _userI, System.Data.SqlDbType.VarChar); WriteLogExecutingCommand(command); command.ExecuteScalar(); } return(lastestInserted); }
public ActionMessage createProposalType(ProposalTypeInfo _ProposalType, string _userI) { ActionMessage ret = new ActionMessage(); if (_ProposalType.TypeCode.Trim() == string.Empty) { ret.isSuccess = false; ret.err.msgCode = "Internal Error"; ret.err.msgString = "Chưa nhập mã loại đề xuất "; } //else if (_ProposalType.SourceID == -1) //{ //} else { SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); using (SqlConnection connection = sqlConnection.GetConnection()) { ProposalTypeSeachCriteria _criteria = new ProposalTypeSeachCriteria(); _criteria.TypeCode = _ProposalType.TypeCode; var chkProposalTypeInfo = getProposalType(_criteria); if (chkProposalTypeInfo.Count > 0) { ret.isSuccess = false; ret.err.msgCode = "Internal Error"; ret.err.msgString = "Trùng mã "; } else { try { ProposalTypeDataLayer.GetInstance().InsertProposalType(connection, _ProposalType, _userI); ret.isSuccess = true; } catch (Exception ex) { ret.isSuccess = false; ret.err.msgCode = "Internal Error"; ret.err.msgString = ex.ToString(); } } } } return(ret); }
public ActionMessage editProposalType(int id, ProposalTypeInfo _ProposalType, string _userU) { ActionMessage ret = new ActionMessage(); if (_ProposalType.TypeCode.Trim().Length == 0) { ret.isSuccess = false; ret.err.msgCode = "Internal Error"; ret.err.msgString = "Chưa nhập mã Khoa phòng"; } else { SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); using (SqlConnection connection = sqlConnection.GetConnection()) { ProposalTypeSeachCriteria _criteria = new ProposalTypeSeachCriteria(); _criteria.TypeCode = _ProposalType.TypeCode; var chkProposalTypeInfo = getProposalType(_criteria); if (chkProposalTypeInfo.Count > 0) { ret.isSuccess = false; ret.err.msgCode = "Internal Error"; ret.err.msgString = "Trùng mã Khoa phòng"; } else { try { ProposalTypeDataLayer.GetInstance().UpdateProposalType(connection, id, _ProposalType, _userU); ret.isSuccess = true; } catch (Exception ex) { ret.isSuccess = false; ret.err.msgCode = "Internal Error"; ret.err.msgString = ex.ToString(); } } } } return(ret); }
public List <ProposalTypeInfo> getProposalType(SqlConnection connection, ProposalTypeSeachCriteria _criteria) { var result = new List <ProposalTypeInfo>(); using (var command = new SqlCommand("Select * " + " from tbl_ProposalType where 1 = 1 ", connection)) { if (!string.IsNullOrEmpty(_criteria.TypeID)) { command.CommandText += " and TypeID = @PTypeID"; AddSqlParameter(command, "@TypeID", _criteria.TypeID, System.Data.SqlDbType.Int); } if (!string.IsNullOrEmpty(_criteria.TypeCode)) { command.CommandText += " and TypeCode = @TypeCode"; AddSqlParameter(command, "@TypeCode", _criteria.TypeCode, System.Data.SqlDbType.NVarChar); } if (!string.IsNullOrEmpty(_criteria.TypeName)) { command.CommandText += " and TypeName like N'%" + _criteria.TypeName + "%' "; } command.CommandText += " order by TypeID "; WriteLogExecutingCommand(command); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var info = new ProposalTypeInfo(); info.TypeID = GetDbReaderValue <int>(reader["TypeID"]); info.TypeCode = GetDbReaderValue <string>(reader["TypeCode"]); info.TypeName = GetDbReaderValue <string>(reader["TypeName"]); info.UserI = GetDbReaderValue <string>(reader["UserI"]); info.InTime = GetDbReaderValue <DateTime?>(reader["InTime"]); info.UserU = GetDbReaderValue <string>(reader["UserU"]); info.UpdateTime = GetDbReaderValue <DateTime>(reader["UpdateTime"]); result.Add(info); } } return(result); } }