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

📄 signature.cs

📁 采用vc#.net和sqlce实现智能手机端和服务器数据交换
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlServerCe;
using System.Windows.Forms;
using System.Threading;
using System.Reflection;

namespace Microsoft.Sql.SqlCe.Samples.Cs.IBuySpyDelivery.IBuySpyDevice
{
	/// <summary>
	/// Summary description for the Signature Control. This control allows users to add a signature to an order as well
	/// as saving the Orders and OrderDetails information to the local database.
	/// </summary>
	public class Signature : System.Windows.Forms.Control
	{
        private System.Windows.Forms.Button btnViewOrder;
        private System.Windows.Forms.PictureBox pboIDegree;
        private System.Windows.Forms.Label lblSignature;
        private System.Windows.Forms.Button btnClear;
        private System.Windows.Forms.Button btnFinish;

        private SignatureBox signatureBox = null;
        byte[] signatureData = null;
        private IBuySpyData dataIBuySpy = null;
        private int orderID = -1;
        private OrderStatus orderStatus = OrderStatus.Failed;

        internal event ViewCustomerEventHandler OnViewCustomers;
        internal event ViewOrdersEventHandler OnViewOrders;
        
        public Signature()
        {
            dataIBuySpy = IBuySpyData.GetInstance();

            /// This call is required by the Windows.Forms Form Designer.
            ///
            InitializeComponent();

            this.signatureBox           = new SignatureBox(220, 110);
            this.signatureBox.BackColor = System.Drawing.Color.Gold;
            this.signatureBox.Location  = new System.Drawing.Point(10, 42);
            this.signatureBox.Size      = new System.Drawing.Size(220, 110);
            this.Controls.Add(this.signatureBox);

			this.pboIDegree.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("IBuySpyDevice.idegree.gif"));
        }

        internal int OrderID
        {
            get
            {
                return orderID;
            }
            set
            {
                orderID = value;
            }
        }

