Example #1
0
        public List <DepartmentInfo> getAllDepartment(int pageSize, int pageIndex)
        {
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                List <DepartmentInfo> ListDepartment = DepartmentDataLayer.GetInstance().GetAllDepartment(connection);
                //int min = pageIndex * pageSize;
                //int max = pageIndex * pageSize + pageSize;

                //if (min > ListDepartment.Count) return new List<DepartmentInfo>();
                //if (max >= ListDepartment.Count) pageSize = ListDepartment.Count - min;
                //if (pageSize <= 0) return new List<DepartmentInfo>();
                return(ListDepartment);
            }
            //using (SqlConnection connection = sqlConnection.GetConnection())
            //{
            //    List<DepartmentInfo> ListDepartment = DepartmentDataLayer.GetInstance().GetAllDepartment(connection);
            //    int min = pageIndex * pageSize;
            //    int max = pageIndex * pageSize + pageSize;

            //    if (min > ListDepartment.Count) return new List<DepartmentInfo>();
            //    if (max >= ListDepartment.Count) pageSize = ListDepartment.Count - min;
            //    if (pageSize <= 0) return new List<DepartmentInfo>();
            //    return ListDepartment.GetRange(min, pageSize);
            //}
        }
Example #2
0
        public List <Department> GetAllDepartments()
        {
            try
            {
                List <Department> DepartmentList       = new List <Department>();
                DataTable         DepartentTablefromDB = new DepartmentDataLayer().GetAllDepartmentsFromDB();

                foreach (DataRow dr in DepartentTablefromDB.Rows)
                {
                    DepartmentList.Add(
                        new Department(
                            int.Parse(dr["depNo-12"].ToString()),
                            dr["depName-12"].ToString(),
                            dr["depContact-12"].ToString()
                            )
                        );
                }

                return(DepartmentList);
            }

            catch (Exception e)
            {
                throw e;
            }
        }
Example #3
0
        public ActionMessage createProposal(ProposalInfo _Proposal, string _userI)
        {
            ActionMessage        ret           = new ActionMessage();
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    int    year           = DateTime.Now.Year;
                    int    maxPropCode    = ProposalDataLayer.GetInstance().GetMaxPropCode(connection, year);
                    string departmentCode = DepartmentDataLayer.GetInstance().GetDepartmentCodeById(connection, _Proposal.DepartmentID);

                    _Proposal.ProposalCode = departmentCode + year.ToString() + maxPropCode;
                    ret.id = ProposalDataLayer.GetInstance().InsertProposal(connection, _Proposal, _userI);
                    ProposalDataLayer.GetInstance().UpdateMaxCode(connection, maxPropCode, year);
                    ret.isSuccess = true;
                }
                catch (Exception ex)
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "Internal Error";
                    ret.err.msgString = ex.Message;
                }
            }
            return(ret);
        }
Example #4
0
        public List <DepartmentInfo> getDepartment(DepartmentSeachCriteria _criteria)
        {
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                List <DepartmentInfo> ListDepartment = DepartmentDataLayer.GetInstance().getDepartment(connection, _criteria);
                return(ListDepartment);
            }
        }
Example #5
0
        public DepartmentInfo getDepartmentbyId(int _ID)
        {
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                List <DepartmentInfo> ListDepartment = DepartmentDataLayer.GetInstance().GetAllDepartment(connection);
                DepartmentInfo        findDepartment = ListDepartment.Where(i => i.DepartmentID == _ID).First();
                return(findDepartment);
            }
        }
Example #6
0
        public int getNewId()
        {
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                List <DepartmentInfo> ListDepartment = DepartmentDataLayer.GetInstance().GetAllDepartment(connection);
                DepartmentInfo        lastDepartment = ListDepartment.Last();
                if (lastDepartment != null)
                {
                    return(lastDepartment.DepartmentID + 1);
                }
                return(1);
            }
        }
Example #7
0
        public ActionMessage createDepartment(DepartmentInfo _department, string _userI)
        {
            ActionMessage ret = new ActionMessage();

            if (_department.DepartmentCode.Trim() == string.Empty)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error";
                ret.err.msgString = "Chưa nhập Khoa phòng";
            }
            //else if (_department.SourceID == -1)
            //{
            //}
            else
            {
                SqlConnectionFactory sqlConnection = new SqlConnectionFactory();
                using (SqlConnection connection = sqlConnection.GetConnection())
                {
                    DepartmentSeachCriteria _criteria = new DepartmentSeachCriteria();
                    _criteria.DepartmentCode = _department.DepartmentCode;
                    var chkDepartmentInfo = getDepartment(_criteria);
                    if (chkDepartmentInfo.Count > 0)
                    {
                        ret.isSuccess     = false;
                        ret.err.msgCode   = "Internal Error";
                        ret.err.msgString = "Trùng mã Khoa phòng";
                    }
                    else
                    {
                        try
                        {
                            DepartmentDataLayer.GetInstance().InsertDepartment(connection, _department, _userI);
                            ret.isSuccess = true;
                        }
                        catch (Exception ex)
                        {
                            ret.isSuccess     = false;
                            ret.err.msgCode   = "Internal Error";
                            ret.err.msgString = ex.ToString();
                        }
                    }
                }
            }
            return(ret);
        }
