private void InitValue() { Product p = (Product)Item; prPid.Text = p.Pid; prItemType.Text = ItemType[Page]; prBrand.Text = p.Brand; prPrice.Text = p.Price.ToString("F"); switch (Page) { case 0: Len pl = (Len)Item; prTypeLen.Text = pl.Type; prSightLen.Text = pl.Sight; prSPHLen.Text = pl.Sph.ToString(); prCYLLen.Text = pl.Cyl.ToString(); PanelFrame.Visible = false; PanelContact.Visible = false; break; case 1: Frame pf = (Frame)Item; prClass.Text = pf.Class; prColor.Text = pf.Color; PanelLen.Visible = false; PanelContact.Visible = false; PanelValue.Location = new Point(0, PanelFrame.Location.Y + PanelFrame.Height); break; case 2: Contact pc = (Contact)Item; prDuration.Text = pc.Duration; prSightContact.Text = pc.Sight; prSPHContact.Text = pc.Sph.ToString(); PanelLen.Visible = false; PanelFrame.Visible = false; break; } }
private void loadFrame() { Page = 1; string sql = ""; string whr = whereFrame(); sql += "SELECT * "; sql += "FROM product, frame "; sql += "WHERE product.pid = frame.pid"; sql += whr; // MessageBox.Show(sql); try { int count = 0; con.Open(); dt = new DataTable(); cmd = new MySqlCommand(sql, con); adapter = new MySqlDataAdapter(cmd); adapter.Fill(dt); dgvProduct.Rows.Clear(); foreach (DataRow row in dt.Rows) { Frame item = new Frame(); listItem[count] = item; item.Pid = row[0].ToString(); item.Qty = (int)row[1]; item.Price = (float)row[2]; item.Brand = row[4].ToString(); item.Class = row[5].ToString(); item.Color = row[6].ToString(); dgvProduct.Rows.Add(item.Pid, item.getName(), item.Qty, item.Price, txtPO, txtEdit, txtDelete); count++; } con.Close(); if (count > 0) { errorBox.Text = count.ToString() + " matches found."; } else { errorBox.Text = "not found."; } } catch (Exception ex) { errorBox.Text = ex.ToString(); con.Close(); } }
private bool loadProduct() { bool found = false; string sql = ""; string pid = prPid.Text; if (prPid.Text == string.Empty) { return(found); } if (pid[0] == '1') { sql += "SELECT * "; sql += "FROM product, len "; sql += "WHERE product.pid = len.pid "; } else if (pid[0] == '2') { sql += "SELECT * "; sql += "FROM product, frame "; sql += "WHERE product.pid = frame.pid "; } else { sql += "SELECT * "; sql += "FROM product, contact_len "; sql += "WHERE product.pid = contact_len.pid "; } sql += "AND product.pid = \'" + pid + "\'"; cmd = new MySqlCommand(sql, con); //MessageBox.Show(sql); try { con.Open(); dt = new DataTable(); cmd = new MySqlCommand(sql, con); adapter = new MySqlDataAdapter(cmd); adapter.Fill(dt); foreach (DataRow row in dt.Rows) { if (pid[0] == '1') { Len item = new Len(); item.Pid = row[0].ToString(); item.Qty = (int)row[1]; item.Price = (float)row[2]; item.Brand = row[4].ToString(); item.Type = row[5].ToString(); item.Sight = row[6].ToString(); item.Sph = (float)row[7]; item.Cyl = (float)row[8]; Item = item; Name = item.getName(); } else if (pid[0] == '2') { Frame item = new Frame(); item.Pid = row[0].ToString(); item.Qty = (int)row[1]; item.Price = (float)row[2]; item.Brand = row[4].ToString(); item.Class = row[5].ToString(); item.Color = row[6].ToString(); Item = item; Name = item.getName(); } else { Contact item = new Contact(); item.Pid = row[0].ToString(); item.Qty = (int)row[1]; item.Price = (float)row[2]; item.Brand = row[4].ToString(); item.Duration = row[5].ToString(); item.Sight = row[6].ToString(); item.Sph = (float)row[7]; Item = item; Name = item.getName(); } txtName.Text = Name; found = true; } con.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); con.Close(); } return(found); }