        internal OrderStatus Status
        {
            get
            {
                return orderStatus;
            }
            set
            {
                orderStatus = value;
            }
        }

		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.btnViewOrder = new System.Windows.Forms.Button();
            this.btnFinish = new System.Windows.Forms.Button();
            this.lblSignature = new System.Windows.Forms.Label();
            this.btnClear = new System.Windows.Forms.Button();
            this.pboIDegree = new System.Windows.Forms.PictureBox();
            /// 
            /// btnViewOrder
            /// 
            this.btnViewOrder.Location = new System.Drawing.Point(132, 168);
            this.btnViewOrder.Size = new System.Drawing.Size(100, 24);
            this.btnViewOrder.Text = "<< View Order";
            this.btnViewOrder.Click += new System.EventHandler(this.btnViewOrder_Click);
            /// 
            /// btnFinish
            /// 
            this.btnFinish.Location = new System.Drawing.Point(132, 198);
            this.btnFinish.Size = new System.Drawing.Size(100, 24);
            this.btnFinish.Text = "Finish >>";
            this.btnFinish.Click += new System.EventHandler(this.btnFinish_Click);
            /// 
            /// lblSignature
            /// 
            this.lblSignature.Location = new System.Drawing.Point(8, 8);
            this.lblSignature.Size = new System.Drawing.Size(144, 16);
            this.lblSignature.Text = "Please sign your order:";
            /// 
            /// btnClear
            /// 
            this.btnClear.Location = new System.Drawing.Point(160, 6);
            this.btnClear.Size = new System.Drawing.Size(72, 24);
            this.btnClear.Text = "Clear";
            this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
            /// 
            /// pboIDegree
            /// 
            this.pboIDegree.Location = new System.Drawing.Point(8, 168);
            this.pboIDegree.Size = new System.Drawing.Size(120, 55);
            /// 
            /// Signature
            /// 
            this.Controls.Add(this.btnClear);
            this.Controls.Add(this.lblSignature);
            this.Controls.Add(this.btnViewOrder);
            this.Controls.Add(this.btnFinish);
            this.Size = new System.Drawing.Size(240, 240);
        }
		#endregion

		/// Load the signature from the local database.
		///
        internal void LoadSignature()
        {
            this.signatureBox.Clear();

            /// If the status is delivered, the signature cannot be altered.
            ///
            if (OrderStatus.Delivered == this.orderStatus)
            {
                this.btnClear.Enabled  = false;
                this.btnFinish.Enabled = false;
            }
            /// If the status is pending, the signature can be altered.
            ///
            else if (OrderStatus.Pending == this.orderStatus)
            {
                this.btnClear.Enabled  = true;
                this.btnFinish.Enabled = true;
            }
            else   
            {
                throw (new Exception(@"Invalid state: only ""Pending"" or ""Delivered"" statuses is supported on this control"));
            }

            try
            {
                /// Load the signature byte array from the database.
                ///
                this.signatureData = dataIBuySpy.LoadSignature(this.orderID);

                /// If there is a signature in the database
				///
                if (null != this.signatureData)
                {
                    /// Update the signature box with a separate thread.
                    ///
                    Thread thread = new Thread(new ThreadStart(DisplaySignature));
                    thread.Start();
                }
                else
                {
                    /// Clear the signature box (display information and data).
                    ///
                    this.signatureBox.Clear();
                }
            }
            catch(SqlCeException e)
            {
                IBuySpyData.ShowErrors(e);
                return;
            }
            catch(Exception e)
            {
                MessageBox.Show("Load Signature: " + e.Message, "IBuySpy Delivery");
                return;
            }
        }

        /// Display the signature in the signature box.
        ///
        private void DisplaySignature() 
        {
            short[] buf = new short[Convert.ToInt32(signatureData.Length / 2)];

            /// Transfer the signature from byte array into a signature box coordinate format.
            ///
            Buffer.BlockCopy(signatureData, 0, buf, 0, signatureData.Length); 
            this.signatureBox.Signature = buf;
            try
            {
                /// Display the signature in the signature box.
                ///
                this.signatureBox.DisplaySignature();
            }
            catch(Exception e)
            {
                MessageBox.Show("Update Signature: " + e.Message, "IBuySpy Delivery");
            }

            this.signatureData = null;
        }

		/// Saves the CustomerOrders dataset to the Orders and OrderDetails tables in the local database.
		///
        private void btnFinish_Click(object sender, System.EventArgs e)
        {
            /// Prompt the user for permission to continue.
            ///
            if (DialogResult.OK != MessageBox.Show(String.Format("You are about to save order {0}. You will not be able to make additional changes.", this.orderID),  
                "IBuySpy Delivery", 
                MessageBoxButtons.OKCancel, 
                MessageBoxIcon.Asterisk, 
                MessageBoxDefaultButton.Button1)) 
            {
                return;
            }

            try
            {
                short[] buf = this.signatureBox.Signature;
                this.signatureData = new Byte[buf.Length * 2];

				/// Transfer the signature from signature box coordinate format into a byte array.
				///
                Buffer.BlockCopy(buf, 0, this.signatureData, 0, this.signatureData.Length); 

				/// Save the OrderDetails information to the OrderDetails table in the local database.
				/// Also, change the order status from pending to delivered.
				///
                this.dataIBuySpy.SaveOrderDetails(this.orderID);

				/// Saves the byte array containing the signature data to the Orders table in the local database.
				///
                this.dataIBuySpy.SaveSignature(this.orderID, this.signatureData);
            }
            catch(SqlCeException err)
            {
                IBuySpyData.ShowErrors(err);
            }
            catch(Exception err)
            {
                MessageBox.Show("Save Signature:" + err.Message, "IBuySpy Delivery");
            }

            OnViewCustomers(this, new EventArgs());
        }

		/// Allows the user to go back to the Orders Control and continue making modifications (adding products) to the order.
		///
        private void btnViewOrder_Click(object sender, System.EventArgs e)
        {
            OnViewOrders(this, new OrderEventArgs());
        }

        /// Clears the signature box.
        ///
        private void btnClear_Click(object sender, System.EventArgs e)
        {
            this.signatureBox.Clear();
            this.signatureData = null;
        }
	}
}

⌨️ 快捷键说明

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