using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DTS_mediator
{
    public partial class frmSaveAuthorize : Form
    {
        public frmSaveAuthorize()//卡csAccess/csConn
        {
            InitializeComponent();
        }
        public static string FormName = "Authorize";
        public static string Field = "AuthorizeCode";

        public Boolean Authorize = false;
      
        public string AuthorizeCode
        { get {return  textBox1.Text; } }

        private void button1_Click(object sender, EventArgs e)
        {
            string comName = GetComName();

            if (textBox1.Text.Trim() == "")
            {
                MessageBox.Show("驗證碼不可為空白,請輸入驗證碼!");
                DialogResult = DialogResult.None;
            }
            else
            {
                string code = textBox1.Text;

                if (DTS_authorize(comName, code))
                {
                    string Val = textBox1.Text;
                    csAccess.SetStringKey(FormName, Field, Val);
                    Authorize = true;
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("驗證失敗,請重新輸入。");                   
                    DialogResult = DialogResult.None;
                    textBox1.Select();                 
                }
            }
        }
        private static string GetComName()
        {
            string cmd = "select NAME from PDM_APPGLOBAL";
            string comName = csConn.SqlDataReader_Field(cmd, true);
           
            return comName;
        }
        public static Boolean DTS_authorize()
        {
            Boolean result = false;
            string comName  = GetComName();
            if (comName == "")
            {
                MessageBox.Show("PDM的公司名稱不可為空白!");
                return result;
            }

            string code = csAccess.GetStringKey(frmSaveAuthorize.FormName, frmSaveAuthorize.Field, "");           
            if (comName != "" && code != "")
            {
                if (Math.Abs((comName.GetHashCode() + 3) * 6) == int.Parse(code))
                    result = true;
            }
            if (!result)//FOR 還沒設定,或設定錯誤.
            {
                frmSaveAuthorize f = new frmSaveAuthorize();
                DialogResult dialogResult = f.ShowDialog();//指定識別項以指示對話方塊的傳回值
                if (dialogResult == DialogResult.OK)//如果按下的是ok,才去呼叫myDialog.MyDialogOutputValue
                {
                    result = true;
                }
            }
            return result;
        }
        private  Boolean DTS_authorize(string com, string code)
        {
            Boolean result = false;
            if (Math.Abs((com.GetHashCode() + 3) * 6) == int.Parse(code))
                result = true;
            return result;
        }
        private void frmSaveAuthorize_Load(object sender, EventArgs e)
        {
            textBox1.Select(); 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("若預索取授權碼,請與我們聯絡。\t\n \t\n");
        }
    }
}

namespace DTS_mediator
{
    partial class frmSaveAuthorize
    {
        /// <summary>
        /// 設計工具所需的變數。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清除任何使用中的資源。
        /// </summary>
        /// <param name="disposing">如果應該公開 Managed 資源則為 true,否則為 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form 設計工具產生的程式碼

        /// <summary>
        /// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器修改這個方法的內容。
        ///
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button2 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(207, 14);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(53, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "確認";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 18);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(65, 12);
            this.label1.TabIndex = 1;
            this.label1.Text = "軟體授權碼";
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(83, 15);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(118, 22);
            this.textBox1.TabIndex = 2;
            //
            // button2
            //
            this.button2.Location = new System.Drawing.Point(266, 15);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(53, 23);
            this.button2.TabIndex = 4;
            this.button2.Text = "說明";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            //
            // frmSaveAuthorize
            //
            this.AcceptButton = this.button1;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(330, 53);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
            this.HelpButton = true;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmSaveAuthorize";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "軟體註冊資訊";
            this.Load += new System.EventHandler(this.frmSaveAuthorize_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button2;
    }
}

posted on 2008-05-02 18:43  una  阅读(127)  评论(0编辑  收藏  举报