private void dgvCustomers_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            CustomerAddress objCustomerAddress = dgvCustomers.CurrentRow.DataBoundItem as CustomerAddress;

            SelectedCustomerAddress = objCustomerAddress;
            this.Dispose();
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            CustomerAddress objCustomerAddress;

            if (dgvCustomers.SelectedRows.Count == 0)
                MessageBox.Show("No Customer selected!", "Job", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            else
            {
                objCustomerAddress = dgvCustomers.CurrentRow.DataBoundItem as CustomerAddress;
                SelectedCustomerAddress = objCustomerAddress;
                this.Dispose();
            }
        }
        public CustomerAddress(string strCustomerNumber)
        {
            CustomerAddress objTemp = Search(strCustomerNumber, 1).First();

            CustomerNumber = objTemp.CustomerNumber;
            Name           = objTemp.Name;
            AddressLine1   = objTemp.AddressLine1;
            AddressLine2   = objTemp.AddressLine2;
            AddressLine3   = objTemp.AddressLine3;
            AddressLine4   = objTemp.AddressLine4;
            City           = objTemp.City;
            State          = objTemp.State;
            ZipCode        = objTemp.ZipCode;
            Country        = objTemp.Country;
        }
        public static SortableSearchableBindingList <CustomerAddress> Search(string strCustomerNumber, int intMaxRecordCount = 100, string strSearchBy = "cust_num")//Retrieves a list of customers that match the customer number
        {
            SortableSearchableBindingList <CustomerAddress> objCustomerAddressList;
            SL8_WTF_DataBaseSettings objSL8_WTF_DataBaseSettings;
            DataTable       objDataTable = new DataTable();
            SqlDataAdapter  objDataAdapter;
            SqlCommand      objSQLCommand;
            CustomerAddress objCustomerAddress;
            string          strSQL;


            objSL8_WTF_DataBaseSettings = new SL8_WTF_DataBaseSettings();
            strSQL = QueryDefinitions.GetQuery("SelectTopNCustomerAddresses", new string[] { intMaxRecordCount.ToString(), strSearchBy, strCustomerNumber.Trim(), strSearchBy });
            objSL8_WTF_DataBaseSettings.SQLConnection.Open();
            objSQLCommand  = new SqlCommand(strSQL, objSL8_WTF_DataBaseSettings.SQLConnection);
            objDataAdapter = new SqlDataAdapter(objSQLCommand);
            objDataAdapter.Fill(objDataTable);

            objCustomerAddressList = new SortableSearchableBindingList <CustomerAddress>();

            if (objDataTable.Rows.Count > 0)
            {
                foreach (DataRow objRow in objDataTable.Rows)
                {
                    objCustomerAddress = new CustomerAddress();

                    objCustomerAddress.CustomerNumber = objRow["cust_num"].ToString();
                    objCustomerAddress.Name           = objRow["Name"].ToString();
                    objCustomerAddress.AddressLine1   = objRow["Addr##1"].ToString();
                    objCustomerAddress.AddressLine2   = objRow["Addr##2"].ToString();
                    objCustomerAddress.AddressLine3   = objRow["Addr##3"].ToString();
                    objCustomerAddress.AddressLine4   = objRow["Addr##4"].ToString();
                    objCustomerAddress.City           = objRow["City"].ToString();
                    objCustomerAddress.State          = objRow["State"].ToString();
                    objCustomerAddress.ZipCode        = objRow["ZIP"].ToString();
                    objCustomerAddress.Country        = objRow["country"].ToString();

                    objCustomerAddressList.Add(objCustomerAddress);
                }
            }
            return(objCustomerAddressList);
        }
        //Retrieves a list of addresses of the specified customer
        public static SortableSearchableBindingList<CustomerAddress> Find(string strCustomerNumber)
        {
            SortableSearchableBindingList<CustomerAddress> objCustomerAddressList;
            SL8_WTF_DataBaseSettings objSL8_WTF_DataBaseSettings;
            DataTable objDataTable = new DataTable();
            SqlDataAdapter objDataAdapter;
            SqlCommand objSQLCommand;
            CustomerAddress objCustomerAddress;
            string strSQL;

            objSL8_WTF_DataBaseSettings = new SL8_WTF_DataBaseSettings();
            strSQL = QueryDefinitions.GetQuery("SelectCustomerAddresses", new string[] { strCustomerNumber });
            objSL8_WTF_DataBaseSettings.SQLConnection.Open();
            objSQLCommand = new SqlCommand(strSQL, objSL8_WTF_DataBaseSettings.SQLConnection);
            objDataAdapter = new SqlDataAdapter(objSQLCommand);
            objDataAdapter.Fill(objDataTable);

            objCustomerAddressList = new SortableSearchableBindingList<CustomerAddress>();

            if (objDataTable.Rows.Count > 0)
            {
                foreach (DataRow objRow in objDataTable.Rows)
                {
                    objCustomerAddress = new CustomerAddress();

                    objCustomerAddress.CustomerNumber = objRow["cust_num"].ToString();
                    objCustomerAddress.Name = objRow["Name"].ToString();
                    objCustomerAddress.AddressLine1 = objRow["Addr##1"].ToString();
                    objCustomerAddress.AddressLine2 = objRow["Addr##2"].ToString();
                    objCustomerAddress.AddressLine3 = objRow["Addr##3"].ToString();
                    objCustomerAddress.AddressLine4 = objRow["Addr##4"].ToString();
                    objCustomerAddress.City = objRow["City"].ToString();
                    objCustomerAddress.State = objRow["State"].ToString();
                    objCustomerAddress.ZipCode = objRow["ZIP"].ToString();
                    objCustomerAddress.Country = objRow["country"].ToString();

                    objCustomerAddressList.Add(objCustomerAddress);
                }
            }
            return objCustomerAddressList;
        }
        private void LoadCustomerAddresses()
        {
            SL8_WTF_DataBaseSettings objSL8_WTF_DataBaseSettings;
            DataTable objDataTable = new DataTable();
            SqlDataAdapter objDataAdapter;
            SqlCommand objSQLCommand;
            CustomerAddress objCustomerAddress;
            string strSQL;

            objSL8_WTF_DataBaseSettings = new SL8_WTF_DataBaseSettings();
            strSQL = QueryDefinitions.GetQuery("SelectCustomerAddresses", new string[] { mintCustomerNumber.ToString() });
            objSL8_WTF_DataBaseSettings.SQLConnection.Open();
            objSQLCommand = new SqlCommand(strSQL, objSL8_WTF_DataBaseSettings.SQLConnection);
            objDataAdapter = new SqlDataAdapter(objSQLCommand);
            objDataAdapter.Fill(objDataTable);

            mobjCustomerAddressList = new BindingList<CustomerAddress>();

            foreach (DataRow objRow in objDataTable.Rows)
            {
                objCustomerAddress = new CustomerAddress();

                objCustomerAddress.Name = objRow["Name"].ToString();
                objCustomerAddress.AddressLine1 = objRow["Addr##1"].ToString();
                objCustomerAddress.AddressLine2 = objRow["Addr##2"].ToString();
                objCustomerAddress.AddressLine3 = objRow["Addr##3"].ToString();
                objCustomerAddress.AddressLine4 = objRow["Addr##4"].ToString();
                objCustomerAddress.City = objRow["City"].ToString();
                objCustomerAddress.State = objRow["State"].ToString();
                objCustomerAddress.ZipCode = objRow["ZIP"].ToString();
                objCustomerAddress.Country = objRow["Country"].ToString();

                mobjCustomerAddressList.Add(objCustomerAddress);
            }

            mintSelectedAddressIndex = -1;

            if (objDataTable.Rows.Count > 0)
            {
                SelectCustomerAddress(0);
                grpAddress.Enabled = (mobjSelectedLabel.AddressLineCount > 0);
            }
            else
            {
                MessageBox.Show("No addresses found for customer!", "No Addresses Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                lblAddrCt.Text = "";
                grpAddress.Enabled = false;
            }
        }
        private void txtNo_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    try
                    {
                        if (!string.IsNullOrEmpty(txtNo.Text))
                        {
                            switch (((ComboBoxItem)cmbAddressType.SelectedItem).Value)
                            {
                                case CUSTOMERVALUE:
                                    var objCustomerAddress = new CustomerAddress(txtNo.Text);
                                    mintCustomerOrVendorNumber = int.Parse(objCustomerAddress.CustomerNumber);
                                    LoadCustomerAddresses();
                                    break;
                                case VENDORVALUE:
                                    var objVendorAddress = new VendorAddress(txtNo.Text);
                                    mintCustomerOrVendorNumber = int.Parse(objVendorAddress.VendorNumber);
                                    LoadVendorAddresses();
                                    break;
                            }

                            txtNo.Text = mintCustomerOrVendorNumber.ToString();
                        }
                    }
                    catch
                    {
                        switch (((ComboBoxItem)cmbAddressType.SelectedItem).Value)
                        {
                            case CUSTOMERVALUE:
                                MessageBox.Show("Customer " + txtNo.Text + " Not Found", "No Customer Found", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                break;
                            case VENDORVALUE:
                                MessageBox.Show("Vendor " + txtNo.Text + " Not Found", "No Vendor Found", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                break;
                        }

                    }
                    break;
            }
        }
示例#8
0
        private void txtCustomer_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    try
                    {
                        if (!string.IsNullOrEmpty(txtCustomer.Text))
                        {
                            var objCustomerAddress = new CustomerAddress(txtCustomer.Text);// objCustomersForm.SelectedCustomerAddress.CustomerNumber;

                            mintCustomerNumber = int.Parse(objCustomerAddress.CustomerNumber);
                            txtCustomer.Text = mintCustomerNumber.ToString();
                            LoadCustomerAddresses();
                            lblCustomerError.Text = string.Empty;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Customer " + txtCustomer.Text + " Not Found", "No Customer Found", MessageBoxButtons.OK,
                            MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        lblCustomerError.Text = "X";
                    }
                    break;
            }
        }