示例#1
0
        public static int DeleteGroupByGroupID(int groupID)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            var group = db.tblGroups.Where(g => g.GroupID == groupID).FirstOrDefault();

            if (group == null)
            {
                return(0);
            }

            //delete group
            db.DeleteObject(group);

            //delete group's users in tblUserInGroup
            List <tblUserInGroup> listTblUserInGroup = db.tblUserInGroups.Where(g => g.GroupID == groupID).ToList();

            foreach (tblUserInGroup userInGroup in listTblUserInGroup)
            {
                db.DeleteObject(userInGroup);
            }

            //delete group's permission in tblUserGroupPermistion
            List <tblUserGroupPermission> listUserGroupPermission = db.tblUserGroupPermissions.Where(g => g.GroupID == groupID && g.PermissionType == UserGroupPermissionFactory.PERMISSION_TYPE_GROUP).ToList();

            foreach (tblUserGroupPermission userGroupPermission in listUserGroupPermission)
            {
                db.DeleteObject(userGroupPermission);
            }

            int re = db.SaveChanges();

            db.Connection.Close();
            return(re);
        }
        public static int Delete(Int64 ID)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            try
            {
                var reply = db.tblListHandoverReplies.FirstOrDefault(vt => vt.ID == ID);
                if (reply == null)
                {
                    return(0);
                }
                else
                {
                    //update all related Handover
                    RemoveListReplyIDFromHandover(ID);

                    //delete Bang ke hoi bao
                    db.DeleteObject(reply);
                    return(db.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
            finally
            {
                db.Dispose();
            }
        }
示例#3
0
        public static List <tblUser> SelectAllUser()
        {
            var            db   = new dbTrainEntities(ConnectionController.GetConnection());
            List <tblUser> list = db.tblUsers.OrderBy(g => g.Name).ToList();

            return(list);
        }
        public static tblListHandoverReply InsertListHandoverReply(tblListHandoverReply handoverReply, List <tblHandover> listHandover, tblNumberGenerate numberGenerate)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            db.AddTotblNumberGenerates(numberGenerate);
            db.AddTotblListHandoverReplies(handoverReply);

            foreach (tblHandover handover in listHandover)
            {
                tblHandover obj = db.tblHandovers.Where(g => g.ID == handover.ID).FirstOrDefault();
                if (obj != null)
                {
                    obj.tblListHandoverReply = handoverReply;
                }
            }
            int result = db.SaveChanges();

            if (result > 0)
            {
                return(handoverReply);
            }
            else
            {
                return(null);
            }
        }
        public static tblNumberGenerate AutoGenerate(int type)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());
            tblNumberGenerate number = new tblNumberGenerate();

            number.Year       = CommonFactory.GetCurrentDate().Year + "";
            number.NumberType = type;
            tblNumberGenerate max = getMaxValueByType(type);

            if (max == null)
            {
                max = new tblNumberGenerate
                {
                    HandoverNumber    = 0,
                    ReplyReportNumber = 0,
                    Year = CommonFactory.GetCurrentDate().Year + ""
                };
            }
            if (type == NUMBER_TYPE_HANDOVER)
            {
                number.HandoverNumber = max.HandoverNumber + 1;
            }
            if (type == NUMBER_TYPE_REPLY)
            {
                number.ReplyReportNumber = max.ReplyReportNumber + 1;
            }

            return(number);
        }
示例#6
0
        public static tblUser GetByID(int userID)
        {
            var db   = new dbTrainEntities(ConnectionController.GetConnection());
            var user = db.tblUsers.Where(g => g.UserID.Equals(userID)).FirstOrDefault();

            return(user);
        }
