示例#1
0
        private void btnMCUpdate_Click(object sender, RoutedEventArgs e)
        {
            int index = lvModifyCustomerList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            CustSuppliers c = (CustSuppliers)lvModifyCustomerList.Items[index];

            try
            {
                c.CompanyName  = tbMCCompanyName.Text;
                c.ContactName  = tbMCContactName.Text;
                c.ContactTitle = tbMCContactTitle.Text;
                c.Address      = tbMCAddress.Text;
                c.Phone        = tbMCPhone.Text;

                db.UpdateCustSupplier(c);
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.StackTrace);
                MessageBox.Show("Database query error " + ex.Message);
            }
            Reset();
        }
示例#2
0
        private void lvModifyCustomerList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = lvModifyCustomerList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            CustSuppliers c = (CustSuppliers)lvModifyCustomerList.Items[index];

            lblMCId.Content       = c.CustSupplierId + "";
            tbMCCompanyName.Text  = c.CompanyName;
            tbMCContactName.Text  = c.ContactName;
            tbMCContactTitle.Text = c.ContactTitle;
            tbMCAddress.Text      = c.Address;
            tbMCPhone.Text        = c.Phone;
        }
        public void UpdateCustSupplier(CustSuppliers c)
        {
            string sql = "UPDATE CustSuppliers SET CompanyName = @CompanyName, ContactName = @ContactName, ContactTitle = @ContactTitle," +
                         " Address = @Address, Phone = @Phone, IsCustomer = @IsCustomer, IsSupplier = @IsSupplier WHERE CustSupplierId = @CustSupplierId";
            SqlCommand cmd = new SqlCommand(sql, conn);

            cmd.Parameters.Add("@CustSupplierId", SqlDbType.Int).Value    = c.CustSupplierId;
            cmd.Parameters.Add("@CompanyName", SqlDbType.NVarChar).Value  = c.CompanyName;
            cmd.Parameters.Add("@ContactName", SqlDbType.NVarChar).Value  = c.ContactName;
            cmd.Parameters.Add("@ContactTitle", SqlDbType.NVarChar).Value = c.ContactTitle;
            cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value      = c.Address;
            cmd.Parameters.Add("@Phone", SqlDbType.NVarChar).Value        = c.Phone;
            cmd.Parameters.Add("@IsCustomer", SqlDbType.Bit).Value        = c.IsCustomer;
            cmd.Parameters.Add("@IsSupplier", SqlDbType.Bit).Value        = c.IsSupplier;

            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        public void AddCustSupplier(CustSuppliers c)
        {
            List <CustSuppliers> result = new List <CustSuppliers>();
            string sql = "INSERT INTO CustSuppliers (CompanyName, ContactName, ContactTitle, Address, Phone, IsCustomer, IsSupplier) "
                         + " VALUES (@CompanyName, @ContactName, @ContactTitle, @Address, @Phone, @IsCustomer, @IsSupplier)";
            SqlCommand cmd = new SqlCommand(sql, conn);

            cmd.Parameters.Add("@CompanyName", SqlDbType.NVarChar).Value  = c.CompanyName;
            cmd.Parameters.Add("@ContactName", SqlDbType.NVarChar).Value  = c.ContactName;
            cmd.Parameters.Add("@ContactTitle", SqlDbType.NVarChar).Value = c.ContactTitle;
            cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value      = c.Address;
            cmd.Parameters.Add("@Phone", SqlDbType.NVarChar).Value        = c.Phone;
            cmd.Parameters.Add("@IsCustomer", SqlDbType.Bit).Value        = c.IsCustomer;
            cmd.Parameters.Add("@IsSupplier", SqlDbType.Bit).Value        = c.IsSupplier;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            result.Add(c);
        }
示例#5
0
        private void btnMCRemove_Click(object sender, RoutedEventArgs e)
        {
            int index = lvModifyCustomerList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            CustSuppliers c = (CustSuppliers)lvModifyCustomerList.Items[index];

            try
            {
                db.DeleteCustSupplierById(c.CustSupplierId);
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.StackTrace);
                MessageBox.Show("Database query error " + ex.Message);
            }
            Reset();
        }
示例#6
0
        private void btnMCAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string  companyName  = tbMCCompanyName.Text;
                string  contactName  = tbMCContactName.Text;
                string  contactTitle = tbMCContactTitle.Text;
                string  address      = tbMCAddress.Text;
                string  phone        = tbMCPhone.Text;
                Boolean isCustomer   = true;
                Boolean isSupplier   = false;

                CustSuppliers c = new CustSuppliers(0, companyName, contactName, contactTitle, address, phone, isCustomer, isSupplier);
                db.AddCustSupplier(c);
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.StackTrace);
                MessageBox.Show("Database query error " + ex.Message);
            }
            Reset();
        }
        public List <CustSuppliers> GetAllCustSuppliers()
        {
            List <CustSuppliers> result = new List <CustSuppliers>();

            using (SqlCommand command = new SqlCommand("SELECT * FROM CustSuppliers", conn))
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int           custSupplierId = (int)reader["CustSupplierId"];
                        string        companyName    = (string)reader["CompanyName"];
                        string        contactName    = (string)reader["ContactName"];
                        string        contactTitle   = (string)reader["ContactTitle"];
                        string        address        = (string)reader["Address"];
                        string        phone          = (string)reader["Phone"];
                        Boolean       isCustomer     = (Boolean)reader["IsCustomer"];
                        Boolean       isSupplier     = (Boolean)reader["IsSupplier"];
                        CustSuppliers c = new CustSuppliers(custSupplierId, companyName, contactName, contactTitle, address, phone, isCustomer, isSupplier);
                        result.Add(c);
                    }
                }
            return(result);
        }