Ir para conteúdo

Pedro João

Members
  • Total de itens

    2
  • Registro em

  • Última visita

Reputação

0 Comum

Sobre Pedro João

  1. Boa tarde Pessoal, sou novato na programação , estou uma dificuldade de enviar na base de dados local (Sql Server), lembrando que existe um metodo private void PopulateallFields() que me permite visualizar alguns dados na textbox, mas os dados são solicitado apartir de um ficheiro json na WebAPi public class BranchMethod { public List<Branches> GetBranchList(string url, string authtoken, string passkey, out string ReasonPhrase,Guid pkorganization) { try { List<Branches> list = new List<Branches>(); url = "http://" + url + "/webapi"; HttpClient clientorg = new HttpClient(); clientorg.BaseAddress = new Uri(url); clientorg.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", authtoken); clientorg.DefaultRequestHeaders.Add("passkey", passkey); string webapi = "WebApi/v1.0/Branches"; HttpResponseMessage getresponses = clientorg.GetAsync(webapi).Result; if (getresponses.IsSuccessStatusCode) { var branches = JObject.Parse(getresponses.Content.ReadAsStringAsync().Result); if (branches["value"].ToString() != "" && branches["value"] != null) { var organisation = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Branches>>(branches["value"].ToString()).Where(p => p.PkOrganization == pkorganization).ToList(); list = organisation; } } ReasonPhrase = getresponses.ReasonPhrase; return list; } catch (Exception ex) { throw ex; } } } Método de Inserir os valores na textbox atravez das chamadas Web private void PopulateallFields() { try { TokenMethods objtoken = new TokenMethods(); LoginMethod objlogin = new LoginMethod(); CompanyMethod objcmp = new CompanyMethod(); BranchMethod objbranch = new BranchMethod(); DeviceTypesMethod objdevicetypes = new DeviceTypesMethod(); ddlNetlogiaUrl.SelectedItem = Url; if (TokenMethods.authtoken != "") { string val = ""; List<Companies> listcmp = objcmp.GetCompanyList(Url, TokenMethods.authtoken, LoginMethod.Passkey, out val); if (val == "OK") { // Listar todas empresas criada na Internet. if (listcmp.Count > 0) { cmbOrganization.DisplayMember = "Nome"; cmbOrganization.ValueMember = "ID"; // Listar a empresa cmbOrganization.DataSource = listcmp; btnRefreshOrg.Enabled = true; ; if (cmbOrganization.SelectedValue.ToString() != "") { List<Branches> listbranch = objbranch.GetBranchList(Url, TokenMethods.authtoken, LoginMethod.Passkey, out val, Guid.Parse(cmbOrganization.SelectedValue.ToString())); if (val == "OK") { if (listbranch.Count > 0) { //Class_Conection connection = new Class_Conection(); // connection.conn.Open(); // SqlDataAdapter da = new SqlDataAdapter(); // int X; // string insertData = " Insert into ORGBranches (Pk, Name) values (@Pk, @Name)"; cmbBranch.DisplayMember = "Name"; cmbBranch.ValueMember = "Pk"; cmbBranch.DataSource = listbranch; SqlCommand cmd = new SqlCommand(insertData, connection.conn); cmd.CommandText = insertData; cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@Code",3); cmd.Parameters.AddWithValue("@Name", cmbBranch.Text); X = cmd.ExecuteNonQuery(); // Listar as Filiares. btnRefreshBranch.Enabled = true; List<DeviceTypes> listDeviceTypes = objdevicetypes.GetDevicetypeList(Url, TokenMethods.authtoken, LoginMethod.Passkey, out val); if (val == "OK") { if (listDeviceTypes.Count > 0) { cmbDeviceType.DisplayMember = "Nome"; cmbDeviceType.ValueMember = "ID"; cmbDeviceType.DataSource = listDeviceTypes; //btnRefreshDeviceType.Enabled = true; //btnRefreshDevice.Enabled = true; btnFilter.Enabled = true; btnApplyDevice.Enabled = true; } else { MessageBox.Show("No Devicetypes Found "); } } } catch (Exception ex) { throw ex; } } Muito obrigado.
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.