public MSL_Agreement_Search()
 {
     InitializeComponent();
     AgmResult.Hide();
     AgmWait.Hide();
     SetConnectionString();
 }
        private void AgmSearch_Click(object sender, EventArgs e)
        {
            CountryName      = Country.Text;
            ProgramName      = Program.Text;
            CustomerTypeCode = CustomerType.Text;
            AgmType          = AgreementType.Text;
            Agmcontract      = ContractType.Text;
            Status           = AgmStatus.Text;


            if (CountryName == "")
            {
                MessageBox.Show("Please Select Country");
            }

            else if (ProgramName == "")
            {
                MessageBox.Show("Please Select Program Name");
            }

            else if (CustomerTypeCode == "")
            {
                MessageBox.Show("Please Select Customer Type");
            }

            else if (AgmType == "")
            {
                MessageBox.Show("Please Select Agreement Type");
            }

            else if (Agmcontract == "")
            {
                MessageBox.Show("Please Select Agreement Contract");
            }

            else if (Status == "")
            {
                MessageBox.Show("Please Select Agreement Status");
            }



            else
            {
                AgmWait.Show();
                AgmSearch.Enabled = false;
                using (SqlConnection conn = new SqlConnection(ConnectionString))
                {
                    string countryCode  = GetCountryCode(CountryName);
                    string programCode  = GetProgramCode(ProgramName);
                    string customerType = GetCustomerTypeCode(CustomerTypeCode);
                    string AType        = GetAgmType(AgmType);
                    string AContract    = GetAgmContract(Agmcontract);
                    string AStatus      = GetAgmStatus(Status);

                    AgmResult.Show();

                    SqlCommand cmd = new SqlCommand(String.Format(@"select  A.Agreementnumber,A.Programcode,AP.CustomerTypeCode,A.StartEffectiveDate, A.ContractTypeCode,A.LicenseAgreementTypeCode, * from Agreement A
                                                            join AgreementParticipant AP on A.AgreementID = AP.AgreementID
                                                            where SalesLocationCode = '{0}'
                                                            and  Programcode = '{1}'
                                                            and AgreementTypeCode = '{2}'
                                                            and CustomerTypeCode ='{3}'
                                                            and AgreementStatusCode = '{4}'
                                                            and ContractTypeCode='{5}'
                                                            order by A.StartEffectiveDate desc", countryCode, programCode, AType, customerType, AStatus, AContract), conn);


                    conn.Open();

                    DataTable dt = new DataTable();

                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                    AgmWait.Hide();
                    AgmResult.DataSource = dt;
                    AgmResult.Show();
                    AgmSearch.Enabled = true;
                }
            }
        }