Example #8
0
        public ActionMessage editDepartment(int id, DepartmentInfo _department, string _userU)
        {
            ActionMessage ret = new ActionMessage();

            if (_department.DepartmentCode.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())
                {
                    DepartmentSeachCriteria _criteria = new DepartmentSeachCriteria();
                    _criteria.DepartmentCode = _department.DepartmentCode;
                    var chkDepartmentInfo = getDepartment(_criteria);
                    if (chkDepartmentInfo.Count > 0)
                    {
                        ret.isSuccess     = false;
                        ret.err.msgCode   = "Internal Error";
                        ret.err.msgString = "Trùng mã Khoa phòng";
                    }
                    else
                    {
                        try
                        {
                            DepartmentDataLayer.GetInstance().UpdateDepartment(connection, _department, _userU);
                            ret.isSuccess = true;
                        }
                        catch (Exception ex)
                        {
                            ret.isSuccess     = false;
                            ret.err.msgCode   = "Internal Error";
                            ret.err.msgString = ex.ToString();
                        }
                    }
                }
            }
            return(ret);
        }
Example #9
0
        public int createProposal2(ProposalInfo _Proposal, string _userI)
        {
            int ret = -1;



            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    int    year           = DateTime.Now.Year;
                    int    maxPropCode    = ProposalDataLayer.GetInstance().GetMaxPropCode(connection, year);
                    string departmentCode = DepartmentDataLayer.GetInstance().GetDepartmentCodeById(connection, _Proposal.DepartmentID);

                    _Proposal.ProposalCode = departmentCode + year.ToString() + maxPropCode.ToString().PadLeft(4, '0');
                    UserLogInfo info = new UserLogInfo();
                    info.Action      = "Insert";
                    info.Description = "ngày : " + _Proposal.DateIn + " khoa/phòng chịu trách nhiệm ID " + _Proposal.CurDepartmentID + " code " + _Proposal.ProposalCode
                                       + " khoa phòng đề xuất ID : " + _Proposal.DepartmentID + " trạng thái : " + _Proposal.Status;
                    info.Feature  = TableFile.Proposal.ToString();
                    info.Time     = DateTime.Now;
                    info.UserName = _userI;
                    info.UserID   = 1;
                    UserService.GetInstance().TrackUserAction(info);

                    ret = ProposalDataLayer.GetInstance().InsertProposal(connection, _Proposal, _userI);
                    ProposalDataLayer.GetInstance().UpdateMaxCode(connection, maxPropCode, year);

                    //   ret.isSuccess = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(ret);
        }
Example #10
0
        public ActionMessage deleteDepartment(int id)
        {
            ActionMessage ret = new ActionMessage();

            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    DepartmentDataLayer.GetInstance().DeleteDepartment(connection, id);
                    ret.isSuccess = true;
                }
                catch (Exception ex)
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "Internal Error";
                    ret.err.msgString = ex.ToString();
                }
            }
            return(ret);
        }
Example #11
0
        public DecisionInfo GetDecision(int _ID, string _userID)
        {
            DecisionInfo         record        = new DecisionInfo();
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                record = DecisionDataLayer.GetInstance().getDecision(connection, _ID, _userID);
                if (record == null)
                {
                    return(null);
                }

                record.Items           = new List <ItemInfo>();
                record.Items           = QuoteDataLayer.GetInstance().getSelectedItemsQuote(connection, record.QuoteID);
                record.DepartmentNames = DepartmentDataLayer.GetInstance().GetDepartmentNamesFromQuote(connection, record.QuoteID);

                //Get document
                DocumentSeachCriteria documentCriteria = new DocumentSeachCriteria();
                documentCriteria.TableName = TableFile.Decision.ToString();
                documentCriteria.PreferId  = _ID.ToString();
                record.ListDocument        = DocumentService.GetInstance().GetDocument(documentCriteria);
                //get Comment
                CommentSeachCriteria commentCriteria = new CommentSeachCriteria();
                commentCriteria.TableName = TableFile.Decision.ToString();
                commentCriteria.PreferId  = _ID.ToString();
                record.ListComment        = CommentService.GetInstance().getComment(commentCriteria);
                foreach (var item in record.ListComment)
                {
                    DocumentSeachCriteria documentCriteria2 = new DocumentSeachCriteria();
                    documentCriteria2.TableName = TableFile.Comment.ToString();
                    documentCriteria2.PreferId  = item.AutoID.ToString();
                    item.ListDocument           = DocumentService.GetInstance().GetDocument(documentCriteria2);
                }
            }
            return(record);
        }