private async void Btn_deleteTodo_Click(object sender, EventArgs e) { string url = "https://localhost:5001/api/Task/delete?taskId=" + task.TaskId; XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <Models.Task>)); Client client = new Client(); try { HttpResponseMessage result = await client.Delete(url); if (result.IsSuccessStatusCode) { delegate_Get(); } else { using (Form_Tips tip = new Form_Tips("警告", "初始化信息失败")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private async void GetSiteName() { string url = "https://localhost:5001/api/site/get?siteId=" + siteId; XmlSerializer xmlSerializer = new XmlSerializer(typeof(Site)); Client client = new Client(); try { HttpResponseMessage result = await client.Get(url); if (result.IsSuccessStatusCode) { Site site = (Site)xmlSerializer.Deserialize(await result.Content.ReadAsStreamAsync()); siteName = site.SiteName; this.Btn_ToSiteInfo.Text = siteName; } else { using (Form_Tips tip = new Form_Tips("警告", "获取失败")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public async void InitInfo() { string url = "https://localhost:5001/api/route/get?travelId=" + travelId; XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <Route>)); Client client = new Client(); try { HttpResponseMessage result = await client.Get(url); if (result.IsSuccessStatusCode) { List <Route> routes = (List <Route>)xmlSerializer.Deserialize(await result.Content.ReadAsStreamAsync()); flowLayoutPanel_route.Controls.Clear(); foreach (Route route in routes) { UC_Site cell = new UC_Site(changePanel, travelTitle, travelId, route.RouteId, route.StartSiteId); //添加到panel中 flowLayoutPanel_route.Controls.Add(cell); } } else { using (Form_Tips tip = new Form_Tips("警告", "获取失败")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private async void Btn_deleteTravel_Click(object sender, EventArgs e) { string url = "https://localhost:5001/api/Travel/delete?travelId=" + travelID; Client client = new Client(); try { HttpResponseMessage result = await client.Delete(url); if (result.IsSuccessStatusCode) { init(); } else { using (Form_Tips tip = new Form_Tips("警告", "初始化信息失败")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private async void Btn_ToSiteInfo_Click(object sender, EventArgs e) { string url = "https://localhost:5001/api/route?routeId=" + routeID; XmlSerializer xmlSerializer = new XmlSerializer(typeof(Route)); Client client = new Client(); try { HttpResponseMessage result = await client.Get(url); if (result.IsSuccessStatusCode) { Route route = (Route)xmlSerializer.Deserialize(await result.Content.ReadAsStreamAsync()); UC_SiteInfo uc_siteInfo = new UC_SiteInfo(changePanel, travelTitle, travelId, false, routeID, siteId); uc_siteInfo.delegate_Get = new delegate_getTask(uc_siteInfo.getTask); changePanel(uc_siteInfo); } else { using (Form_Tips tip = new Form_Tips("警告", "获取失败")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private async void Btn_delete_Click(object sender, EventArgs e) { string url = "https://localhost:5001/api/Route/delete?routeId=" + route.RouteId; Client client = new Client(); try { HttpResponseMessage result = await client.Delete(url); if (result.IsSuccessStatusCode) { UC_AllSites uc_as = new UC_AllSites(changePanel, TravelTitle, travelId); changePanel(uc_as); } else { using (Form_Tips tip = new Form_Tips("警告", "初始化信息失败")) { tip.ShowDialog(); } } } catch (Exception ex) { using (Form_Tips tip = new Form_Tips("警告", ex.Message)) { tip.ShowDialog(); } } }
public async void getTask() { string url = "https://localhost:5001/api/Task/get?routeId=" + route.RouteId; XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <Models.Task>)); Client client = new Client(); flowLayoutPanel_todo.Controls.Clear(); try { HttpResponseMessage result = await client.Get(url); if (result.IsSuccessStatusCode) { List <Models.Task> tasks = (List <Models.Task>)xmlSerializer.Deserialize(await result.Content.ReadAsStreamAsync()); foreach (Models.Task task in tasks) { UC_Todo cell = new UC_Todo(task, delegate_Get); //添加到panel中 flowLayoutPanel_todo.Controls.Add(cell); } } else { using (Form_Tips tip = new Form_Tips("警告", "初始化信息失败")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private async void initinfo() { string url = "https://localhost:5001/api/route?routeId=" + route.RouteId; XmlSerializer xmlSerializer = new XmlSerializer(typeof(Route)); Client client = new Client(); try { HttpResponseMessage result = await client.Get(url); if (result.IsSuccessStatusCode) { Route route = (Route)xmlSerializer.Deserialize(await result.Content.ReadAsStreamAsync()); this.Txtbos_vehicle.Text = route.Method; this.dateTimePicker1.Value = route.StartTime; this.dateTimePicker2.Value = route.EndTime; getTask(); GetSiteName(); } else { using (Form_Tips tip = new Form_Tips("警告", "初始化信息失败")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private async void Btn_addtodo_Click(object sender, EventArgs e) { if (TxtBox_todo.Text.Length == 0) { using (Form_Tips tip = new Form_Tips("警告", "待办事项为空")) { tip.ShowDialog(); } } else { Models.Task task = new Models.Task(); task.State = 0; task.RouteId = route.RouteId; task.Description = TxtBox_todo.Text; string url = "https://localhost:5001/api/Task"; XmlSerializer xmlSerializer = new XmlSerializer(typeof(Models.Task)); Client client = new Client(); try { string data = ""; using (StringWriter sw = new StringWriter()) { xmlSerializer.Serialize(sw, task); data = sw.ToString(); } HttpResponseMessage result = await client.Post(url, data); if (result.IsSuccessStatusCode) { TxtBox_todo.Text = ""; flowLayoutPanel_todo.Controls.Clear(); getTask(); } else { using (Form_Tips tip = new Form_Tips("警告", result.StatusCode.ToString())) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
private async void BtnShare_Click(object sender, EventArgs e) { //进行分享 if (btnShare.Text.Equals("已分享")) { DialogResult dr = MessageBox.Show("确定取消分享?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (dr == DialogResult.Yes) { //修改数据库 Diary diary = await GetDiary(); diary.Share = 0; if (await PutDiary(diary)) { using (Form_Tips tip = new Form_Tips("提示", "修改成功")) { tip.ShowDialog(); } } btnShare.Text = "分享"; } } else if (btnShare.Text.Equals("分享")) { DialogResult dr; using (Form_Tips tip = new Form_Tips("提示", "确定进行分享?")) { tip.ShowDialog(); dr = tip.DialogResult; } if (dr == DialogResult.Yes) { //修改数据库 Diary diary = await GetDiary(); diary.Share = 1; if (await PutDiary(diary)) { using (Form_Tips tip = new Form_Tips("提示", "修改成功")) { tip.ShowDialog(); } } btnShare.Text = "已分享"; } } }
private async void Cbx_todo_CheckedChanged(object sender, EventArgs e) { if (Cbx_todo.Checked == true) { task.State = 1; } else { task.State = 0; } string url = "https://localhost:5001/api/Task/update?taskId=" + task.TaskId; XmlSerializer xmlSerializer = new XmlSerializer(typeof(Models.Task)); Client client = new Client(); try { string data = ""; using (StringWriter sw = new StringWriter()) { xmlSerializer.Serialize(sw, task); data = sw.ToString(); } HttpResponseMessage result = await client.Put(url, data); if (result.IsSuccessStatusCode) { } else { using (Form_Tips tip = new Form_Tips("警告", result.StatusCode.ToString())) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private async void BtnAddPic_Click(object sender, EventArgs e) { string filePath = ""; FileClient fileClient = new FileClient(); //添加图片:打开文件管理器,选择图片进行上传 OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "选择上传的图片"; openFileDialog.InitialDirectory = @"C:\"; openFileDialog.Filter = "图片文件|*.jpg;*.gif;*.jpeg;*.png"; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { filePath = Path.GetFullPath(openFileDialog.FileName); } try { if (await fileClient.Upload(this.DiaryId, filePath)) { using (Form_Tips tip = new Form_Tips("提示", "上传成功")) { tip.ShowDialog(); } ImgRefresh(); } else { using (Form_Tips tip = new Form_Tips("提示", "上传失败")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message + "上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private async void BtnSave_Click(object sender, EventArgs e) { //保存修改 tbTitle.Enabled = false; btnSave.Enabled = false; btnAddPic.Enabled = false; rtbDescription.Enabled = false; //将修改传到远端 Diary diary = await GetDiary(); diary.Title = tbTitle.Text; diary.Description = rtbDescription.Text; if (await PutDiary(diary)) { using (Form_Tips tip = new Form_Tips("提示", "修改成功")) { tip.ShowDialog(); } } //将编辑激活 btnEdit.Enabled = true; btnEdit.Text = "编辑"; }
private async void Btn_Comfirm_Click(object sender, EventArgs e) { if (isCreate == false) { string url = "https://localhost:5001/api/route?routeId=" + route.RouteId; string url2 = "https://localhost:5001/api/route/update?routeId=" + route.RouteId; XmlSerializer xmlSerializer = new XmlSerializer(typeof(Route)); Client client = new Client(); try { string data = ""; HttpResponseMessage result = await client.Get(url); if (result.IsSuccessStatusCode) { Route route = (Route)xmlSerializer.Deserialize(await result.Content.ReadAsStreamAsync()); route.Method = this.Txtbos_vehicle.Text; route.StartTime = this.dateTimePicker1.Value; route.EndTime = this.dateTimePicker2.Value; using (StringWriter sw = new StringWriter()) { xmlSerializer.Serialize(sw, route); data = sw.ToString(); } result = await client.Put(url2, data); if (!result.IsSuccessStatusCode) { using (Form_Tips tip = new Form_Tips("提示", "修改失败")) { tip.ShowDialog(); } } } else { using (Form_Tips tip = new Form_Tips("警告", "信息有误")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { string url = "https://localhost:5001/api/route"; string urlOfSite = "https://localhost:5001/api/Site"; XmlSerializer xmlSerializerForRoute = new XmlSerializer(typeof(Route)); XmlSerializer xmlSerializerForSite = new XmlSerializer(typeof(Site)); Client client = new Client(); try { string data = ""; string dataOfSite = ""; Route routeToSend = new Route(); routeToSend.Method = this.Txtbos_vehicle.Text; routeToSend.StartTime = this.dateTimePicker1.Value; routeToSend.EndTime = this.dateTimePicker2.Value; routeToSend.TravelId = travelId; Site site = new Site(); site = sites[comboBox_site.Text]; routeToSend.StartSiteId = site.SiteId; //添加site using (StringWriter sw = new StringWriter()) { xmlSerializerForRoute.Serialize(sw, routeToSend); data = sw.ToString(); } using (StringWriter sw = new StringWriter()) { xmlSerializerForSite.Serialize(sw, site); dataOfSite = sw.ToString(); } HttpResponseMessage resultOfSite = await client.Post(urlOfSite, dataOfSite); HttpResponseMessage result = new HttpResponseMessage(); if (resultOfSite.IsSuccessStatusCode) { result = await client.Post(url, data); } if (result.IsSuccessStatusCode) { Route newRoute = (Route)xmlSerializerForRoute.Deserialize(await result.Content.ReadAsStreamAsync()); routeToSend = newRoute; isCreate = false; } else { using (Form_Tips tip = new Form_Tips("警告", "信息有误")) { tip.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }