I have created dinamic button from sql items table...I need to create insert into function for them...I create POS system for sale...
- private void Form1_Load(object sender, EventArgs e)
- {
- // TODO: This line of code loads data into the 'bssDataSet.roba_usluge' table. You can move, or remove it, as needed.
- this.roba_uslugeTableAdapter.Fill(this.bssDataSet.roba_usluge);
- SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=bss;Integrated Security=True");
- //SqlCommand cmd = new SqlCommand("SELECT Concat(ime),data FROM roba_usluge", con);
- // SqlCommand cmd = new SqlCommand("SELECT (redni_broj),data FROM roba_usluge", con);
- SqlCommand cmd = new SqlCommand("SELECT (ime), data FROM roba_usluge", con);
- // SqlCommand cmd = new SqlCommand("SELECT Concat(ime, cijena_sa_porezom),data FROM roba_usluge", con);
- // Getting all the data to ItemTable
- var da = new SqlDataAdapter(cmd);
- var ItemTable = new DataTable();
- da.Fill(ItemTable);
- con.Open();
- Int32 count = ItemTable.Rows.Count;
- con.Close();
- int top = 50;
- int left = 50;
- for (int i = 1; i <= count; i++)
- // for (int i = 0; i < count; i++)
- {
- Button button = new Button();
- button.Size = new Size(128,128);
- button.BackColor = Color.Transparent;
- //button.FlatStyle = FlatStyle.Flat;
- button.FlatAppearance.BorderSize = 0;
- button.Font = new System.Drawing.Font("Trebuchet MS", 10);
- button.TextAlign = ContentAlignment.TopCenter;
- button.BackgroundImageLayout = ImageLayout.Zoom;
- button.Left = left;
- button.Top = top;
- button.Text = ItemTable.Rows[i - 1][0].ToString();
- //if (ItemTable.Rows[i - 1][1] != null && ItemTable.Rows[i - 1][1] != "")
- if (ItemTable.Rows[i - 1][1] != null)
- {
- try
- {
- byte[] _byte = (byte[])ItemTable.Rows[i - 1][1];
- MemoryStream ms = new MemoryStream(_byte);
- button.BackgroundImage = System.Drawing.Image.FromStream(ms);//bilo image
- }
- catch { }
- }
- // button.Text = ItemTable.Rows[i][0].ToString();
- this.Controls.Add(button);
- if (i % 5 == 0)
- {
- left = 50;
- top += button.Height + 2;
- }
- else
- {
- left += button.Width + 2;
- }
- // top += button.Height + 2;
- }
- }
Rafnas T PPosted Apr 7, 2018, 9:07 AM
int sno = dataGridView1.Rows.Count + 1;
string nazivartikla = itemAndPrice.Split('-')[0].ToString();
double cijena = Convert.ToDouble(itemAndPrice.Split('-')[1].ToString());
string exists="":
foreach (DataGridViewRow g1 in datagrid1.Rows)
{
if(g1.Cells[1].Value.ToString().Trim()== itemAndPrice.Split('-')[0].ToString().Trim())
{
exists="y";
g1.Cells[2].Value = Convert.ToInt32(g1.Cells[2].Value) + 1;
g1.Cells[4].Value = Convert.ToInt32(g1.Cells[2].Value) * Convert.ToInt32(g1.Cells[3].Value);
}
}
if(exists!="y")
{
dataGridView1.Rows.Add(sno, nazivartikla, 1, cijena, cijena);
}
Goran BibicPosted Apr 7, 2018, 9:06 AM
Rafnas T PPosted Apr 7, 2018, 8:36 AM
Goran BibicPosted Apr 7, 2018, 8:29 AM
Rafnas T PPosted Apr 7, 2018, 8:25 AM
yellow colored one you can change based on your columns in grid
Goran BibicPosted Apr 7, 2018, 8:20 AM
Goran BibicPosted Apr 7, 2018, 8:18 AM
Goran BibicPosted Apr 7, 2018, 8:13 AM
Rafnas T PPosted Apr 7, 2018, 8:06 AM
Rafnas T PPosted Apr 7, 2018, 8:05 AM
Goran BibicPosted Apr 7, 2018, 8:02 AM
Rafnas T PPosted Apr 7, 2018, 7:56 AM
{
Button btn = (Button)sender;
var itemAndPrice = btn.Text;
int id = datagrid1.Rows.Count + 1;
string Item = itemAndPrice.Split('-')[0].ToString();
double price = Convert.ToDouble(itemAndPrice.Split('-')[1].ToString());
datagrid1.Rows.Add(id, Item, 1, price, price);//id,iem,quantity,price,total your grid columns
}
Goran BibicPosted Apr 7, 2018, 7:55 AM
Goran BibicPosted Apr 7, 2018, 7:53 AM
Rafnas T P
Rafnas T PPosted Apr 7, 2018, 7:26 AM
Rafnas T PPosted Apr 7, 2018, 2:16 AM
Goran BibicPosted Apr 6, 2018, 5:34 PM
Amit GuptaPosted Apr 6, 2018, 5:32 PM
Goran BibicPosted Apr 6, 2018, 5:24 PM
Amit GuptaPosted Apr 6, 2018, 5:14 PM
Goran BibicPosted Apr 6, 2018, 5:11 PM
Amit GuptaPosted Apr 6, 2018, 5:06 PM
Goran BibicPosted Apr 6, 2018, 5:04 PM
Goran BibicPosted Apr 6, 2018, 5:03 PM
Goran BibicPosted Apr 6, 2018, 4:54 PM
Goran BibicPosted Apr 6, 2018, 4:49 PM
Amit GuptaPosted Apr 6, 2018, 4:48 PM
Goran BibicPosted Apr 6, 2018, 4:43 PM
Amit GuptaPosted Apr 6, 2018, 4:36 PM
Goran BibicPosted Apr 6, 2018, 4:21 PM
Goran BibicPosted Apr 6, 2018, 4:14 PM
Amit GuptaPosted Apr 6, 2018, 4:09 PM
Goran BibicPosted Apr 6, 2018, 4:01 PM
Amit GuptaPosted Apr 6, 2018, 3:54 PM
Goran BibicPosted Apr 6, 2018, 3:47 PM
Amit GuptaPosted Apr 6, 2018, 3:41 PM
Amit GuptaPosted Apr 6, 2018, 3:24 PM