public JsonConverter listaPrzesylekDlaKuriera(string courierId) { //pobranie connection string z webconfig System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/PROJEKT"); System.Configuration.ConnectionStringSettings connString = rootWebConfig.ConnectionStrings.ConnectionStrings["KurierProBazaSystemu"]; SqlConnection con = null; SqlDataReader dr; // deklaracja obiektu SqlDataReader o nazwie dr JsonConverter converter = new JsonConverter(); try { con = new SqlConnection(connString.ConnectionString); SqlCommand cmd = new SqlCommand("SELECT * FROM [Dostawy] WHERE IdKuriera = @courierID", con); // SqlCommand cmd = new SqlCommand("SELECT * FROM [Dostawy] WHERE IdKuriera = 1112", con);// cmd.Parameters.Add("@courierID", SqlDbType.NVarChar).Value = Request.QueryString["id_kuriera"]; con.Open(); dr = cmd.ExecuteReader(); while (dr.Read())//dr.HasRows == true) { //status jako klucz glowny converter.StartVector(Convert.ToString(dr.GetValue(0)));//jedna para for (int i = 9; i <= 15; i++)//kolumny 9-15 //.GetString converter.AddKey(dr.GetName(i), Convert.ToString(dr.GetValue(i)));//jedna para //kwota pobrania converter.AddKey(dr.GetName(25), Convert.ToString(dr.GetValue(25)));//jedna para converter.EndVector(); } con.Close(); } catch (Exception ex) { } return converter; }
protected void Page_Load(object sender, EventArgs e) { string input; Boolean inputOk = false; string trackNum = "Bad data"; JsonConverter converter = new JsonConverter(); using (var reader = new StreamReader(Request.InputStream)) { input = reader.ReadToEnd(); } //przetwarzanie jsona//// if (input.Length > 0) { trackNum = dodajNowaPrzesylke(input); if(trackNum.IndexOf("[ERROR]") == -1) inputOk = true; /* Dictionary<string, string> dict = converter.JsonToDictionary(input, "NadImie"); //pobranie connection string z webconfig System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/PROJEKT"); System.Configuration.ConnectionStringSettings connString = rootWebConfig.ConnectionStrings.ConnectionStrings["KurierProBazaSystemu"]; SqlConnection con = null; SqlDataReader dr; // deklaracja obiektu SqlDataReader o nazwie dr try { con = new SqlConnection(connString.ConnectionString); SqlCommand cmd = new SqlCommand("DodajPrzesylke", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@NadImie", SqlDbType.NVarChar).Value = dict["NadImie"]; cmd.Parameters.Add("@NadNazwisko", SqlDbType.NVarChar).Value = dict["NadNazwisko"]; cmd.Parameters.Add("@NadMiasto", SqlDbType.NVarChar).Value = dict["NadMiasto"]; cmd.Parameters.Add("@NadUlica", SqlDbType.NVarChar).Value = dict["NadUlica"]; cmd.Parameters.Add("@NadNumerUlicy", SqlDbType.Int).Value = Convert.ToInt32(dict["NadNumerUlicy"]); cmd.Parameters.Add("@NadNumerDomu", SqlDbType.Int).Value = Convert.ToInt32(dict["NadNumerDomu"]); cmd.Parameters.Add("@NadKraj", SqlDbType.NVarChar).Value = dict["NadKraj"]; cmd.Parameters.Add("@CelImie", SqlDbType.NVarChar).Value = dict["CelImie"]; cmd.Parameters.Add("@CelNazwisko", SqlDbType.NVarChar).Value = dict["CelNazwisko"]; cmd.Parameters.Add("@CelMiasto", SqlDbType.NVarChar).Value = dict["CelMiasto"]; cmd.Parameters.Add("@CelUlica", SqlDbType.NVarChar).Value = dict["CelUlica"]; cmd.Parameters.Add("@CelNumerUlicy", SqlDbType.Int).Value = Convert.ToInt32(dict["CelNumerUlicy"]); cmd.Parameters.Add("@CelNumerDomu", SqlDbType.Int).Value = Convert.ToInt32(dict["CelNumerDomu"]); cmd.Parameters.Add("@CelKraj", SqlDbType.NVarChar).Value = dict["CelKraj"]; cmd.Parameters.Add("@Masa", SqlDbType.Float).Value = Convert.ToDouble(dict["Masa"].Replace('.', ',')); cmd.Parameters.Add("@GabX", SqlDbType.Float).Value = Convert.ToDouble(dict["GabX"].Replace('.', ',')); cmd.Parameters.Add("@GabY", SqlDbType.Float).Value = Convert.ToDouble(dict["GabY"].Replace('.', ',')); cmd.Parameters.Add("@GabZ", SqlDbType.Float).Value = Convert.ToDouble(dict["GabZ"].Replace('.', ',')); cmd.Parameters.Add("@Pobranie", SqlDbType.Bit).Value = Convert.ToBoolean(dict["Pobranie"]); cmd.Parameters.Add("@KwotaPobrania", SqlDbType.Float).Value = Convert.ToDouble(dict["KwotaPobrania"].Replace('.', ',')); cmd.Parameters.Add("@numer_przesylki_out", SqlDbType.BigInt); cmd.Parameters["@numer_przesylki_out"].Direction = ParameterDirection.Output; con.Open(); cmd.ExecuteNonQuery(); con.Close(); trackNum = cmd.Parameters["@numer_przesylki_out"].Value.ToString(); inputOk = true; } catch (Exception ex) { trackNum = ex.Message; } */ } ///////////////////////// if (inputOk) //nie ma errora { converter.AddKey("trackNum", trackNum); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; //Response.Write("{\"trackNum\":" + "\"" + trackNum + "\"}"); Response.Write(converter.StringToJson()); Response.End(); } else { converter.AddKey("msg", trackNum); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(converter.StringToJson()); Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { Boolean inputOk = false; Boolean dodanoPoprawnie = true; string status = ""; if(Request.QueryString["Id"] != null) { JsonConverter converter = new JsonConverter(); status = sledzPrzesylke(Request.QueryString["Id"]); /* JsonConverter converter = new JsonConverter(); //pobranie connection string z webconfig System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/PROJEKT"); System.Configuration.ConnectionStringSettings connString = rootWebConfig.ConnectionStrings.ConnectionStrings["KurierProBazaSystemu"]; SqlConnection con = null; try { con = new SqlConnection(connString.ConnectionString); SqlCommand cmd = new SqlCommand("SELECT Status FROM [Dostawy] WHERE Id = @ID", con); cmd.Parameters.Add("@ID", SqlDbType.BigInt).Value = Convert.ToInt64(Request.QueryString["Id"]); cmd.CommandType = CommandType.Text; con.Open(); status = Convert.ToString(cmd.ExecuteScalar()); con.Close(); } catch (Exception ex) { } */ inputOk = true; if (status != "") { converter.AddKey("Status", status); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(converter.StringToJson()); Response.End(); } else { if (inputOk) { converter.AddKey("msg", "Brak przesyłki o podanym numerze."); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(converter.StringToJson()); Response.End(); } } } }