public void GetGroups() { try { using (WebClient client = new WebClient()) { client.Encoding = Encoding.UTF8; string data = client.DownloadString(About.Server + "Groups"); data = data.Remove(data.Length - 2); data = data.Substring(2, data.Length - 2); GroupList.Children.Clear(); comboBox_ProductCombo.Items.Clear(); foreach (var row in data.Split(new string[] { "},{" }, StringSplitOptions.None)) { GroupUserControl groupUserControl = new GroupUserControl(); ComboBoxItem comboItem = new ComboBoxItem(); foreach (var column in row.Split(',')) { string[] values = column.Split(':'); values[0] = values[0].Remove(values[0].Length - 1); values[0] = values[0].Substring(1, values[0].Length - 1); values[1] = values[1].Remove(values[1].Length - 1); values[1] = values[1].Substring(1, values[1].Length - 1); if (values[0] == "Name") { groupUserControl.GroupName = values[1]; comboItem.Content = values[1]; } else if (values[0] == "Id") { groupUserControl.Id = new Guid(values[1]); comboItem.Tag = values[1]; } } comboBox_ProductCombo.Items.Add(comboItem); GroupList.Children.Add(groupUserControl); } } } catch { MessageBox.Show("خطا در دریافت اطلاعات از سرور"); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { using (WebClient client = new WebClient()) { client.Encoding = Encoding.UTF8; string data = client.DownloadString(About.Server + "Groups"); data = data.Remove(data.Length - 2); data = data.Substring(2, data.Length - 2); comboBox_Group.Items.Clear(); foreach (var row in data.Split(new string[] { "},{" }, StringSplitOptions.None)) { GroupUserControl groupUserControl = new GroupUserControl(); ComboBoxItem comboItem = new ComboBoxItem(); foreach (var column in row.Split(',')) { string[] values = column.Split(':'); values[0] = values[0].Remove(values[0].Length - 1); values[0] = values[0].Substring(1, values[0].Length - 1); values[1] = values[1].Remove(values[1].Length - 1); values[1] = values[1].Substring(1, values[1].Length - 1); if (values[0] == "Name") { groupUserControl.GroupName = values[1]; comboItem.Content = values[1]; } else if (values[0] == "Id") { groupUserControl.Id = new Guid(values[1]); comboItem.Tag = values[1]; } } comboBox_Group.Items.Add(comboItem); data = client.DownloadString(About.Server + "Products/" + ProductId); data = data.Remove(data.Length - 1); data = data.Substring(1, data.Length - 1); foreach (string column in data.Split(new string[] { "," }, StringSplitOptions.None)) { string[] item = column.Split(':'); item[0] = item[0].Remove(item[0].Length - 1); item[0] = item[0].Substring(1, item[0].Length - 1); item[1] = item[1].Remove(item[1].Length - 1); item[1] = item[1].Substring(1, item[1].Length - 1); if (item[0] == "ProductName") { textbox_Name.Text = item[1]; } else if (item[0] == "ProductDescription") { textbox_Description.Text = item[1]; } } } } } catch { System.Windows.MessageBox.Show("خطا در دریافت اطلاعات از سرور"); Close(); } }