public FormForStorage(Login_token tokens, string json) { InitializeComponent(); productList = json; tokens_info = tokens; JArray pArray = JArray.Parse(productList); IList <Product> result = pArray.Select(p => new Product { id = (string)p["id"], store = (string)p["store"], qrcode = (string)p["product"]["qrcode"], name = (string)p["product"]["name"], description = (string)p["product"]["desciption"], base_unit = (string)p["product"]["base_unit"], price = (string)p["product"]["price"], picture_path = (string)p["product"]["picture_path"], category = (string)p["product"]["category"], quantity = (string)p["quantity"], active = (string)p["active"] }).ToList(); int numberOfProducts = result.Count; for (int index = 0; index < numberOfProducts; ++index) { ListViewItem item = new ListViewItem(); // items[0].Tag = result.ElementAt(0); productBox.Items.Add(item); item.Text = result.ElementAt(index).qrcode; item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).name }); item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).price }); item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).base_unit }); item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).category }); item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).quantity }); } }
public ProductTable(Login_token tokens, string json) { InitializeComponent(); productList = json; JArray pArray = JArray.Parse(productList); IList <Product> result = pArray.Select(p => new Product { id = (string)p["id"], store = (string)p["store"], qrcode = (string)p["product"]["qrcode"], name = (string)p["product"]["name"], description = (string)p["product"]["desciption"], base_unit = (string)p["product"]["base_unit"], price = (string)p["product"]["price"], picture_path = (string)p["product"]["picture_path"], category = (string)p["product"]["category"], quantity = (string)p["quantity"], active = (string)p["active"] }).ToList(); temp = result; //resultBox.Text = productList; tokens_info = tokens; intro.Text = "Welcome " + tokens.username; // BAT DAU TAI DAY, DE XU LI STRING // hien thi san pham int numberOfProducts = result.Count; // DANG CODE O DAY //while (numberOfProducts >= 0) for (int index = 0; index < numberOfProducts; ++index) { ListViewItem item = new ListViewItem(); // items[0].Tag = result.ElementAt(0); ProductBox.Items.Add(item); item.Text = result.ElementAt(index).qrcode; item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).name }); item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).price }); item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).base_unit }); item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).category }); item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).description }); item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = result.ElementAt(index).quantity }); } }
private void button1_Click(object sender, EventArgs e) { // dang nhap va lay access token cho nhung lan truy cap sau var client = new RestClient("https://phamthoai-store-management.herokuapp.com/api/token/"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\"username\": \"" + tokens_info.username + "\",\"password\": \"" + tokens_info.pass + "\"}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); if (response.StatusCode.ToString() != "OK") { status.Visible = true; status.Text = "Login failed"; } else { // Neu dang nhap thanh cong, chuyen sang trang hien thi tat ca san pham cua store string json = response.Content; Login_token tokens = JsonConvert.DeserializeObject <Login_token>(json); tokens_info.access = tokens.access; tokens_info.refresh = tokens.refresh; var client1 = new RestClient("https://phamthoai-store-management.herokuapp.com/api/stores/products/"); client1.Timeout = -1; var request1 = new RestRequest(Method.GET); request1.AddHeader("Authorization", "Bearer " + tokens.access); IRestResponse response1 = client1.Execute(request1); if (response1.StatusCode.ToString() != "OK") { string error_text = response1.Content; if (response1.StatusCode.ToString() == "Unauthorized") { error_text = "Given token not valid for any token type"; } if (response1.StatusCode.ToString() == "BadRequest") { error_text = "You have not permission!"; } status.Visible = true; status.Text = "Can't access to the store products, " + error_text; } else { var client2 = new RestClient("https://phamthoai-store-management.herokuapp.com/api/users/check_permissions/"); client2.Timeout = -1; var request2 = new RestRequest(Method.GET); request2.AddHeader("Authorization", "Bearer " + tokens_info.access); IRestResponse response2 = client2.Execute(request2); string json2 = response2.Content; PermissionCheck check = JsonConvert.DeserializeObject <PermissionCheck>(json2); string json1 = response1.Content; if (check.import_invoice == "false") { ProductTable pTable = new ProductTable(tokens_info, json1); username_input.Text = pass_input.Text = ""; //this.Hide(); pTable.ShowDialog(); //this.Show(); //HTTPresponseBox.Text = response1.Content; } else { FormForStorage pStrorage = new FormForStorage(tokens_info, json1); username_input.Text = pass_input.Text = ""; pStrorage.ShowDialog(); } } } }