private double FindDistance(List <Drugstore> listStore, Drugstore point) { var centroid = FindCentroid(listStore); var point3D = Change(point); return(GetDistance(centroid, point3D)); }
public ActionResult DeleteConfirmed(int id) { Drugstore drugstore = db.Drugstores.Find(id); db.Drugstores.Remove(drugstore); db.SaveChanges(); return(RedirectToAction("Index")); }
private List <double> ChangeToCoordinate(Drugstore point) { List <double> result = new List <double>(); string[] temp = new string[2]; temp = point.Coordinate.Split(','); result.Add(double.Parse(temp[0])); result.Add(double.Parse(temp[1])); return(result); }
private double FindDistance2D(List <Drugstore> listStore, Drugstore point) { var centroid = FindCentroid2D(listStore); var temp = ChangeToCoordinate(point); var point2D = new Point2D(); point2D.x = temp[0]; point2D.y = temp[1]; return(GetDistance(centroid, point2D)); }
public ActionResult AddDrugstore(Drugstore drugStore) { if (ModelState.IsValid) { drugStore.DrugstoreTypeID = 3; unitOfWork.DrugStoreRepository.Insert(drugStore); unitOfWork.DrugStoreRepository.SaveChanges(); return RedirectToAction("AddDrugstore"); } return View(drugStore); }
public DrugstoreViewModel(Drugstore drugstore) { Id = drugstore.Id; Name = drugstore.Name; RoundTheClock = drugstore.RoundTheClock; FoundationDate = drugstore.FoundationDate; Neighborhood = drugstore.Neighborhood; NeighborhoodId = drugstore.NeighborhoodId; CanRemove = drugstore.CanRemove(); }
public ActionResult AddDrugstore(Drugstore drugStore) { if (ModelState.IsValid) { drugStore.DrugstoreTypeID = 3; unitOfWork.DrugStoreRepository.Insert(drugStore); unitOfWork.DrugStoreRepository.SaveChanges(); return(RedirectToAction("AddDrugstore")); } return(View(drugStore)); }
public ActionResult Create([Bind(Include = "Id,Name,Address,OpeningTime,ClosingTime,PhoneNumber,DopInform,CityId")] Drugstore drugstore) { if (ModelState.IsValid) { db.Drugstores.Add(drugstore); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(db.Citys, "Id", "Name", drugstore.CityId); return(View(drugstore)); }
// GET: Drugstore/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Drugstore drugstore = db.Drugstores.Find(id); if (drugstore == null) { return(HttpNotFound()); } return(View(drugstore)); }
public ActionResult EditDrugstore(Drugstore drugStore) { var drugstoretemp = unitOfWork.DrugStoreRepository.GetByID(drugStore.DrugstoreID); drugstoretemp.DrugstoreName = drugStore.DrugstoreName; drugstoretemp.Address = drugStore.Address; drugstoretemp.Coordinate = drugStore.Coordinate; drugstoretemp.DrugstoreTypeID = drugStore.DrugstoreTypeID; drugstoretemp.DistrictID = drugStore.DistrictID; unitOfWork.DrugStoreRepository.Update(drugstoretemp); unitOfWork.DrugStoreRepository.SaveChanges(); return(RedirectToAction("ListDrugstore")); // return View(drugStore); }
// GET: Drugstore/Edit/5 /*public ActionResult Edit(int? id) * { * if (id == null) * { * return new HttpStatusCodeResult(HttpStatusCode.BadRequest); * } * Drugstore drugstore = db.Drugstores.Find(id); * if (drugstore == null) * { * return HttpNotFound(); * } * ViewBag.CityId = new SelectList(db.Citys, "Id", "Name", drugstore.CityId); * return View(drugstore); * } */ public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var drugstoreViewModel = new DrugstoreViewModel { Drugstore = db.Drugstores.Include(i => i.Products).First(i => i.Id == id), }; if (drugstoreViewModel.Drugstore == null) { return(HttpNotFound()); } var drugstoreProduct = db.Products.ToList(); drugstoreViewModel.DrugstoresProducts = drugstoreProduct.Select(o => new SelectListItem { Text = o.Name, Value = o.Id.ToString() }); Drugstore drugstore = db.Drugstores.Find(id); if (drugstore == null) { return(HttpNotFound()); } drugstoreViewModel.ListItems = db.Citys.ToList().ConvertAll( a => { return(new SelectListItem() { Text = a.Name, Value = a.Id.ToString(), Selected = false }); }); return(View(drugstoreViewModel)); }
public ActionResult ImportExcel(HttpPostedFileBase file) { DataSet ds = new DataSet(); if (Request.Files["file"].ContentLength > 0) { string fileExtension = System.IO.Path.GetExtension(Request.Files["file"].FileName); if (fileExtension == ".xls" || fileExtension == ".xlsx") { string fileLocation = Server.MapPath("/Excel/") + Request.Files["file"].FileName; //if (System.IO.File.Exists(fileLocation)) //{ // System.IO.File.Delete(fileLocation); //} //Request.Files["file"].SaveAs(fileLocation); string excelConnectionString = string.Empty; excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; //connection String for xls file format. if (fileExtension == ".xls") { excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; } //connection String for xlsx file format. else if (fileExtension == ".xlsx") { excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=Excel 12.0;"; } //Create Connection to Excel work book and add oledb namespace OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); // OleDbConnection excelConnection = new System.Data.OleDb.OleDbConnection(excelConnectionString); excelConnection.Open(); DataTable dt = new DataTable(); dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (dt == null) { return(null); } String[] excelSheets = new String[dt.Rows.Count]; int t = 0; //excel data saves in temp file here. foreach (DataRow row in dt.Rows) { excelSheets[t] = row["TABLE_NAME"].ToString(); t++; } OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString); var test = excelSheets[0]; string query = string.Format("Select * from [{0}]", excelSheets[0]); using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1)) { dataAdapter.Fill(ds); } excelConnection1.Close(); excelConnection.Close(); } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { // string conn = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString; // SqlConnection con = new SqlConnection(conn); // string query = "Insert into Drugstore(DrugstoreName,Address) Values('" + ds.Tables[0].Rows[i][0].ToString() + "','" + ds.Tables[0].Rows[i][1].ToString() + "')";//query string // con.Open(); // SqlCommand cmd = new SqlCommand(query, con); // unitOfWork.DrugStoreRepository.dbSet.SqlQuery(query);// thực thi câu query // cmd.ExecuteNonQuery(); // con.Close(); try { Drugstore drugstore = new Drugstore(); drugstore.DrugstoreName = ds.Tables[0].Rows[i][0].ToString(); drugstore.Address = ds.Tables[0].Rows[i][1].ToString(); var coordinate = GetGeocode(ds.Tables[0].Rows[i][1].ToString()); drugstore.Coordinate = coordinate; drugstore.IsActive = true; var drugstoreTemp = unitOfWork.DrugStoreRepository.Get( b => b.DrugstoreName == drugstore.DrugstoreName && b.Coordinate == drugstore.Coordinate).ToList(); if (drugstoreTemp.Count == 0) { drugstore.DrugstoreTypeID = 3; unitOfWork.DrugStoreRepository.Insert(drugstore); unitOfWork.DrugStoreRepository.SaveChanges(); } } catch (Exception) { } } } return(RedirectToAction("ListDrugstore")); }
private double FindDistance(List<Drugstore> listStore, Drugstore point) { var centroid = FindCentroid(listStore); var point3D= Change(point); return GetDistance(centroid, point3D); }
private List<double> ChangeToCoordinate(Drugstore point) { List<double> result = new List<double>(); string[] temp = new string[2]; temp = point.Coordinate.Split(','); result.Add(double.Parse(temp[0])); result.Add(double.Parse(temp[1])); return result; }
public Point3D Change(Drugstore point) { List<double> listCoordinate = ChangeToCoordinate(point); return ChangeCoordinateMapToCoordinate3D(listCoordinate[0], listCoordinate[1]); }
public ActionResult EditDrugstore(Drugstore drugStore) { var drugstoretemp = unitOfWork.DrugStoreRepository.GetByID(drugStore.DrugstoreID); drugstoretemp.DrugstoreName = drugStore.DrugstoreName; drugstoretemp.Address = drugStore.Address; drugstoretemp.Coordinate = drugStore.Coordinate; drugstoretemp.DrugstoreTypeID = drugStore.DrugstoreTypeID; unitOfWork.DrugStoreRepository.Update(drugstoretemp); unitOfWork.DrugStoreRepository.SaveChanges(); return RedirectToAction("ListDrugstore"); // return View(drugStore); }
public ActionResult ImportExcel(HttpPostedFileBase file) { DataSet ds = new DataSet(); if (Request.Files["file"].ContentLength > 0) { string fileExtension = System.IO.Path.GetExtension(Request.Files["file"].FileName); if (fileExtension == ".xls" || fileExtension == ".xlsx") { string fileLocation = Server.MapPath("/Excel/") + Request.Files["file"].FileName; //if (System.IO.File.Exists(fileLocation)) //{ // System.IO.File.Delete(fileLocation); //} //Request.Files["file"].SaveAs(fileLocation); string excelConnectionString = string.Empty; excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; //connection String for xls file format. if (fileExtension == ".xls") { excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; } //connection String for xlsx file format. else if (fileExtension == ".xlsx") { excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=Excel 12.0;"; } //Create Connection to Excel work book and add oledb namespace OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); // OleDbConnection excelConnection = new System.Data.OleDb.OleDbConnection(excelConnectionString); excelConnection.Open(); DataTable dt = new DataTable(); dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (dt == null) { return null; } String[] excelSheets = new String[dt.Rows.Count]; int t = 0; //excel data saves in temp file here. foreach (DataRow row in dt.Rows) { excelSheets[t] = row["TABLE_NAME"].ToString(); t++; } OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString); var test = excelSheets[0]; string query = string.Format("Select * from [{0}]", excelSheets[0]); using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1)) { dataAdapter.Fill(ds); } excelConnection1.Close(); excelConnection.Close(); } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { // string conn = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString; // SqlConnection con = new SqlConnection(conn); // string query = "Insert into Drugstore(DrugstoreName,Address) Values('" + ds.Tables[0].Rows[i][0].ToString() + "','" + ds.Tables[0].Rows[i][1].ToString() + "')";//query string // con.Open(); // SqlCommand cmd = new SqlCommand(query, con); // unitOfWork.DrugStoreRepository.dbSet.SqlQuery(query);// thực thi câu query // cmd.ExecuteNonQuery(); // con.Close(); try { Drugstore drugstore = new Drugstore(); drugstore.DrugstoreName = ds.Tables[0].Rows[i][0].ToString(); drugstore.Address = ds.Tables[0].Rows[i][1].ToString(); var coordinate = GetGeocode(ds.Tables[0].Rows[i][1].ToString()); drugstore.Coordinate = coordinate; drugstore.IsActive = true; var drugstoreTemp = unitOfWork.DrugStoreRepository.Get( b => b.DrugstoreName == drugstore.DrugstoreName && b.Coordinate == drugstore.Coordinate).ToList(); if (drugstoreTemp.Count == 0) { drugstore.DrugstoreTypeID = 3; unitOfWork.DrugStoreRepository.Insert(drugstore); unitOfWork.DrugStoreRepository.SaveChanges(); } } catch (Exception) { } } } return RedirectToAction("ListDrugstore"); }
private double FindDistance2D(List<Drugstore> listStore, Drugstore point) { var centroid = FindCentroid2D(listStore); var temp = ChangeToCoordinate(point); var point2D = new Point2D(); point2D.x = temp[0]; point2D.y = temp[1]; return GetDistance(centroid, point2D); }
public Point3D Change(Drugstore point) { List <double> listCoordinate = ChangeToCoordinate(point); return(ChangeCoordinateMapToCoordinate3D(listCoordinate[0], listCoordinate[1])); }
public List <Tuple <List <Drugstore>, string> > DoKMeans(List <Drugstore> listStore, int clusterCount) { var allGroups = new List <List <Drugstore> >(); var result = new List <Tuple <List <Drugstore>, string> >(); //devide all group into some group for (int i = 0; i < clusterCount; i++) { var tempList = new List <Drugstore>(); for (int j = 0; j < listStore.Count; j++) { if (j % clusterCount == i) { tempList.Add(listStore[j]); } } allGroups.Add(tempList); } int movement = 1; int movementMax = 0; //while (movement > 0 && movementMax<100) //{ while (movement > 0) { movement = 0; movementMax++; for (int i = 0; i < allGroups.Count; i++) { List <Drugstore> tempList = allGroups[i]; for (int j = 0; j < tempList.Count; j++) { Drugstore tempPoint = tempList[j]; int neareastCluster = -1; double currDistance = double.MaxValue; for (int k = 0; k < allGroups.Count; k++) { double findDistance = FindDistance2D(allGroups[k], tempPoint); if (findDistance < currDistance) { neareastCluster = k; currDistance = findDistance; } } //if (neareastCluster != j) if (neareastCluster != i) { if (tempList.Count > 1) { tempList.Remove(tempPoint); allGroups[neareastCluster].Add(tempPoint); movement++; } } } } } for (int i = 0; i < allGroups.Count; i++) { result.Add( new Tuple <List <Drugstore>, string> ( allGroups[i], ChangeCoordinate2DToCoordinateMap(FindCentroid2D(allGroups[i])) ) ); } return(result); }
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!" })); }
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!" }); }