เอาข้อมูลที่ได้จาก firebaseresponse รูปแบบคล้าย ๆ JSON เอามาใส่เป็น fill in datagrideview มีคำสั่งอย่างไร
Posted: Sat Dec 14, 2019 11:14 pm
Code: Select all
using System;
using System.Data;
using FireSharp.Config;
using FireSharp.Interfaces;
using FireSharp.Response;
using System.Windows.Forms;
namespace Cshrp_doups
{
public partial class Form1 : Form
{
IFirebaseConfig config = new FirebaseConfig
{
AuthSecret = "SrqpM36Rj5S6R4ATa4tzYdTPN0EEcgR",
BasePath = "https://doups.firebaseio.com/"
};
IFirebaseClient client;
public Form1()
{
InitializeComponent();
}
private async void btmsearch_Click(object sender, EventArgs e)
{
//ค้นหาข้อมูลทำตรงนี
FirebaseResponse response = await client.GetAsync("customer/" + txtclientsearchkey.Text);
Customer cust = response.ResultAs<Customer>();
//debug.print command in vb = System.Diagnostics.Debug.WriteLine("Hello world");
// or System.Console.WriteLine("Hello world");
if (cust != null)
{
Console.WriteLine(cust.custid.ToString());
dataGridView1.Rows.Clear();
dataGridView1.Rows.Add(cust.custid, cust.customername, cust.customeraccount, cust.custpreflang);
}
}
private void button3_Click(object sender, EventArgs e)
{
//Add shipment data put <code> here to open transaction window
}
private void Form1_Load(object sender, EventArgs e)
{
client = new FireSharp.FirebaseClient(config);
if (client != null)
{
//MessageBox.Show("connected");
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int rowIndex = e.RowIndex;
DataGridViewRow row = dataGridView1.Rows[rowIndex];
//txtclientsearchkey.Text = dataGridView1.Rows[1].Cells[1].Value.ToString();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Console.WriteLine(this.comboBox1.Text);
}
private void btmaddnew_Click(object sender, EventArgs e)
{
Form newcust = new AddCustomer();
newcust.Show();
}
private async void button1_Click(object sender, EventArgs e)
{
FirebaseResponse respallcust = await client.GetAsync("customer/");
// ตรงนี้จะได้ข้อมูลออกมาเป็นชุดคล้าย json
/*
**JSON ที่ได้หน้าตาแบบนี้**
{
"1" : {
"custid" : "1",
"customeraccount" : "FEE45GH",
"customername" : "Bay bank",
"custpreflang" : "EN"
},
"2" : {
"custid" : "2",
"customeraccount" : "FT4GGH",
"customername" : "BBL ",
"custpreflang" : "EN"
},
"77" : {
"custid" : "77",
"customeraccount" : "MR4GGS",
"customername" : "Max77",
"custpreflang" : "EN"
},
"123456789" : {
"custid" : "123456789",
"customeraccount" : "FE3CDE",
"customername" : "Kitjar",
"custpreflang" : "EN"
},
"234569876" : {
"custid" : "234569876",
"customeraccount" : "REF2GGY",
"customername" : "Yanakorn",
"custpreflang" : "EN"
},
"345667JK" : {
"custid" : "345667JK",
"customeraccount" : "N/A",
"customername" : "Somchai",
"custpreflang" : "EN"
},
"8EE9433" : {
"custid" : "8EE9433",
"customeraccount" : "8EE9433",
"customername" : "nothing 8EE9433",
"custpreflang" : "EN"
}
}
*/
Data allcust = respallcust.ResultAs<Data>();
try
{
dataGridView1.Rows.Clear();
//ที่จะถามคือตรงนี้ เอาข้อมูลที่ได้จาก firebaseresponse รูปแบบคล้าย ๆ JSON เอามาใส่เป็น fill in datagrideview มีคำสั่งอย่างไร
dataGridView1.Rows.Add(allcust.custid, allcust.customername, allcust.customeraccount, allcust.custpreflang);
}
catch
{
}
}
}
}
เอาข้อมูลที่ได้จาก firebaseresponse รูปแบบคล้าย ๆ JSON เอามาใส่เป็น fill in datagrideview มีคำสั่งอย่างไร