示例#7
0
        public static int Update(tblType typeObj)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            tblType originType = db.tblTypes.Where(g => g.TypeCode == typeObj.TypeCode).FirstOrDefault();

            if (originType == null)
            {
                return(-1);
            }

            originType.TypeName     = typeObj.TypeName;
            originType.Description  = typeObj.Description;
            originType.ModifiedBy   = typeObj.ModifiedBy;
            originType.ModifiedDate = CommonFactory.GetCurrentDate();

            try
            {
                return(db.SaveChanges());
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
示例#8
0
        public static DateTime GetCurrentDate()
        {
            var db            = new dbTrainEntities(ConnectionController.GetConnection());
            var objCurentDate = db.ViewGetCurrentDates.FirstOrDefault();

            return(objCurentDate.CurrentDateTime);
        }
示例#9
0
        public static int Update(tblCompany companyObj)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            tblCompany originCompany = db.tblCompanies.Where(g => g.CompanyCode == companyObj.CompanyCode).FirstOrDefault();

            if (originCompany == null)
            {
                return(-1);
            }

            originCompany.CompanyName  = companyObj.CompanyName;
            originCompany.Description  = companyObj.Description;
            originCompany.ModifiedBy   = companyObj.ModifiedBy;
            originCompany.ModifiedDate = CommonFactory.GetCurrentDate();

            try
            {
                return(db.SaveChanges());
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
示例#10
0
        public static tblTrain FindTrainByID(Int64 ID)
        {
            var db          = new dbTrainEntities(ConnectionController.GetConnection());
            var originTrain = db.tblTrains.Where(g => g.TrainID == ID).FirstOrDefault();

            return(originTrain);
        }
示例#11
0
        public static List <tblTrain> SearchTrain(string numberTrain, short type, bool seachDate, DateTime dateFrom, DateTime dateTo)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            try
            {
                IQueryable <tblTrain> lst = db.tblTrains;
                if (!string.IsNullOrEmpty(numberTrain))
                {
                    lst = lst.Where(x => x.Number.Contains(numberTrain));
                }
                if (type >= 0)
                {
                    lst = lst.Where(x => x.Type == type);
                }

                if (seachDate == true)
                {
                    var fromDate = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, 0, 0, 0);
                    var toDate   = new DateTime(dateTo.Year, dateTo.Month, dateTo.Day, 23, 59, 59);
                    lst = lst.Where(x => x.DateImportExport.HasValue && x.DateImportExport.Value >= fromDate && x.DateImportExport.Value <= toDate);
                }

                return(lst.ToList());
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                db.Dispose();
            }
        }
示例#12
0
        public static tblUser getUserByUserName(string userName)
        {
            var     db   = new dbTrainEntities(ConnectionController.GetConnection());
            tblUser user = db.tblUsers.Where(g => g.UserName == userName).FirstOrDefault();

            return(user);
        }
示例#13
0
        public static int Delete(long trainId)
        {
            var db    = new dbTrainEntities(ConnectionController.GetConnection());
            var train = db.tblTrains.FirstOrDefault(g => g.TrainID == trainId);

            db.DeleteObject(train);
            return(db.SaveChanges());
        }
示例#14
0
        public static int Insert(tblTrain train)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            train.CreatedDate = CommonFactory.GetCurrentDate();
            db.AddTotblTrains(train);
            return(db.SaveChanges());
        }
        public static int AddNew(tblNumberGenerate number)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            db.AddTotblNumberGenerates(number);

            return(db.SaveChanges());
        }
示例#16
0
        public static List <tblUserInGroup> GetTblUserInGroupByGroupID(int groupID)
        {
            var db         = new dbTrainEntities(ConnectionController.GetConnection());
            var userGroups = db.tblUserInGroups.Where(g => g.GroupID == groupID).ToList();

            db.Connection.Close();
            return(userGroups);
        }
示例#17
0
        public static List <ViewUserGroup> GetByUserID(int userID)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());
            List <ViewUserGroup> list = db.ViewUserGroups.Where(g => g.UserID == userID).ToList();

            db.Connection.Close();
            return(list);
        }
