using System;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;

namespace MuEditor
{
    public class T_CashShop_Point : frmBase
    {
        private IContainer components;

        private GroupBox groupBox1;

        private Label label1;

        private ComboBox txtAccount;

        private Label label2;

        private System.Windows.Forms.TextBox WCoinC;

        private MuEditor.TextBox WCoinC_Add;

        private Label label3;

        private Button btn_CashShop;

        private GroupBox groupBox2;
        private System.Windows.Forms.TextBox GoblinPoint;
        private Label label4;
        private Label label5;
        private TextBox GoblinPoint_Add;
        private Button btn_CashShopGP;
        private Button btn_CashShopWP;
        private TextBox WCoinP_Add;
        private Label label7;
        private System.Windows.Forms.TextBox WCoinP;
        private Label label6;
        private DataGridView CashLog;

        public T_CashShop_Point()
        {
            this.InitializeComponent();
        }

        private void btn_CashShopGP_Click(object sender, EventArgs e)
        {
            if (this.txtAccount.Text.Trim() == "" || this.GoblinPoint_Add.Text.Trim() == "0")
            {
                return;
            }
            string str = string.Format("UPDATE T_InGameShop_Point SET GoblinPoint += {0} WHERE (AccountID = N'{1}')", this.GoblinPoint_Add.Text.Trim(), this.txtAccount.Text.Trim());
            try
            {
                if (!base.Me_ExecuteSQL(str))
                {
                    Utils.WarningMessage("Operation Failed.");
                }
                else
                {
                    str = string.Format("INSERT INTO CashLog (UserID, Amount) VALUES ('{0}', {1});", this.txtAccount.Text.Trim(), this.GoblinPoint_Add.Text.Trim());
                    OleDbCommand oleDbCommand = new OleDbCommand(str.ToString(), frmBase.Mu_Conn);
                    oleDbCommand.ExecuteNonQuery();
                    Utils.InfoMessage("Operation Successful!");
                    this.InputAccount(this.txtAccount.Text.Trim());
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                string[] message = new string[] { "Error:", exception.Message, "\nSource:", exception.Source, "\nTrace:", exception.StackTrace };
                Utils.WarningMessage(string.Concat(message));
            }
        }

        private void btn_CashShop_Click(object sender, EventArgs e)
        {
            if (this.txtAccount.Text.Trim() == "" || this.WCoinC_Add.Text.Trim() == "0")
            {
                return;
            }
            string str = string.Format("UPDATE T_InGameShop_Point SET WCoinC += {0} WHERE (AccountID = N'{1}')", this.WCoinC_Add.Text.Trim(), this.txtAccount.Text.Trim());
            try
            {
                if (!base.Me_ExecuteSQL(str))
                {
                    Utils.WarningMessage("Operation Failed.");
                }
                else
                {
                    str = string.Format("INSERT INTO CashLog (UserID, Amount) VALUES ('{0}', {1});", this.txtAccount.Text.Trim(), this.WCoinC_Add.Text.Trim());
                    OleDbCommand oleDbCommand = new OleDbCommand(str.ToString(), frmBase.Mu_Conn);
                    oleDbCommand.ExecuteNonQuery();
                    Utils.InfoMessage("Operation Successful!");
                    this.InputAccount(this.txtAccount.Text.Trim());
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                string[] message = new string[] { "Error:", exception.Message, "\nSource:", exception.Source, "\nTrace:", exception.StackTrace };
                Utils.WarningMessage(string.Concat(message));
            }
        }

        private void btn_CashShopWP_Click(object sender, EventArgs e)
        {
            if (this.txtAccount.Text.Trim() == "" || this.WCoinP_Add.Text.Trim() == "0")
            {
                return;
            }
            string str = string.Format("UPDATE T_InGameShop_Point SET WCoinP += {0} WHERE (AccountID = N'{1}')", this.WCoinP_Add.Text.Trim(), this.txtAccount.Text.Trim());
            try
            {
                if (!base.Me_ExecuteSQL(str))
                {
                    Utils.WarningMessage("Operation Failed.");
                }
                else
                {
                    str = string.Format("INSERT INTO CashLog (UserID, Amount) VALUES ('{0}', {1});", this.txtAccount.Text.Trim(), this.WCoinP_Add.Text.Trim());
                    OleDbCommand oleDbCommand = new OleDbCommand(str.ToString(), frmBase.Mu_Conn);
                    oleDbCommand.ExecuteNonQuery();
                    Utils.InfoMessage("Operation Successful!");
                    this.InputAccount(this.txtAccount.Text.Trim());
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                string[] message = new string[] { "Error:", exception.Message, "\nSource:", exception.Source, "\nTrace:", exception.StackTrace };
                Utils.WarningMessage(string.Concat(message));
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && this.components != null)
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(T_CashShop_Point));
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.btn_CashShopWP = new System.Windows.Forms.Button();
            this.WCoinP_Add = new MuEditor.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.WCoinP = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.btn_CashShopGP = new System.Windows.Forms.Button();
            this.label5 = new System.Windows.Forms.Label();
            this.GoblinPoint_Add = new MuEditor.TextBox();
            this.GoblinPoint = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.btn_CashShop = new System.Windows.Forms.Button();
            this.WCoinC_Add = new MuEditor.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.WCoinC = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtAccount = new System.Windows.Forms.ComboBox();
            this.label1 = new System.Windows.Forms.Label();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.CashLog = new System.Windows.Forms.DataGridView();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.CashLog)).BeginInit();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.btn_CashShopWP);
            this.groupBox1.Controls.Add(this.WCoinP_Add);
            this.groupBox1.Controls.Add(this.label7);
            this.groupBox1.Controls.Add(this.WCoinP);
            this.groupBox1.Controls.Add(this.label6);
            this.groupBox1.Controls.Add(this.btn_CashShopGP);
            this.groupBox1.Controls.Add(this.label5);
            this.groupBox1.Controls.Add(this.GoblinPoint_Add);
            this.groupBox1.Controls.Add(this.GoblinPoint);
            this.groupBox1.Controls.Add(this.label4);
            this.groupBox1.Controls.Add(this.btn_CashShop);
            this.groupBox1.Controls.Add(this.WCoinC_Add);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.WCoinC);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.txtAccount);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new System.Drawing.Point(8, 9);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(449, 171);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "CashShop Management";
            // 
            // btn_CashShopWP
            // 
            this.btn_CashShopWP.Location = new System.Drawing.Point(310, 50);
            this.btn_CashShopWP.Name = "btn_CashShopWP";
            this.btn_CashShopWP.Size = new System.Drawing.Size(109, 25);
            this.btn_CashShopWP.TabIndex = 16;
            this.btn_CashShopWP.Text = "Update WCoinP";
            this.btn_CashShopWP.UseVisualStyleBackColor = true;
            this.btn_CashShopWP.Click += new System.EventHandler(this.btn_CashShopWP_Click);
            // 
            // WCoinP_Add
            // 
            this.WCoinP_Add.IsOnlyNumber = false;
            this.WCoinP_Add.Location = new System.Drawing.Point(204, 53);
            this.WCoinP_Add.Name = "WCoinP_Add";
            this.WCoinP_Add.Size = new System.Drawing.Size(100, 20);
            this.WCoinP_Add.TabIndex = 15;
            this.WCoinP_Add.Text = "0";
            this.WCoinP_Add.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(177, 56);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(21, 13);
            this.label7.TabIndex = 14;
            this.label7.Text = "+/-";
            // 
            // WCoinP
            // 
            this.WCoinP.Location = new System.Drawing.Point(82, 53);
            this.WCoinP.Name = "WCoinP";
            this.WCoinP.ReadOnly = true;
            this.WCoinP.Size = new System.Drawing.Size(89, 20);
            this.WCoinP.TabIndex = 13;
            this.WCoinP.Text = "0";
            this.WCoinP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(9, 56);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(52, 13);
            this.label6.TabIndex = 12;
            this.label6.Text = "WCoinP：";
            // 
            // btn_CashShopGP
            // 
            this.btn_CashShopGP.Location = new System.Drawing.Point(310, 109);
            this.btn_CashShopGP.Name = "btn_CashShopGP";
            this.btn_CashShopGP.Size = new System.Drawing.Size(109, 25);
            this.btn_CashShopGP.TabIndex = 11;
            this.btn_CashShopGP.Text = "Update GPoints";
            this.btn_CashShopGP.UseVisualStyleBackColor = true;
            this.btn_CashShopGP.Click += new System.EventHandler(this.btn_CashShopGP_Click);
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(177, 115);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(21, 13);
            this.label5.TabIndex = 10;
            this.label5.Text = "+/-";
            // 
            // GoblinPoint_Add
            // 
            this.GoblinPoint_Add.IsOnlyNumber = false;
            this.GoblinPoint_Add.Location = new System.Drawing.Point(204, 112);
            this.GoblinPoint_Add.Name = "GoblinPoint_Add";
            this.GoblinPoint_Add.Size = new System.Drawing.Size(100, 20);
            this.GoblinPoint_Add.TabIndex = 9;
            this.GoblinPoint_Add.Text = "0";
            this.GoblinPoint_Add.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // GoblinPoint
            // 
            this.GoblinPoint.Location = new System.Drawing.Point(82, 112);
            this.GoblinPoint.Name = "GoblinPoint";
            this.GoblinPoint.ReadOnly = true;
            this.GoblinPoint.Size = new System.Drawing.Size(89, 20);
            this.GoblinPoint.TabIndex = 8;
            this.GoblinPoint.Text = "0";
            this.GoblinPoint.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(9, 115);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(67, 13);
            this.label4.TabIndex = 7;
            this.label4.Text = "GoblinPoint：";
            // 
            // btn_CashShop
            // 
            this.btn_CashShop.Location = new System.Drawing.Point(310, 81);
            this.btn_CashShop.Name = "btn_CashShop";
            this.btn_CashShop.Size = new System.Drawing.Size(109, 25);
            this.btn_CashShop.TabIndex = 6;
            this.btn_CashShop.Text = "Update WCoinC";
            this.btn_CashShop.UseVisualStyleBackColor = true;
            this.btn_CashShop.Click += new System.EventHandler(this.btn_CashShop_Click);
            // 
            // WCoinC_Add
            // 
            this.WCoinC_Add.IsOnlyNumber = false;
            this.WCoinC_Add.Location = new System.Drawing.Point(204, 84);
            this.WCoinC_Add.Name = "WCoinC_Add";
            this.WCoinC_Add.Size = new System.Drawing.Size(100, 20);
            this.WCoinC_Add.TabIndex = 5;
            this.WCoinC_Add.Text = "0";
            this.WCoinC_Add.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(177, 87);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(21, 13);
            this.label3.TabIndex = 4;
            this.label3.Text = "+/-";
            // 
            // WCoinC
            // 
            this.WCoinC.Location = new System.Drawing.Point(82, 84);
            this.WCoinC.Name = "WCoinC";
            this.WCoinC.ReadOnly = true;
            this.WCoinC.Size = new System.Drawing.Size(89, 20);
            this.WCoinC.TabIndex = 3;
            this.WCoinC.Text = "0";
            this.WCoinC.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(9, 87);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(52, 13);
            this.label2.TabIndex = 2;
            this.label2.Text = "WCoinC：";
            // 
            // txtAccount
            // 
            this.txtAccount.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
            this.txtAccount.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
            this.txtAccount.FormattingEnabled = true;
            this.txtAccount.Location = new System.Drawing.Point(62, 26);
            this.txtAccount.MaxLength = 10;
            this.txtAccount.Name = "txtAccount";
            this.txtAccount.Size = new System.Drawing.Size(121, 21);
            this.txtAccount.TabIndex = 1;
            this.txtAccount.SelectedIndexChanged += new System.EventHandler(this.txtAccount_SelectedIndexChanged);
            this.txtAccount.TextChanged += new System.EventHandler(this.txtAccount_TextChanged);
            this.txtAccount.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtAccount_KeyPress);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 30);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(50, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Account:";
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.CashLog);
            this.groupBox2.Location = new System.Drawing.Point(8, 186);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(473, 304);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "SQL - CashLog";
            // 
            // CashLog
            // 
            this.CashLog.AllowUserToAddRows = false;
            this.CashLog.AllowUserToDeleteRows = false;
            this.CashLog.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.CashLog.Location = new System.Drawing.Point(12, 22);
            this.CashLog.Name = "CashLog";
            this.CashLog.ReadOnly = true;
            this.CashLog.RowTemplate.Height = 23;
            this.CashLog.Size = new System.Drawing.Size(447, 272);
            this.CashLog.TabIndex = 0;
            // 
            // T_CashShop_Point
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.Silver;
            this.ClientSize = new System.Drawing.Size(486, 502);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "T_CashShop_Point";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "CashShop Point Management";
            this.Load += new System.EventHandler(this.T_CashShop_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.CashLog)).EndInit();
            this.ResumeLayout(false);

        }

        public void InputAccount(string account)
        {
            this.Cursor = Cursors.WaitCursor;
            this.showByAccount(account);
            this.Cursor = Cursors.Default;
        }

        private void showByAccount(string account)
        {
            if (account == "")
            {
                return;
            }
            if (frmBase.Me_Conn.State != ConnectionState.Open)
            {
                return;
            }
            string str = null;
            try
            {
                str = string.Format("SELECT [WCoinP],[WCoinC],[GoblinPoint] FROM [T_InGameShop_Point] WHERE ([AccountID] = N'{0}')", account);
                OleDbDataReader oleDbDataReader = (new OleDbCommand(str, frmBase.Me_Conn)).ExecuteReader();
                if (!oleDbDataReader.Read())
                {
                    Utils.WarningMessage(string.Concat("Sorry, no account [", account, "] corresponding integrating information!"));
                    this.WCoinP.Text = "0";
                    this.WCoinC.Text = "0";
                    this.GoblinPoint.Text = "0";
                }
                else
                {
                    this.WCoinP.Text = Convert.ToString(oleDbDataReader.GetValue(0));
                    this.WCoinC.Text = Convert.ToString(oleDbDataReader.GetValue(1));
                    this.GoblinPoint.Text = Convert.ToString(oleDbDataReader.GetValue(2));
                }
                oleDbDataReader.Close();
                this.WCoinP_Add.Text = "0";
                this.WCoinC_Add.Text = "0";
                this.GoblinPoint_Add.Text = "0";
                this.showByCashLog(account);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                string[] message = new string[] { "SQL：", str, "\nError:", exception.Message, "\nSource:", exception.Source, "\nTrace:", exception.StackTrace };
                Utils.WarningMessage(string.Concat(message));
            }
        }

        private void showByCashLog(string UserID)
        {
            if (UserID == "")
            {
                return;
            }
            if (frmBase.Mu_Conn.State != ConnectionState.Open)
            {
                return;
            }
            string str = null;
            try
            {
                str = string.Format("SELECT [ID] AS [ID], [UserID] AS [Username], [Amount] AS [Amount], [SentDate] AS [Date] FROM [CashLog] WHERE ([UserID] = N'{0}') ORDER BY [ID] DESC", UserID);
                OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(new OleDbCommand(str, frmBase.Mu_Conn));
                DataTable dataTable = new DataTable();
                oleDbDataAdapter.Fill(dataTable);
                this.CashLog.DataSource = dataTable;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                string[] message = new string[] { "SQL：", str, "\nError:", exception.Message, "\nSource:", exception.Source, "\nTrace:", exception.StackTrace };
                Utils.WarningMessage(string.Concat(message));
            }
        }

        private void T_CashShop_Load(object sender, EventArgs e)
        {
        }

        private void txtAccount_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                this.InputAccount(this.txtAccount.Text.Trim());
            }
        }

        private void txtAccount_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.InputAccount(this.txtAccount.Text.Trim());
        }

        private void txtAccount_TextChanged(object sender, EventArgs e)
        {
            if (this.txtAccount.Items.Contains(this.txtAccount.Text) || this.txtAccount.Text == null)
            {
                return;
            }
            if (frmBase.Me_Conn.State != ConnectionState.Open)
            {
                return;
            }
            string str = null;
            try
            {
                str = string.Format("SELECT TOP 100 [AccountID] FROM [T_InGameShop_Point] WHERE [AccountID] LIKE '{0}%'", this.txtAccount.Text);
                OleDbDataReader oleDbDataReader = (new OleDbCommand(str, frmBase.Me_Conn)).ExecuteReader();
                object value = null;
                while (oleDbDataReader.Read())
                {
                    value = oleDbDataReader.GetValue(0);
                    if (this.txtAccount.Items.Contains(value))
                    {
                        continue;
                    }
                    this.txtAccount.Items.Add(value);
                }
                oleDbDataReader.Close();
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                string[] message = new string[] { "SQL：", str, "\nError:", exception.Message, "\nSource:", exception.Source, "\nTrace:", exception.StackTrace };
                Utils.WarningMessage(string.Concat(message));
            }
        }

        private void txtAccountLoad()
        {
            if (frmBase.Me_Conn.State != ConnectionState.Open)
            {
                return;
            }
            string str = null;
            try
            {
                str = "SELECT TOP 100 [AccountID] FROM [T_InGameShop_Point]";
                OleDbDataReader oleDbDataReader = (new OleDbCommand(str, frmBase.Me_Conn)).ExecuteReader();
                this.txtAccount.Items.Clear();
                this.txtAccount.AutoCompleteCustomSource.Clear();
                this.txtAccount.Text = "";
                while (oleDbDataReader.Read())
                {
                    this.txtAccount.Items.Add(oleDbDataReader.GetValue(0));
                }
                if (this.txtAccount.Items.Count > 0)
                {
                    this.txtAccount.SelectedIndex = 0;
                }
                oleDbDataReader.Close();
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                string[] message = new string[] { "SQL：", str, "\nError:", exception.Message, "\nSource:", exception.Source, "\nTrace:", exception.StackTrace };
                Utils.WarningMessage(string.Concat(message));
            }
        }
    }
}