コード例 #1
0
        public ActionResult CreateNewSalesman(string username, string password, string fullname, string address, string phonenumber, string coordinate, string email)
        {
            Account salesman = new Account();
            AccountProfile salesmanProfile = new AccountProfile();
            salesman.Email = email;
            salesman.RoleID = 2;

            salesman.Password = md5(password);
            //salesmanProfile.Email = email;
            salesmanProfile.Phone = phonenumber;
            salesmanProfile.FullName = fullname;
            salesmanProfile.Address = address;
            salesmanProfile.Coordinate = coordinate;
            salesman.IsActive = true;
            salesman.IsPending = true;
            salesman.AccountProfile = salesmanProfile;
            unitOfWork.AccountRepository.Insert(salesman);
            unitOfWork.AccountRepository.SaveChanges();

            return RedirectToAction("ManageStaff", "Admin");
        }
コード例 #2
0
 //public double DistanceFromCentroid(string CentroidCoordinate, DrugstoreGroup drugstoreGroup)
 //{
 //    string[] tempString = drugstoreGroup.DrugstoreCentroid.Split(',');
 //    List<double> coodinates = new List<double>();
 //    for (int i = 0; i < tempString.Count(); i++)
 //    {
 //        coodinates.Add(double.Parse(tempString[i]));
 //    }
 //    List<double> result = new List<double>();
 //    string[] temp = new string[2];
 //    temp = CentroidCoordinate.Split(',');
 //    result.Add(double.Parse(temp[0]));
 //    result.Add(double.Parse(temp[1]));
 //    //var poin3D = kMeans.Change(drugStore);
 //    var point3D = kMeans.ChangeCoordinateMapToCoordinate3D(result[0], result[1]);
 //    return kMeans.GetDistance(point3D, kMeans.ChangeCoordinateMapToCoordinate3D(coodinates[0], coodinates[1]));
 //    //return kMeans.GetDistance(kMeans.Change(drugStore), kMeans.ChangeCoordinateMapToCoordinate3D(coodinates[0], coodinates[1]));
 //}
 public List<Drugstore> NearestDrugstores(List<Drugstore> listDrugstore, Account saleman, int count)
 {
     string coordinate = saleman.AccountProfile.Coordinate;
     string[] stringSalemanCoordinates = coordinate.Split(',');
     List<double> salemanCoordinate = new List<double>();
     for (int i = 0; i < stringSalemanCoordinates.Count(); i++)
     {
         salemanCoordinate.Add(double.Parse(stringSalemanCoordinates[i]));
     }
     List<Drugstore> nearestDrugstores = new List<Drugstore>(count);
     double x = 0;
     double y = 0;
     List<Point> listPoint = new List<Point>();
     for (int i = 0; i < listDrugstore.Count; i++)
     {
         var point = new Point();
         point.Drugstore = listDrugstore[i];
         coordinate = listDrugstore[i].Coordinate;
         string[] stringDrugstoreCoordinates = coordinate.Split(',');
         List<double> drugstoreCoordinate = new List<double>();
         for (int j = 0; j < stringDrugstoreCoordinates.Count(); j++)
         {
             drugstoreCoordinate.Add(double.Parse(stringDrugstoreCoordinates[j]));
         }
         point.distance = FindDistance(salemanCoordinate, drugstoreCoordinate);
         listPoint.Add(point);
     }
     var resultList = BubbleSort(listPoint);
     for (int i = 0; i < count; i++)
     {
         nearestDrugstores.Add(resultList[i].Drugstore);
     }
     return nearestDrugstores;
 }
コード例 #3
0
        //public ActionResult DeleteDrugstoreGroup()
        //{
        //    if (Session["ListGroupID"] != null)
        //    {
        //        bool flag = true;
        //        var listGroupID = (List<int>)Session["ListGroupID"];
        //        var listGroup = new List<int>();
        //        listGroup.AddRange(listGroupID);
        //        for (int i = listGroupID.Count - 1; i >= 0; i--)
        //        {
        //            var id = Int32.Parse(listGroupID[i].ToString());
        //            var drusgtore = unitOfWork.DrugStoreRepository.Get(b => b.DrugstoreGroupID == id).ToList();
        //            for (int j = 0; j < drusgtore.Count; j++)
        //            {
        //                drusgtore[j].DrugstoreGroupID = null;
        //                unitOfWork.DrugStoreRepository.Update(drusgtore[j]);
        //                unitOfWork.DrugStoreRepository.SaveChanges();
        //            }
        //            unitOfWork.DrugstoreGroupRepository.Delete(listGroupID[i]);
        //            unitOfWork.DrugstoreGroupRepository.SaveChanges();
        //            listGroupID.RemoveAt(i);
        //        }
        //        Session["ListGroupID"] = listGroupID;
        //        return Json(listGroup);
        //    }
        //    return new EmptyResult();
        //}
        //public void AssignSaleMan()
        //{
        //    ////var accountList =
        //    ////    unitOfWork.AccountRepository.Get(
        //    ////        b => b.Drugstore.SalesmanID == null && b.RoleID == 4 && b.IsPending == true && b.IsActive == true);
        //    //List<Drugstore> listDrugstore = (List<Drugstore>)unitOfWork.DrugStoreRepository.Get(b => b.SalesmanID == null&&b.OwnerID!=null);
        //    ////List<Drugstore> listDrugstore = (List<Drugstore>) unitOfWork.AccountRepository.Get(
        //    ////    b => b.Drugstore.SalesmanID == null && b.RoleID == 4 && b.IsPending == true && b.IsActive == true)
        //    ////    .Select(b => b.Drugstore);
        //    //var listSalesman = unitOfWork.AccountRepository.Get(b=>b.RoleID==3);
        //    //Random r = new Random();
        //    //int index = 0;
        //    //if (listSalesman!=null)
        //    //{
        //    //    var listClusterQuantity = ListClusterQuantity(listSalesman.Count(), listDrugstore.Count);
        //    //    foreach (int i in Enumerable.Range(0, listSalesman.Count()).OrderBy(x => r.Next()))
        //    //    {
        //    //        var drugstores = NearestDrugstores(listDrugstore, listSalesman.ElementAt(i), listClusterQuantity[index]);
        //    //        for (int j = 0; j < drugstores.Count; j++)
        //    //        {
        //    //            Drugstore drugstore = new Drugstore();
        //    //            drugstore = drugstores[j];
        //    //            drugstore.SalesmanID = listSalesman.ElementAt(i).AccountID;
        //    //            unitOfWork.DrugStoreRepository.Update(drugstore);
        //    //            unitOfWork.DrugStoreRepository.SaveChanges();
        //    //        }
        //    //        for (int j = listDrugstore.Count - 1; j >= 0; j--)
        //    //        {
        //    //            for (int k = 0; k < drugstores.Count; k++)
        //    //            {
        //    //                if (listDrugstore[j].DrugstoreID == drugstores[k].DrugstoreID)
        //    //                {
        //    //                    listDrugstore.RemoveAt(j);
        //    //                    break;
        //    //                }
        //    //            }
        //    //        }
        //    //        index++;
        //    //    }
        //    //}
        //    var listSalemans = unitOfWork.AccountRepository.GetAll().Where(a => a.RoleID == 3).ToList();
        //    var allGroups = kMeans.Processing();
        //    var groupDrugstore = unitOfWork.DrugstoreGroupRepository.GetAll().ToList();
        //    if (allGroups!=null)
        //    {
        //        if (groupDrugstore.Count >0)
        //        {
        //            for (int i = 0; i < listSalemans.Count; i++)
        //            {
        //                var index = -1;
        //                double minDistance = double.MaxValue;
        //                for (int j = 0; j < allGroups.Count; j++)
        //                {
        //                    double curDistance = DistanceFromSalesman(allGroups[j].Item2, listSalemans[i]);
        //                    if (curDistance < minDistance)
        //                    {
        //                        minDistance = curDistance;
        //                        index = j;
        //                    }
        //                }
        //                var drugstoreGroup = new DrugstoreGroup();
        //                drugstoreGroup.SalesmanID = listSalemans[i].AccountID;
        //                drugstoreGroup.DrugstoreCentroid = allGroups[index].Item2;
        //                unitOfWork.DrugstoreGroupRepository.Insert(drugstoreGroup);
        //                unitOfWork.DrugstoreGroupRepository.SaveChanges();
        //                for (int k = 0; k < allGroups[index].Item1.Count; k++)
        //                {
        //                    var drugstoreID = allGroups[index].Item1[k].DrugstoreID;
        //                    var drugstore =
        //                        unitOfWork.DrugStoreRepository.GetAll()
        //                            .Where(s => s.DrugstoreID == drugstoreID)
        //                            .Single();
        //                    drugstore.DrugstoreGroupID = drugstoreGroup.DrugstoreGroupID;
        //                    unitOfWork.DrugStoreRepository.Update(drugstore);
        //                    unitOfWork.DrugStoreRepository.SaveChanges();
        //                }
        //                allGroups.Remove(allGroups[index]);
        //            }
        //        }
        //        else
        //        {
        //           for (int i = 0; i < groupDrugstore.Count(); i++)
        //            {
        //                var index = -1;
        //                double minDistance = double.MaxValue;
        //                for (int j = 0; j < allGroups.Count; j++)
        //                {
        //                    double curDistance = DistanceFromCentroid(allGroups[j].Item2, groupDrugstore[i]);
        //                    if (curDistance < minDistance)
        //                    {
        //                        minDistance = curDistance;
        //                        index = j;
        //                    }
        //                }
        //                //var drugstoreGroup = new DrugstoreGroup();
        //                //drugstoreGroup.SalesmanID = listSalemans[i].AccountID;
        //                //drugstoreGroup.DrugstoreCentroid = allGroups[index].Item2.Coordinate;
        //                //unitOfWork.DrugstoreGroupRepository.Insert(drugstoreGroup);
        //                //unitOfWork.DrugstoreGroupRepository.SaveChanges();
        //                for (int k = 0; k < allGroups[index].Item1.Count; k++)
        //                {
        //                    var drugstoreID = allGroups[index].Item1[k].DrugstoreID;
        //                    var drugstore =
        //                        unitOfWork.DrugStoreRepository.GetAll()
        //                            .Where(s => s.DrugstoreID == drugstoreID)
        //                            .Single();
        //                    drugstore.DrugstoreGroupID = groupDrugstore[i].DrugstoreGroupID;
        //                    unitOfWork.DrugStoreRepository.Update(drugstore);
        //                    unitOfWork.DrugStoreRepository.SaveChanges();
        //                }
        //                var listDrugstore =
        //                    unitOfWork.DrugStoreRepository.Get(
        //                        b => b.DrugstoreGroupID == groupDrugstore[i].DrugstoreGroupID).ToList();
        //                var centroid = kMeans.FindCentroid(listDrugstore);
        //                allGroups.Remove(allGroups[index]);
        //            }
        //            if (allGroups.Count>0)
        //            {
        //                var saleman = unitOfWork.AccountRepository.Get(b => b.RoleID == 3);
        //                var salemandID = unitOfWork.DrugstoreGroupRepository.GetAll().Select(b => b.SalesmanID);
        //                var salemanNew = (from i in saleman
        //                    where !salemandID.Contains(i.AccountID)
        //                    select i).ToList();
        //                for (int i = 0; i < salemanNew.Count; i++)
        //                {
        //                    var index = -1;
        //                    double minDistance = double.MaxValue;
        //                    for (int j = 0; j < allGroups.Count; j++)
        //                    {
        //                        double curDistance = DistanceFromSalesman(allGroups[j].Item2, salemanNew[i]);
        //                        if (curDistance < minDistance)
        //                        {
        //                            minDistance = curDistance;
        //                            index = j;
        //                        }
        //                    }
        //                    var drugstoreGroup = new DrugstoreGroup();
        //                    drugstoreGroup.SalesmanID = salemanNew[i].AccountID;
        //                    drugstoreGroup.DrugstoreCentroid = allGroups[index].Item2;
        //                    unitOfWork.DrugstoreGroupRepository.Insert(drugstoreGroup);
        //                    unitOfWork.DrugstoreGroupRepository.SaveChanges();
        //                    for (int k = 0; k < allGroups[index].Item1.Count; k++)
        //                    {
        //                        var drugstoreID = allGroups[index].Item1[k].DrugstoreID;
        //                        var drugstore =
        //                            unitOfWork.DrugStoreRepository.GetAll()
        //                                .Where(s => s.DrugstoreID == drugstoreID)
        //                                .Single();
        //                        drugstore.DrugstoreGroupID = drugstoreGroup.DrugstoreGroupID;
        //                        unitOfWork.DrugStoreRepository.Update(drugstore);
        //                        unitOfWork.DrugStoreRepository.SaveChanges();
        //                    }
        //                    allGroups.Remove(allGroups[index]);
        //                }
        //            }
        //        }
        //    }
        //}
        public double DistanceFromSalesman(string CentroidCoordinate, Account account)
        {
            //KMeans kmeans=new KMeans();
            var pointA=new DMS.Service.KMeans.Point2D();
            var pointB=new DMS.Service.KMeans.Point2D();

            string[] tempString = account.AccountProfile.Coordinate.Split(',');
            //List<double> coodinates = new List<double>();
            //for (int i = 0; i < tempString.Count(); i++)
            //{
            //    coodinates.Add(double.Parse(tempString[i]));
            //}
            pointA.x=double.Parse(tempString[0]);
            pointA.y=double.Parse(tempString[1]);
            List<double> result = new List<double>();
            string[] temp = new string[2];
            temp = CentroidCoordinate.Split(',');
            pointB.x=double.Parse(temp[0]);
            pointB.y=double.Parse(temp[1]);
            //result.Add(double.Parse(temp[0]));
            //result.Add(double.Parse(temp[1]));

            //var poin3D = kMeans.Change(drugStore);
            //var point3D = kMeans.ChangeCoordinateMapToCoordinate3D(result[0], result[1]);
            return kMeans.GetDistance(pointA, pointB);
            //return kMeans.GetDistance(point3D, kMeans.ChangeCoordinateMapToCoordinate3D(coodinates[0], coodinates[1]));
        }
コード例 #4
0
        public ActionResult RegisterDrugstoreAccount(string username, string password, string fullname, string email, string phonenumber, string drugstoreName, string drugstoreAddress, string coordinate, int districtID)
        {
            var account = new Account();
            var accountInfo = new AccountProfile();
            var drugstore = new Drugstore();
            account.Email = email;
            account.RoleID = 4;
            //var md5Hasher = new MD5CryptoServiceProvider();

            //var encoder = new UTF8Encoding();
            //var hashed = md5Hasher.ComputeHash(encoder.GetBytes(password)).ToString();
            account.Password = md5(password);
            //accountInfo.Email = email;
            accountInfo.Phone = phonenumber;
            accountInfo.FullName = fullname;
            account.Role = unitOfWork.RoleRepository.Get(b => b.RoleID == 4).SingleOrDefault();
            account.IsActive = true;
            account.IsPending = true;
            account.AccountProfile = accountInfo;
            //account.AccountProfiles.Add(accountInfo);
            var checkUser = unitOfWork.AccountRepository.Get(b => b.Email == email).SingleOrDefault();
            //Check if already have that email
            if (checkUser == null)
            {
                var drugstoreTemp = unitOfWork.DrugStoreRepository.Get(b => b.DrugstoreName == drugstoreName && b.Coordinate == coordinate).FirstOrDefault();
                //Check if already have that drugstore
                if (drugstoreTemp != null)
                {
                    //var ownerDrugstore = unitOfWork.AccountRepository.Get(b => b.DrugstoreID == drugstoreTemp.DrugstoreID).SingleOrDefault();
                    //Check if that drugstore already have owner
                    if (drugstoreTemp.OwnerID == null)
                    {

                        //account.DrugstoreID = drugstoreTemp.DrugstoreID;
                        unitOfWork.AccountRepository.Insert(account);
                        unitOfWork.AccountRepository.SaveChanges();
                        var accountDrugstore = unitOfWork.AccountRepository.Get(b => b.Email == account.Email).SingleOrDefault();
                        if (accountDrugstore != null)
                        {
                            drugstoreTemp.OwnerID = accountDrugstore.AccountID;
                            unitOfWork.DrugStoreRepository.Update(drugstoreTemp);
                            unitOfWork.DrugStoreRepository.SaveChanges();
                        }

                        return Json(new { type = "Successful" });
                    }
                    else
                    {
                        return Json(new { type = "DrugstoreAlreadyHaveAccount", message = "Thông tin nhà thuốc bạn vừa đăng ký đã có trong hệ thống." });
                    }

                }
                //Dont have that drugstore
                drugstore.DrugstoreName = drugstoreName;
                drugstore.DistrictID = districtID;
                drugstore.Address = drugstoreAddress;
                drugstore.DrugstoreTypeID = unitOfWork.DrugStoreTypeRepository.GetByID(3).DrugstoreTypeID;
                //drugstore.Debt = 0;
                drugstore.Coordinate = coordinate;
                //drugstore.Debt = 0;
                drugstore.IsActive = true;
                //drugstore.OwnerID = account.AccountID;
                //account.Drugstore=drugstore;
                unitOfWork.AccountRepository.Insert(account);
                unitOfWork.AccountRepository.SaveChanges();
                var accountTemp = unitOfWork.AccountRepository.Get(b => b.Email == account.Email).SingleOrDefault();
                if (accountTemp != null)
                {
                    drugstore.OwnerID = accountTemp.AccountID;
                    unitOfWork.DrugStoreRepository.Insert(drugstore);
                    unitOfWork.DrugStoreRepository.SaveChanges();
                }

                return Json(new { type = "Successful" });
            }
            return Json(new
            {
                type = "Fail",
                message = "Tên tài khoản này đã có người sử dụng.Xin thử lại bằng tên khác!"
            });
        }