private void FillGrid()
        {
            DataSet dsAccName = ProjectFunctionsUtils.GetDataSet("Select AccCode,AccName,AccCodeBusy from ActMst");
            DataSet ds        = ProjectFunctionsUtils.GetDataSetBusy("Select Code as AccCodeBusy,Name as AccNameBusy,'' as AccCode,'' as AccName from Master1 where MasterType='2' ");

            if (ds.Tables[0].Rows.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    foreach (DataRow drActMst in dsAccName.Tables[0].Rows)
                    {
                        if (dr["AccCodeBusy"].ToString() == drActMst["AccCodeBusy"].ToString())
                        {
                            dr["AccCode"] = drActMst["AccCode"].ToString();
                            dr["AccName"] = drActMst["AccName"].ToString();
                        }
                    }
                }
                AccountGrid.DataSource = dt;
                AccountGridView.BestFitColumns();
            }
            else
            {
                AccountGrid.DataSource = null;
                AccountGridView.BestFitColumns();
            }
        }
        private void BtnImport_Click(object sender, EventArgs e)
        {
            DataRow currentrow = AccountGridView.GetDataRow(AccountGridView.FocusedRowHandle);
            DataSet ds         = ProjectFunctionsUtils.GetDataSetBusy("Select * from MasterAddressInfo where MasterCode='" + currentrow["AccCodeBusy"].ToString() + "'");

            if (ds.Tables[0].Rows.Count > 0)
            {
                FrmAccountMstAddEdit frm = new FrmAccountMstAddEdit()
                {
                    S1 = "&Add", Text = "Account Addition"
                };
                frm.StartPosition = FormStartPosition.CenterScreen;


                // only name block
                DataSet dsNane = ProjectFunctionsUtils.GetDataSetBusy("Select Code ,Name  from MASTER1  Where Code='" + currentrow["AccCodeBusy"].ToString() + "'");
                frm.txtAccCodeBusy.Text = dsNane.Tables[0].Rows[0]["Code"].ToString();
                frm.txtAccNameBusy.Text = dsNane.Tables[0].Rows[0]["Name"].ToString();
                frm.txtAcName.Text      = dsNane.Tables[0].Rows[0]["Name"].ToString();
                frm.txtBillingName.Text = dsNane.Tables[0].Rows[0]["Name"].ToString();

                // only name block

                //address block & others
                frm.txtAddress1.Text = ds.Tables[0].Rows[0]["Address1"].ToString();
                frm.txtAddress2.Text = ds.Tables[0].Rows[0]["Address2"].ToString();
                frm.txtAddress3.Text = ds.Tables[0].Rows[0]["Address3"].ToString();
                frm.txtAddress4.Text = ds.Tables[0].Rows[0]["Address4"].ToString();
                frm.txtZipCode.Text  = ds.Tables[0].Rows[0]["PINCode"].ToString();
                DataSet dsCity = ProjectFunctions.GetDataSet("SELECT CITYMASTER.CTSYSID, CITYMASTER.CTNAME,STATEMASTER.STNAME,STATEMASTER.UNDERRG FROM CITYMASTER INNER JOIN STATEMASTER ON CITYMASTER.UNDERSTID = STATEMASTER.STSYSID Where CITYMASTER.CTNAME like'%" + ds.Tables[0].Rows[0]["Station"].ToString() + "%'");
                if (dsCity.Tables[0].Rows.Count > 0)
                {
                    frm.txtCityCode.Text = dsCity.Tables[0].Rows[0]["CTSYSID"].ToString();
                    frm.txtCityName.Text = dsCity.Tables[0].Rows[0]["CTNAME"].ToString();
                    frm.txtState.Text    = dsCity.Tables[0].Rows[0]["STNAME"].ToString();
                    frm.txtCountry.Text  = dsCity.Tables[0].Rows[0]["UNDERRG"].ToString();
                }

                frm.txtTel.Text        = ds.Tables[0].Rows[0]["TelNo"].ToString() + "," + ds.Tables[0].Rows[0]["Mobile"].ToString();
                frm.txtEmail.Text      = ds.Tables[0].Rows[0]["Email"].ToString();
                frm.txtTinNo.Text      = ds.Tables[0].Rows[0]["TINNo"].ToString();
                frm.txtCstPst.Text     = ds.Tables[0].Rows[0]["CST"].ToString();
                frm.txtPanNo.Text      = ds.Tables[0].Rows[0]["ITPAN"].ToString();
                frm.txtGSTNo.Text      = ds.Tables[0].Rows[0]["GSTNo"].ToString();
                frm.txtWhatsAppNo.Text = ds.Tables[0].Rows[0]["WhatsAppNo"].ToString();

                //address block

                frm.ShowDialog(Parent);
                FillGrid();
            }
        }
        private void BtnBestMatch_Click(object sender, EventArgs e)
        {
            DataSet ds = ProjectFunctionsUtils.GetDataSetBusy("Select Code as MasterCode1,Name as PrintName from MASTER1  Where Name like '%" + txtAcName.Text + "%'");

            if (ds.Tables[0].Rows.Count > 0)
            {
                HelpGrid.Text       = "txtAccCodeBusy";
                HelpGrid.DataSource = ds.Tables[0];
                HelpGrid.BringToFront();
                HelpGrid.Show();
                HelpGrid.Focus();
                HelpGridView.BestFitColumns();
            }
        }
        private void HelpGrid_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                DataRow row = HelpGridView.GetDataRow(HelpGridView.FocusedRowHandle);
                if (HelpGrid.Text == "txtAccCodeBusy")
                {
                    txtAccCodeBusy.Text = row["MasterCode1"].ToString();
                    txtAccNameBusy.Text = row["PRINTNAME"].ToString();
                    HelpGrid.Visible    = false;
                    txtAccCodeBusy.Focus();

                    if (chImportAll.Checked)
                    {
                        DataSet ds = ProjectFunctionsUtils.GetDataSetBusy("Select * from MasterAddressInfo where MasterCode='" + txtAccCodeBusy.Text + "'");
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            txtAcName.Text      = txtAccNameBusy.Text;
                            txtBillingName.Text = txtAccNameBusy.Text;
                            txtAddress1.Text    = ds.Tables[0].Rows[0]["Address1"].ToString();
                            txtAddress2.Text    = ds.Tables[0].Rows[0]["Address2"].ToString();
                            txtAddress3.Text    = ds.Tables[0].Rows[0]["Address3"].ToString();
                            txtAddress4.Text    = ds.Tables[0].Rows[0]["Address4"].ToString();
                            txtZipCode.Text     = ds.Tables[0].Rows[0]["PINCode"].ToString();


                            DataSet dsCity = ProjectFunctions.GetDataSet("SELECT CITYMASTER.CTSYSID, CITYMASTER.CTNAME,STATEMASTER.STNAME,STATEMASTER.UNDERRG FROM CITYMASTER INNER JOIN STATEMASTER ON CITYMASTER.UNDERSTID = STATEMASTER.STSYSID Where CITYMASTER.CTNAME like'%" + ds.Tables[0].Rows[0]["Station"].ToString() + "%'");
                            if (dsCity.Tables[0].Rows.Count > 0)
                            {
                                txtCityCode.Text = dsCity.Tables[0].Rows[0]["CTSYSID"].ToString();
                                txtCityName.Text = dsCity.Tables[0].Rows[0]["CTNAME"].ToString();
                                txtState.Text    = dsCity.Tables[0].Rows[0]["STNAME"].ToString();
                                txtCountry.Text  = dsCity.Tables[0].Rows[0]["UNDERRG"].ToString();
                            }



                            txtTel.Text        = ds.Tables[0].Rows[0]["TelNo"].ToString() + "," + ds.Tables[0].Rows[0]["Mobile"].ToString();
                            txtEmail.Text      = ds.Tables[0].Rows[0]["Email"].ToString();
                            txtTinNo.Text      = ds.Tables[0].Rows[0]["TINNo"].ToString();
                            txtCstPst.Text     = ds.Tables[0].Rows[0]["CST"].ToString();
                            txtPanNo.Text      = ds.Tables[0].Rows[0]["ITPAN"].ToString();
                            txtGSTNo.Text      = ds.Tables[0].Rows[0]["GSTNo"].ToString();
                            txtWhatsAppNo.Text = ds.Tables[0].Rows[0]["WhatsAppNo"].ToString();
                        }
                    }
                }
                if (HelpGrid.Text == "txtSLCode")
                {
                    txtSLCode.Text   = row["LgrCode"].ToString();
                    txtSLDesc.Text   = row["LgrDesc"].ToString();
                    HelpGrid.Visible = false;
                    txtBSCode.Focus();
                }
                if (HelpGrid.Text == "txtBSCode")
                {
                    txtBSCode.Text   = row["BSCode"].ToString();
                    txtBSDesc.Text   = row["BSDesc"].ToString();
                    HelpGrid.Visible = false;
                    txtBSCode.Focus();
                }
                if (HelpGrid.Text == "txtMainLedgerCode")
                {
                    txtMainLedgerCode.Text = row["GrpCode"].ToString();
                    txtMainLedgerDesc.Text = row["GrpDesc"].ToString();
                    txtSubLedgerCode.Text  = row["GrpSubCode"].ToString();
                    txtSubLedgerDesc.Text  = row["GrpSubDesc"].ToString();
                    HelpGrid.Visible       = false;
                    txtBSCode.Focus();
                }
                if (HelpGrid.Text == "txtEmpCode")
                {
                    txtEmpCode.Text  = row["EmpCode"].ToString();
                    txtEmpName.Text  = row["EmpName"].ToString();
                    HelpGrid.Visible = false;
                    txtChequeName.Focus();
                }
                if (HelpGrid.Text == "txtGSTStateCode")
                {
                    txtGSTStateCode.Text = row["GSTStateCode"].ToString();
                    txtGSTStateDesc.Text = row["GSTStateDesc"].ToString();
                    HelpGrid.Visible     = false;
                    txtChequeName.Focus();
                }
                if (HelpGrid.Text == "txtCityCode")
                {
                    txtCityCode.Text = row["CTSYSID"].ToString();
                    txtCityName.Text = row["CTNAME"].ToString();
                    txtState.Text    = row["STNAME"].ToString();
                    txtCountry.Text  = row["UNDERRG"].ToString();
                    HelpGrid.Visible = false;
                    txtContactPerson.Focus();
                }
                if (HelpGrid.Text == "txtAgentCode")
                {
                    txtAgentCode.Text = row["AgentCode"].ToString();
                    txtAgentName.Text = row["AgentName"].ToString();
                    HelpGrid.Visible  = false;
                    txtAgentCode.Focus();
                }
                if (HelpGrid.Text == "txtUnitCode")
                {
                    txtUnitCode.Text = row["UNITID"].ToString();
                    txtUnitName.Text = row["UNITNAME"].ToString();
                    HelpGrid.Visible = false;
                    txtUnitCode.Focus();
                }
                if (HelpGrid.Text == "txtDelCitycode")
                {
                    txtDelCitycode.Text = row["CTSYSID"].ToString();
                    txtDelCityName.Text = row["CTNAME"].ToString();
                    HelpGrid.Visible    = false;
                    txtDelGSTNo.Focus();
                }
            }
            catch (Exception ex)
            {
                ProjectFunctions.SpeakError(ex.Message);
            }
        }