示例#18
0
        public static List <tblPermission> GetAllPermission()
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());
            List <tblPermission> list = db.tblPermissions.ToList();

            db.Connection.Close();
            return(list);
        }
示例#19
0
        public static int Delete(String companyCode)
        {
            var db      = new dbTrainEntities(ConnectionController.GetConnection());
            var company = db.tblCompanies.FirstOrDefault(vt => vt.CompanyCode == companyCode);

            db.DeleteObject(company);
            return(db.SaveChanges());
        }
 private static dbTrainEntities Instance(bool isNewInstance = false)
 {
     if (isNewInstance)
     {
         return(new dbTrainEntities(ConnectionController.GetConnection()));
     }
     return(_db ?? (_db = new dbTrainEntities(ConnectionController.GetConnection())));
 }
示例#21
0
        public static List <tblGroup> SelectAll()
        {
            var             db   = new dbTrainEntities(ConnectionController.GetConnection());
            List <tblGroup> list = db.tblGroups.ToList();

            db.Connection.Close();
            return(list);
        }
示例#22
0
        public static int Insert(tblCompany company)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            company.CreatedDate  = CommonFactory.GetCurrentDate();
            company.ModifiedDate = CommonFactory.GetCurrentDate();
            db.AddTotblCompanies(company);
            return(db.SaveChanges());
        }
示例#23
0
        public static tblGroup getGroupByID(int groupID)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            var group = db.tblGroups.Where(g => g.GroupID == groupID).FirstOrDefault();

            db.Connection.Close();
            return(group);
        }
示例#24
0
        /// <summary>
        /// Check if the group name is exsiting
        /// </summary>
        /// <param name="groupName"></param>
        /// <returns></returns>
        public static bool IsExistingName(string groupName)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            var group = db.tblGroups.Where(g => g.GroupName == groupName).ToList();

            db.Connection.Close();
            return(group.Count != 0);
        }
示例#25
0
        public static List <tblUserGroupPermission> GetByUserID(int userID)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            List <tblUserGroupPermission> list = db.tblUserGroupPermissions.Where(g => g.UserID == userID && g.PermissionType == PERMISSION_TYPE_USER).ToList();

            db.Connection.Close();
            return(list);
        }
示例#26
0
        public static int DeleteType(String typeCode)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            var type = db.tblTypes.FirstOrDefault(vt => vt.TypeCode == typeCode);

            db.DeleteObject(type);
            return(db.SaveChanges());
        }
        public static tblNumberGenerate getMaxValueByType(int type)
        {
            var    db   = new dbTrainEntities(ConnectionController.GetConnection());
            String year = CommonFactory.GetCurrentDate().Year + "";

            return(db.tblNumberGenerates.
                   Where(x => x.NumberType == type && x.Year == year).
                   OrderByDescending(x => x.ID).FirstOrDefault());
        }
示例#28
0
        public static int Delete(String customsCode)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            var customs = db.tblCustoms.FirstOrDefault(g => g.CustomsCode == customsCode);

            db.DeleteObject(customs);
            return(db.SaveChanges());
        }
示例#29
0
        public static int InsertToKhai(tblToKhaiTau tokhai)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            tokhai.CreatedDate = CommonFactory.GetCurrentDate();

            db.AddTotblToKhaiTaus(tokhai);

            return(db.SaveChanges());
        }
示例#30
0
        //private static ILog logger = LogManager.GetLogger("ECustoms.UserFactory");
        /// <summary>
        /// Gets the user info.
        /// </summary>
        /// <param name="userInfo">The user info.</param>
        /// <returns></returns>
        public static tblUser GetUserInfo(tblUser userInfo)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            // Encode the password & username
            userInfo.Password = Common.Encode(userInfo.Password);
            return
                (db.tblUsers.Where(g => g.UserName.Equals(userInfo.UserName, StringComparison.OrdinalIgnoreCase) && g.Password.Equals(userInfo.Password) && g.IsActive == 1).
                 FirstOrDefault());
        }