//private void addd_Click(object sender, RoutedEventArgs e)
        //{
        //    clear();

        //    txtcompanycode.IsEnabled = true;
        //    txtcompanyname.IsEnabled = true;
        //    txtcontactpersonname.IsEnabled = true;
        //    txtcontactpersonnumber.IsEnabled = true;
        //    txtcategory.IsEnabled = true;
        //    txtplotno.IsEnabled = true;
        //    txtlandmark.IsEnabled = true;
        //    txtcity.IsEnabled = true;
        //    txtstate.IsEnabled = true;
        //    txtcountry.IsEnabled = true;
        //    txtpincode.IsEnabled = true;
        //    txtcontact.IsEnabled = true;
        //    txtemail.IsEnabled = true;
        //    txtdiscount.IsEnabled = true;
        //    txtremarks.IsEnabled = true;
        //    combo1.IsEnabled = true;

        //    savee.IsEnabled = true;
        //    mod.IsEnabled = false;
        //    addd.IsEnabled = false;
        //    searchh.IsEnabled = false;
        //    clearr.IsEnabled = true;
        //

        //    addd.Background = new SolidColorBrush(Colors.Orange);
        //    mod.Background = new SolidColorBrush(Color.FromRgb(53, 71, 102));
        //}

        private void txtcompanycode_LostFocus(object sender, RoutedEventArgs e)
        {
            companymaster cm = new companymaster();

            try
            {
                string a = "Update", b = Convert.ToString(savee.Content);
                if (b == a)
                {
                    cm.COMPANY_CODE = txtcompanycode.Text;
                    cm.UPDATE_BY    = login.u;
                    cm.UPDATE_DATE  = DateTime.Today;
                    cm.Retrive();
                    txtcompanyname.Text = cm.COMPANY_NAME;
                    if (cm.ALLOW_CREDIT == "1")
                    {
                        check.IsChecked     = true;
                        txtcreditlimit.Text = cm.CREDITLIMIT;
                        txtcreditdays.Text  = cm.CREDITDAYS;
                    }
                    else
                    {
                        check.IsChecked     = false;
                        txtcreditlimit.Text = "";
                        txtcreditdays.Text  = "";
                    }
                    if (cm.YES == "1")
                    {
                        yes.IsChecked         = true;
                        txtblacklistedby.Text = cm.BLACKLISTEDBY;
                        txtreason.Text        = cm.REASON;
                    }
                    else
                    {
                        no.IsChecked          = true;
                        txtblacklistedby.Text = "";
                        txtreason.Text        = "";
                    }

                    txtcontactpersonname.Text   = cm.CONTACT_PERSON_NAME;
                    txtcontactpersonnumber.Text = cm.CONTACT_PERSON_NUMBER;
                    txtcategory.Text            = cm.CATEGORY;
                    txtplotno.Text   = cm.PLOT_NO;
                    txtlandmark.Text = cm.LANDMARK;
                    txtcity.Text     = cm.CITY;
                    txtstate.Text    = cm.STATE;
                    txtcountry.Text  = cm.COUNTRY;
                    txtpincode.Text  = cm.PINCODE;
                    txtcontact.Text  = cm.CONTACT;
                    txtemail.Text    = cm.EMAIL;
                    txtdiscount.Text = cm.DISCOUNT;
                    txtremarks.Text  = cm.REMARKS;
                    combo1.Text      = cm.STATUS;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please check the company code.");
            }
        }
        private void mod_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (error != 0 || yes.IsChecked == true)
                {
                    if (yes.IsChecked == true)
                    {
                        txtblacklistedby.Text = "";
                    }
                }
                companymaster c = new companymaster();
                txtcompanycode.IsEnabled         = true;
                txtcompanyname.IsEnabled         = true;
                txtcontactpersonname.IsEnabled   = true;
                txtcontactpersonnumber.IsEnabled = true;
                txtcategory.IsEnabled            = true;
                txtplotno.IsEnabled   = true;
                txtlandmark.IsEnabled = true;
                txtcity.IsEnabled     = true;
                txtstate.IsEnabled    = true;
                txtcountry.IsEnabled  = true;
                txtpincode.IsEnabled  = true;
                txtcontact.IsEnabled  = true;
                txtemail.IsEnabled    = true;
                txtdiscount.IsEnabled = true;
                txtremarks.IsEnabled  = true;
                combo1.IsEnabled      = true;

                //addd.IsEnabled = false;
                mod.IsEnabled     = true;
                savee.IsEnabled   = true;
                searchh.IsEnabled = false;
                clearr.IsEnabled  = true;

                companymaster cm = new companymaster();
                //mod.Content = "Modify";
                string a = "Modify";
                string b = Convert.ToString(mod.Content);
                if (a == b)
                {
                    mod.Content = "Update";
                    cm.Retrive();
                    txtcompanycode.Text         = cm.COMPANY_CODE;
                    txtcompanyname.Text         = cm.COMPANY_NAME;
                    txtcontactpersonname.Text   = cm.CONTACT_PERSON_NAME;
                    txtcontactpersonnumber.Text = cm.CONTACT_PERSON_NUMBER;
                    txtcategory.Text            = cm.CATEGORY;
                    txtplotno.Text   = cm.PLOT_NO;
                    txtlandmark.Text = cm.LANDMARK;
                    txtcity.Text     = cm.CITY;
                    txtstate.Text    = cm.STATE;
                    txtcountry.Text  = cm.COUNTRY;
                    txtpincode.Text  = cm.PINCODE;
                    txtcontact.Text  = cm.CONTACT;
                    txtemail.Text    = cm.EMAIL;
                    if (check.IsChecked == true)
                    {
                        txtcreditlimit.Text = cm.CREDITLIMIT;
                        txtcreditdays.Text  = cm.CREDITDAYS;
                    }
                    else
                    {
                        txtcreditdays.IsEnabled  = false;
                        txtcreditlimit.IsEnabled = false;
                    }
                    //    cm.ALLOW_CREDIT = res.ToString();
                    txtdiscount.Text = cm.DISCOUNT;
                    if (yes.IsChecked == true)
                    {
                        txtblacklistedby.Text = cm.BLACKLISTEDBY;
                        txtreason.Text        = cm.REASON;
                    }
                    if (no.IsChecked == true)
                    {
                        txtblacklistedby.IsEnabled = false;
                        txtreason.IsEnabled        = false;
                    }
                    txtblacklistedby.Text = cm.BLACKLISTEDBY;
                    //cm.YES = resyes.ToString();
                    //cm.NO = resno.ToString();
                    txtremarks.Text = cm.REMARKS;
                    combo1.Text     = cm.STATUS;
                }
                else
                {
                    cm.Update();
                    //MessageBox.Show("Updated Successfully");
                    popup_update.IsOpen = true;
                    mod.Content         = "Modify";
                    clear();
                    this.NavigationService.Refresh();
                }
                insertpop.Content = "updatepopup";
                mod.Background    = new SolidColorBrush(Colors.Orange);
                //addd.Background = new SolidColorBrush(Color.FromRgb(53, 71, 102));
            }
            catch (Exception)
            {
            }
        }