private void FindExisitingRequests(string ReqNo)
        {
            try{
                if (T_purchaseRequisitionDL.ExistingT_purchaseRequisition(ReqNo.Trim()))
                {
                    formMode = 3;
                    //clear datagrid
                    dtx.Clear();
                    dataGridView1.Refresh();

                    //clear error fields
                    errorProvider1.Clear();

                    t_purchaseRequisition cat = new t_purchaseRequisition();
                    cat.no = ReqNo.Trim();
                    T_purchaseRequisitionDL dl = new T_purchaseRequisitionDL();
                    cat = dl.Selectt_purchaseRequisition(cat);

                    //set the process message and mode to edit mode
                    if (cat.isProcessed == false)
                    {
                        lbl_processes.Visible = false;
                        performButtons(xEnums.PerformanceType.Edit);
                    }
                    else
                    {
                        lbl_processes.Visible = true;
                    }

                    //load and disable the data fields

                    txt_location.Text = cat.locationId.Trim();
                    txt_Suplier.Text  = cat.supplierId.Trim();
                    txt_remark.Text   = cat.remarks;

                    txt_Suplier.Enabled   = false;
                    txt_location.Enabled  = false;
                    txt_remark.Enabled    = false;
                    dataGridView1.Enabled = false;

                    t_purchaseReq_detail req = new t_purchaseReq_detail();
                    req.purchaseReqNo = ReqNo.Trim();
                    T_purchaseReq_detailDL      tdl      = new T_purchaseReq_detailDL();
                    List <t_purchaseReq_detail> requests = new List <t_purchaseReq_detail>();
                    requests = tdl.Selectt_purchaseReq_detailMulti(req);

                    foreach (t_purchaseReq_detail det in requests)
                    {
                        commonFunctions.AddRow(dtx, det.productId, det.description, det.costPrice.ToString(), M_ProductDL.GetSellingPrice(det.productId).ToString(), det.quantity.ToString(), det.amount.ToString());
                    }

                    txt_net.Text   = commonFunctions.GetGrossAmount(dataGridView1).ToString();
                    txt_gross.Text = commonFunctions.GetGrossAmount(dataGridView1).ToString();
                    txt_pices.Text = commonFunctions.GetNoofPices(dataGridView1).ToString();
                    txt_items.Text = commonFunctions.GetNoofItems(dataGridView1).ToString();

                    //txt_locaname.Text = cat.Locaname;
                }
                else
                {
                    if (formMode != 1)
                    {
                        errorProvider1.SetError(txt_reqno, "Request Number you have entered does not exists in the system.");
                    }
                }
            }
            catch (Exception ex)
            {
                LogFile.WriteErrorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, this.Name, ex.Message.ToString(), "Exception");
                commonFunctions.SetMDIStatusMessage("Genaral Error", 1);
            }
        }
        private void txt_code_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F2)
            {
                if (ActiveControl.Name.Trim() == txt_code.Name.Trim())
                {
                    int      length         = Convert.ToInt32(ConfigurationManager.AppSettings["ProductFieldLength"]);
                    string[] strSearchField = new string[length];

                    string strSQL = ConfigurationManager.AppSettings["ProductSQL"].ToString();

                    for (int i = 0; i < length; i++)
                    {
                        string m;
                        m = i.ToString();
                        strSearchField[i] = ConfigurationManager.AppSettings["ProductField" + m + ""].ToString();
                    }

                    frmU_Search find = new frmU_Search(strSQL, strSearchField, this);
                    find.ShowDialog(this);
                }

                //FindExisitingSupplier();
                errorProvider1.Clear();
            }

            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    //txt_code.Text = commonFunctions.GetProcutCode(txt_code.Text.Trim());
                    if (T_StockDL.ExistingT_Stock_Product(txt_code.Text, commonFunctions.GlobalCompany, commonFunctions.GlobalLocation))
                    {
                        if (!commonFunctions.IsExistINV(dataGridView1, txt_code.Text))
                        {
                            M_Products stk = new M_Products();
                            stk.Locacode = commonFunctions.GlobalLocation;
                            stk.Compcode = commonFunctions.GlobalCompany;
                            stk.IDX      = txt_code.Text;
                            stk          = new M_ProductDL().Selectm_Product(stk);

                            txt_cost.Text    = stk.CostPrice.ToString();
                            txt_selling.Text = stk.SellingPrice.ToString();
                            lbl_name.Text    = stk.Namex;

                            txt_qty.Text = "0";
                            txt_qty.Focus();

                            errorProvider1.Clear();
                            already = false;
                        }
                        else
                        {
                            already = true;
                            //errorProvider1.SetError(txt_code, "Already exists");
                            M_Products stk = new M_Products();
                            stk.Locacode = commonFunctions.GlobalLocation;
                            stk.Compcode = commonFunctions.GlobalCompany;
                            stk.IDX      = txt_code.Text;
                            stk          = new M_ProductDL().Selectm_Product(stk);

                            txt_cost.Text    = stk.CostPrice.ToString();
                            txt_selling.Text = stk.SellingPrice.ToString();
                            lbl_name.Text    = stk.Namex;

                            DataGridViewRow drowx = new DataGridViewRow();
                            drowx = commonFunctions.GetRow(dataGridView1, txt_code.Text.Trim());

                            txt_qty.Text = drowx.Cells["Quntity"].Value.ToString();

                            txt_qty.Focus();
                        }
                    }
                    else
                    {
                        errorProvider1.SetError(txt_code, "Product you have entered not exist in the product master file");
                        commonFunctions.SetMDIStatusMessage("Product you have entered not exist in the product master file", 1);
                    }
                }
                catch (Exception ex)
                {
                    LogFile.WriteErrorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, this.Name, ex.Message.ToString(), "Exception");
                    commonFunctions.SetMDIStatusMessage("Genaral Error", 2);
                }
            }
        }