예제 #1
0
        private void LoadCustomers()
        {
            string query = @"SELECT  c.CustomerId AS [Customer ID], c.Name, c.Phone as [Contact No.], 
                             CONVERT(nVARCHAR(19), c.Date, 106) as [Inst. Date], b.BrandName as [Brand Name], 
                             p.ProductName as [Product Name], s.Name AS [Salesman]
                             FROM Customer AS c LEFT OUTER JOIN
                             Brand AS b ON c.BrandId = b.BrandId LEFT OUTER JOIN
                             Product AS p ON c.ProductId = p.ProductId LEFT OUTER JOIN
                             Salesman AS s ON c.SalesmanId = s.SalesmanId";

            switch (cboSearch.Text)
            {
            case "All":
                break;

            case "Customer ID":
                long CustId;
                try
                {
                    CustId = Int64.Parse(txtSearch.Text);
                    query  = query + " WHERE CustomerId = " + CustId.ToString();
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid Customer ID, please enter valid Customer ID", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                break;

            case "Contact No.":
                query = query + " WHERE c.Phone like '%" + txtSearch.Text + "%'";
                break;

            case "Customer Name":
                query = query + " WHERE c.Name like '%" + txtSearch.Text + "%'";
                break;

            case "Salesman Name":
                query = query + " WHERE s.Name like '%" + txtSearch.Text + "%'";
                break;

            case "Brand":
                query = query + " WHERE b.BrandName like '%" + txtSearch.Text + "%'";
                break;

            case "Product":
                query = query + " WHERE p.ProductName like '%" + txtSearch.Text + "%'";
                break;
            }

            //query = "select * from customer";
            dtCustomers = dbWrapper.SelectData(query);

            gridCustomer.DataSource = dtCustomers;
            lblCount.Text           = "Count: " + dtCustomers.Rows.Count.ToString();
            txtCustomerName.Focus();

            btnDelete.Enabled = false;
            gridCustomer.Columns.Cast <DataGridViewColumn>().ToList().ForEach(f => f.SortMode = DataGridViewColumnSortMode.NotSortable);
        }
        private void btGetCustId_Click(object sender, EventArgs e)
        {
            int custId = 0;

            int.TryParse(txtCustId.Text, out custId);

            CustomerForm customerList = new CustomerForm();

            customerList.isOpenByCustomerSelectUserControl = true;
            customerList.CustId = custId;
            customerList.ShowDialog();
            if (customerList.CustId != 0)
            {
                CustId         = customerList.CustId;
                txtCustId.Text = CustId.ToString();
            }
        }