int ItemFound(double itemN) { SqlCommand comm; SqlDataReader Itemread; string getbar = "select ItemBarCode from ItemDetails where ItemBarcode='" + itemN + "'"; try { if (con.State == ConnectionState.Closed) { con.Open(); } comm = new SqlCommand(getbar, con); Itemread = comm.ExecuteReader(); while (Itemread.Read()) { Itemread.Close(); return(1); } Itemread.Close(); con.Close(); } catch { con.Close(); } return(-1); }
private void ItemIdQTB_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { Int64 data; try { data = Int64.Parse(ItemIdQTB.Text); } catch { if (ItemIdQTB.Text != "") { MessageBox.Show("الرجاء ادخال ارقام فقط"); ItemIdQTB.Text = ""; } } int catid = 0, itemid = 0, sellPrice = 0; string ItemId; string Quan; SqlCommand comm; SqlDataReader Itemread; /*try * { * con.Open(); * if(count==0) * { * ItemId = "Select Items.ItemId,CatId,ItemSellPriceGo,ItemSellPriceKa from Items join ItemDetails on (Items.ItemId=ItemDetails.ItemId) and ( Items.ItemId= " + ItemIdQTB.Text.Trim() + " or ItemBarcode= " + ItemIdQTB.Text.Trim() + ")"; * comm = new SqlCommand(ItemId, con); * Itemread = comm.ExecuteReader(); * while(Itemread.Read()) * { * * CatCB.SelectedValue = Itemread["CatId"].ToString(); * //CatCB_SelectedIndexChanged(sender, e); * itemsBindingSource.Filter = "CatId='" + CatCB.SelectedValue.ToString() + "' and ItemId='" + Itemread["ItemId"].ToString() + "'"; * itemsTableAdapter.Fill(itemsTADS.Items); * ItemIdQTB.Text = Itemread["ItemId"].ToString(); * //ItemCB.SelectedValue = Itemread["ItemId"].ToString(); * ItemCB_SelectedIndexChanged(sender, e); * * } * Itemread.Close(); * //count = 0; * con.Close(); * } * catch { con.Close(); }*/ try { Int64 s_q_code = 0; s_q_code = Int64.Parse(ItemIdQTB.Text.Trim()); con.Open(); if (count == 0 && ItemIdQTB.Text != "") { ItemId = "Select Items.ItemId,CatId,ItemSellPriceGo,ItemSellPriceKa from Items join ItemDetails on Items.ItemId=ItemDetails.ItemId and (Items.ItemId= " + s_q_code + " or ItemBarcode= " + s_q_code + ")"; comm = new SqlCommand(ItemId, con); Itemread = comm.ExecuteReader(); Itemread.Read(); if (Itemread.HasRows) { itemid = Int32.Parse(Itemread["ItemId"].ToString()); catid = Int32.Parse(Itemread["CatId"].ToString()); FillTextBoxes(itemid); expire_item_grid.DataSource = meth.select_item_expire_dates(ItemIdQTB.Text.Trim()); expire_item_grid.Columns[0].Visible = false; expire_item_grid.Columns[2].Visible = false; count++; Itemread.Close(); ItemIdQTB.Text = itemid.ToString(); CatCB.SelectedValue = catid; ItemCB.SelectedValue = itemid; FillTextBoxes(itemid); } //SellPriceTB.Text = sellPrice.ToString(); //QuanTB.Focus(); } else { CatCB.SelectedValue = catid; ItemCB.SelectedValue = itemid; FillTextBoxes(itemid); // SellPriceTB.Text = sellPrice.ToString(); //QuanTB.Focus(); } count = 0; con.Close(); } catch (Exception dd) { MessageBox.Show(dd.Message); con.Close(); } } }