private void 刷新FToolStripMenuItem_Click(object sender, EventArgs e) { ServiceFormViewModel service = new ServiceFormViewModel(); var ds = service.GetList(); gridControl1.DataSource = ds.Tables[0]; }
public async Task <IActionResult> Edit([FromQuery] string host = null, [FromQuery] int port = 0) { var registry = await services.GetRegistry(); var viewModel = new ServiceFormViewModel(registry.Entries); var registryEntry = registry.Entries.FirstOrDefault(x => x.EndPoint.Equals(new EndPoint(host, port))); if (registryEntry != null) { viewModel.Name = registryEntry.Name; viewModel.Host = registryEntry.Host; viewModel.Port = registryEntry.Port; viewModel.Database = registryEntry.Database; viewModel.Tags = string.Join(",", registryEntry.Tags); } var configEntry = config.Get().Services.FirstOrDefault(x => x.ToEndPoint().Equals(new EndPoint(host, port))); if (configEntry != null) { foreach (var forwardEntry in configEntry.ForwardingTo) { var forwardRegistryEntry = registry.Entries.First(x => x.EndPoint.Equals(new EndPoint(forwardEntry.Host, forwardEntry.Port))); forwardRegistryEntry.Selected = true; viewModel.Forwards.Add(forwardRegistryEntry); } } return(View(viewModel)); }
public void AddServiceToConfigAndStart(ServiceFormViewModel service) { var config = this.config.Get(); var sqlDServiceModel = new SqlDServiceModel() { Name = service.Name, Database = service.Database, Host = service.Host, Port = service.Port, Tags = (service.Tags ?? string.Empty).Split(',').ToList(), }; var registryEntryViewModels = service.Forwards.Where(x => x.Selected).ToList(); if (registryEntryViewModels.Any()) { sqlDServiceModel.ForwardingTo.AddRange(registryEntryViewModels.Select(y => new SqlDForwardingModel() { Host = y.Host, Port = y.Port })); } config.Services.Add(sqlDServiceModel); this.config.Set(config); SqlDStart.SqlDGo(typeof(ServiceService).Assembly, config); }
private void ServiceForm_Load(object sender, EventArgs e) { ServiceFormViewModel service = new ServiceFormViewModel(); var ds = service.GetList(); gridControl1.DataSource = ds.Tables[0]; }
public ActionResult New() { var viewModel = new ServiceFormViewModel { Service = new Service() }; return(View("ServiceForm", viewModel)); }
public IActionResult Launch([FromForm] ServiceFormViewModel formViewModel) { if (ModelState.IsValid) { services.AddServiceToConfigAndStart(formViewModel); return(Redirect("/service")); } return(View(formViewModel)); }
public IActionResult Edit([FromForm] ServiceFormViewModel formViewModel) { if (ModelState.IsValid) { services.UpdateServiceAndRestart(formViewModel); return(Redirect("/service")); } return(View(formViewModel)); }
public ActionResult Details(int id) { var service = serviceRepository.Get(id); var viewModel = new ServiceFormViewModel { Service = service }; return(View(viewModel)); }
public ActionResult New() { var viewModel = new ServiceFormViewModel { Service = new Service(), ServiceTypes = _context.ServiceTypes.ToList(), Option = "New" }; return(View("ServiceForm", viewModel)); }
public ActionResult CreateOrUpdate(ServiceFormViewModel viewModel) // model binding { viewModel.Service.ServiceName = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(viewModel.Service.ServiceName.ToLower()); if (viewModel.Service.Id == 0) // Create { serviceRepository.Insert(viewModel.Service); return(RedirectToAction("ServiceList", "Service")); } else // Update { var service = serviceRepository.Update(viewModel.Service); return(RedirectToAction("ServiceList", "Service")); } }
public ActionResult Edit(int id) { var service = _context.Services.SingleOrDefault(s => s.Id == id); if (service == null) { return(HttpNotFound()); } var viewModel = new ServiceFormViewModel() { Service = service }; return(View("ServiceForm", viewModel)); }
public ActionResult Save(Service service) { //Check if the form is valid if (!ModelState.IsValid) { //Return the same form back to the user var viewModel = new ServiceFormViewModel { Service = service, ServiceTypes = _context.ServiceTypes.ToList(), Option = "New" }; return(View("ServiceForm", viewModel)); } using (var ms = new MemoryStream()) { service.File.InputStream.CopyTo(ms); service.Image = ms.ToArray(); } //new service if (service.ServiceID == 0) { _context.Services.Add(service); } else { var serviceInDB = _context.Services.Single(p => p.ServiceID == service.ServiceID); //Manual update serviceInDB.ServiceName = service.ServiceName; serviceInDB.ServiceDetail = service.ServiceDetail; serviceInDB.ServiceTypeID = service.ServiceTypeID; serviceInDB.Image = service.Image; serviceInDB.File = service.File; } _context.SaveChanges(); return(RedirectToAction("Index", "Services")); }
public ActionResult Edit(int?id) { if (!id.HasValue) { return(HttpNotFound()); } var serviceInDB = _context.Services.SingleOrDefault(p => p.ServiceID == id); if (serviceInDB == null) { return(HttpNotFound()); } var viewModel = new ServiceFormViewModel() { Service = serviceInDB, ServiceTypes = _context.ServiceTypes.ToList(), Option = "Edit" }; return(View("ServiceForm", viewModel)); }
public void UpdateServiceAndRestart(ServiceFormViewModel service) { var config = this.config.Get(); var sqlDServiceModel = config.Services.First(x => x.ToEndPoint().Equals(new EndPoint(service.Host, service.Port))); var registryEntryViewModels = service.Forwards.Where(x => x.Selected).ToList(); if (registryEntryViewModels.Any()) { sqlDServiceModel.ForwardingTo = new List <SqlDForwardingModel>(); sqlDServiceModel.ForwardingTo.AddRange(registryEntryViewModels.Select(y => new SqlDForwardingModel() { Host = y.Host, Port = y.Port })); } this.config.Set(config); KillService(sqlDServiceModel.Host, sqlDServiceModel.Port, removeFromConfig: false); SqlDStart.SqlDGo(typeof(ServiceService).Assembly, config); }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("确定删除吗?", "重要提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } else { var list = this.gridView1.GetSelectedRows(); if (list.Length == 0) { MessageBox.Show("请至少勾选一条数据做删除"); } else { //保存id的数组 List <int> list_id = new List <int>(); var dt = gridControl1.DataSource as DataTable; for (int i = 0; i < list.Count(); i++) { var row = dt.Rows[list[i]]; int id = Convert.ToInt32(row["ID"]); list_id.Add(id); } ServiceFormViewModel service = new ServiceFormViewModel(); if (service.Delete(list_id)) { if (MessageBox.Show("删除成功!", "提示") == DialogResult.OK) { var ds = service.GetList(); gridControl1.DataSource = ds.Tables[0]; } } } } }