⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customers.cs

📁 采用vc#.net和sqlce实现智能手机端和服务器数据交换
💻 CS
📖 第 1 页 / 共 2 页
字号:
            {
                MessageBox.Show("No order data", "IBuySpy Delivery");
                return;
            }
                
            if (null == dvOrders)
            {
                dvOrders = new DataView(dtOrders);
            }

            this.cboCustomers.DisplayMember = "FullName";
            this.cboCustomers.ValueMember   = "CustomerID";
            this.lstOrders.DisplayMember    = "OrderID";
            this.lstOrders.ValueMember      = "OrderID";

            this.cboCustomers.DataSource    = dtCustomers;
            this.lstOrders.DataSource       = dvOrders;
        }

        /// Update the Order Status field on the user interface.
        ///
        internal void UpdateOrderStatus()
        {
            DataRowView row         = null;
            OrderStatus orderStatus = OrderStatus.Failed;

            if (0 == this.dvOrders.Count)
            {
                /// Because there are no orders for the customer, disable the user interface controls specific
                /// to the customer's orders.
                ///
                this.lstOrders.Enabled     = false;
                this.btnEditStatus.Enabled = false;
                this.btnViewOrder.Enabled  = false;

                return;
            }

            /// If the customer has orders, enable the user interface controls specific
            /// to the customer's orders.
            ///
            this.lstOrders.Enabled     = true;
            this.btnViewOrder.Enabled  = true;

            /// Get the current row.
            ///
            row         = (DataRowView)BindingContext[dvOrders].Current;
            orderStatus = (OrderStatus)Convert.ToInt32(row["Status"]);

            switch(orderStatus)
            {
                case OrderStatus.Failed: 
                    this.lblStatusValue.Text   = "Failed";
                    this.btnEditStatus.Text    = "Set Pending"; 
                    this.btnEditStatus.Enabled = true;

                    break;

                case OrderStatus.Pending:
                    this.lblStatusValue.Text   = "Pending";
                    this.btnEditStatus.Text    = "Set Failed"; 
                    this.btnEditStatus.Enabled = true;

                    break;

                default:
                    this.lblStatusValue.Text   = "Delivered";
                    this.btnEditStatus.Enabled = false;

                    break;
            }
        }

        /// This combobox allows users to select different customers. If the user changes customers, the new
        /// customer data is displayed.
        ///
        private void cboCustomers_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (0 <= this.cboCustomers.SelectedIndex && 
                this.customerID != Convert.ToInt32(this.cboCustomers.SelectedValue))
            {
                DataRowView row = null;

                /// If the current order has been modified in any way, and the user selects a different customer,
				/// the user's changes are discard: The CustomerOrders and Inventory datasets are reset.
                ///
                if (this.dataIBuySpy.HasChanges())
                {
                    if (DialogResult.OK == MessageBox.Show(String.Format("You have modified order {0}. Switching customers will discard all changes.", this.orderID),  
                        "IBuySpy Delivery", 
                        MessageBoxButtons.OKCancel, 
                        MessageBoxIcon.Asterisk, 
                        MessageBoxDefaultButton.Button1)) 
                    {
                        this.dataIBuySpy.ResetOrderDetails();
                    }
                    else
                    {
                        this.cboCustomers.SelectedValue = this.customerID;

                        return;
                    }
                }

                /// Set the current binding position.
                ///
                BindingContext[dtCustomers].Position = this.cboCustomers.SelectedIndex;

                /// Load the selected customer information from the Customer datatable.
                ///
                row = (DataRowView)BindingContext[dtCustomers].Current;

                this.customerID = Convert.ToInt32(row["CustomerID"]);

                /// Displays the customer's address information.
                ///
                this.lblAddressValue1.Text = row["Address"].ToString();
                this.lblAddressValue2.Text = String.Format(@"{0}, {1} {2}", row["City"], row["Region"], row["Zip"]); 
                this.lblAddressValue3.Text = row["Phone"].ToString();

                /// Set the data viewer to filter by the selected customer.
                ///
                this.dvOrders.RowFilter = String.Format("CustomerID = '{0}'", this.customerID);

                UpdateOrderStatus();
            }
        }

        /// This combobox allows users to select different orders for a specific customer. If the user changes
        /// orders, the new order information is displayed.
        ///
        private void lstOrders_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (0 <= this.lstOrders.SelectedIndex && 
                this.orderID.ToString() != this.lstOrders.Text)
            {
                /// If the current order has been modified in any way, and the user selects a different order, the user's changes are discarded:
				/// The CustomerOrders and Inventory datasets are reset.
                ///
                if (this.dataIBuySpy.HasChanges())
                {
                    if (DialogResult.OK == MessageBox.Show(String.Format("You have modified order {0}. Switching orders will discard all changes.", this.orderID),  
                        "IBuySpy Delivery", 
                        MessageBoxButtons.OKCancel, 
                        MessageBoxIcon.Asterisk, 
                        MessageBoxDefaultButton.Button1)) 
                    {
                        this.dataIBuySpy.ResetOrderDetails();
                    }
                    else
                    {
                        this.lstOrders.SelectedValue = this.orderID;
                        return;
                    }
                }

                /// Set the current binding position.
                ///
                BindingContext[dvOrders].Position = this.lstOrders.SelectedIndex;
              
                this.orderID = Convert.ToInt32(this.lstOrders.Text);

                /// Update the status of the Order on the user interface.
                ///
                UpdateOrderStatus();
            }
        }

        /// Toggles the Order status from "Pending" to "Failed" and saves the changed status to the database.
        ///
        private void btnEditStatus_Click(object sender, System.EventArgs e)
        {
            DataRowView row         = null;
            OrderStatus orderStatus = OrderStatus.Failed;
            
            if (0 == this.dvOrders.Count)
            {
                return;
            }

            /// Get the current row.
            ///
            row = (DataRowView)BindingContext[this.dvOrders].Current;

            try
            {
                orderStatus = (OrderStatus)Convert.ToInt32(row["Status"]);

                row.BeginEdit();

                /// If status is "Pending", change the status to "Failed".
                ///
                if (OrderStatus.Pending == orderStatus) 
                {
                    row["Status"] = (int)OrderStatus.Failed;
                    this.dataIBuySpy.InventoryChanged = true;
                }

                /// If status is "Failed", change the status to "Pending".
                ///
                else if (OrderStatus.Failed == orderStatus) 
                {
                    row["Status"] = (int)OrderStatus.Pending;
                    this.dataIBuySpy.InventoryChanged = true;
                }
                
                row.EndEdit();

                /// Save the changes to the database.
                ///
                this.dataIBuySpy.SaveOrderStatus();
            }
            catch(SqlCeException err)
            {
                row.CancelEdit();
                IBuySpyData.ShowErrors(err);
                return;
            }
            catch(Exception err)
            {
                row.CancelEdit();
                MessageBox.Show("Save order status: " + err.Message, "IBuySpy Delivery");
                return;
            }

            /// Update the status of the order on the user interface.
            ///
            UpdateOrderStatus();
        }

        /// Displays the Orders control with the information related to the current order loaded.
        ///
        private void btnViewOrder_Click(object sender, System.EventArgs e)
        {
            /// Raise event to the main form to view orders.
            ///
            OrderEventArgs args = new OrderEventArgs();

            args.CustomerID     = this.customerID;
            args.CustomerName   = this.cboCustomers.Text;
            args.OrderID        = this.orderID;

            OnViewOrders(this, args);
        }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -