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

using Core.Mes.ClientFrameWork;
using Core.Mes.IBaseInterface;

namespace Core.Mes.ClientManager
{
	/// <summary>
	/// FrmSetBz 的摘要说明。
	/// </summary>
	public class FrmSetBz : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.ComboBox comboBox2;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.ComboBox comboBox3;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.TextBox textBox3;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FrmSetBz()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.comboBox2 = new System.Windows.Forms.ComboBox();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.comboBox3 = new System.Windows.Forms.ComboBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(168, 112);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "保存";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(256, 112);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 1;
            this.button2.Text = "关闭";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(16, 49);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(29, 12);
            this.label1.TabIndex = 2;
            this.label1.Text = "班次";
            // 
            // comboBox1
            // 
            this.comboBox1.DisplayMember = "BASENAME";
            this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.comboBox1.Location = new System.Drawing.Point(56, 46);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(104, 20);
            this.comboBox1.TabIndex = 6;
            this.comboBox1.ValueMember = "BASECODE";
            this.comboBox1.SelectedValueChanged += new System.EventHandler(this.comboBox1_SelectedValueChanged);
            // 
            // comboBox2
            // 
            this.comboBox2.DisplayMember = "BASENAME";
            this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.comboBox2.Location = new System.Drawing.Point(56, 79);
            this.comboBox2.Name = "comboBox2";
            this.comboBox2.Size = new System.Drawing.Size(104, 20);
            this.comboBox2.TabIndex = 7;
            this.comboBox2.ValueMember = "BASECODE";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(16, 82);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(29, 12);
            this.label2.TabIndex = 8;
            this.label2.Text = "班别";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(16, 16);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(29, 12);
            this.label3.TabIndex = 9;
            this.label3.Text = "用户";
            // 
            // textBox1
            // 
            this.textBox1.BackColor = System.Drawing.Color.White;
            this.textBox1.Location = new System.Drawing.Point(56, 12);
            this.textBox1.Name = "textBox1";
            this.textBox1.ReadOnly = true;
            this.textBox1.Size = new System.Drawing.Size(104, 21);
            this.textBox1.TabIndex = 10;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(176, 16);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(41, 12);
            this.label4.TabIndex = 11;
            this.label4.Text = "工作制";
            // 
            // comboBox3
            // 
            this.comboBox3.DisplayMember = "NAME_";
            this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.comboBox3.Items.AddRange(new object[] {
            "常白班",
            "两班",
            "三班"});
            this.comboBox3.Location = new System.Drawing.Point(224, 13);
            this.comboBox3.Name = "comboBox3";
            this.comboBox3.Size = new System.Drawing.Size(104, 20);
            this.comboBox3.TabIndex = 12;
            this.comboBox3.ValueMember = "ID_";
            this.comboBox3.SelectedValueChanged += new System.EventHandler(this.comboBox3_SelectedValueChanged);
            // 
            // textBox2
            // 
            this.textBox2.BackColor = System.Drawing.Color.White;
            this.textBox2.Location = new System.Drawing.Point(224, 45);
            this.textBox2.Name = "textBox2";
            this.textBox2.ReadOnly = true;
            this.textBox2.Size = new System.Drawing.Size(104, 21);
            this.textBox2.TabIndex = 13;
            // 
            // textBox3
            // 
            this.textBox3.BackColor = System.Drawing.Color.White;
            this.textBox3.Location = new System.Drawing.Point(224, 78);
            this.textBox3.Name = "textBox3";
            this.textBox3.ReadOnly = true;
            this.textBox3.Size = new System.Drawing.Size(104, 21);
            this.textBox3.TabIndex = 14;
            // 
            // FrmSetBz
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(346, 143);
            this.Controls.Add(this.textBox3);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.comboBox3);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.comboBox2);
            this.Controls.Add(this.comboBox1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FrmSetBz";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "设置班组";
            this.Load += new System.EventHandler(this.FrmSetBz_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void FrmSetBz_Load(object sender, System.EventArgs e)
		{
			this.textBox1.Text = ClientCommon._UserInfo.UserName;
			GetDB();
		}
		private void GetDB()
		{
			string strOut = "";
			DataSet ds = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", 
				"Core.Mes.ServerCommon.UserInfoManager", "GetBz", new object[]{"3002"}, out strOut) as DataSet;
		            
			if (strOut == "") 
			{
				this.comboBox1.DataSource = ds.Tables[0];
				this.comboBox1.SelectedValue = ClientCommon._UserInfo.UserBc;
			}
			ds = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", 
				"Core.Mes.ServerCommon.UserInfoManager", "GetBz", new object[]{"3003"}, out strOut) as DataSet;
		            
			if (strOut == "") 
			{
				this.comboBox2.DataSource = ds.Tables[0];
				this.comboBox2.SelectedValue = ClientCommon._UserInfo.UserBb;
			}

			this.comboBox3.SelectedIndex = GetRz(ClientCommon._UserInfo.UserRz);
		}
		private int GetRz(string str)
		{
			switch(str) 
			{
				case "1" :
					return 0;
				case "2" :
					return 1;
				case "3" :
					return 2;
				default :
					return 0;
			}
		}

		private void comboBox3_SelectedValueChanged(object sender, System.EventArgs e)
		{
			SetBz();
		}

		private void SetBz()
		{
			if ( this.comboBox3.SelectedIndex == 1 )
			{
				if ( this.comboBox1.SelectedIndex == 0 )
				{
					this.textBox2.Text = "08:00:00";
					this.textBox3.Text = "20:00:00";
					return;
				}
				if ( this.comboBox1.SelectedIndex == 2 )
				{
					this.textBox2.Text = "20:00:00";
					this.textBox3.Text = "08:00:00";
					return;
				}
			}
			if ( this.comboBox3.SelectedIndex == 2 )
			{
				if ( this.comboBox1.SelectedIndex == 0 )
				{
					this.textBox2.Text = "08:00:00";
					this.textBox3.Text = "16:00:00";
					return;
				}
				if ( this.comboBox1.SelectedIndex == 1 )
				{
					this.textBox2.Text = "16:00:00";
					this.textBox3.Text = "24:00:00";
					return;
				}
				if ( this.comboBox1.SelectedIndex == 2 )
				{
					this.textBox2.Text = "00:00:00";
					this.textBox3.Text = "08:00:00";
					return;
				}
			}

			this.textBox2.Text = "";
			this.textBox3.Text = "";
		}

		private void comboBox1_SelectedValueChanged(object sender, System.EventArgs e)
		{
			SetBz();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			_boFlag = false;
			this.Close();
		}

		public bool _boFlag = false;
		private void button1_Click(object sender, System.EventArgs e)
		{
			string strOut = "";
			object obj = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", 
				"Core.Mes.ServerCommon.UserInfoManager", "SetBz", 
				new object[]{ClientCommon._UserInfo.UserID,
								Convert.ToString(this.comboBox3.SelectedIndex + 1),
								this.comboBox2.SelectedValue.ToString()}, out strOut);
		            
			if (strOut != "") { MessageBox.Show("保存失败!/n" + strOut); return ;  }
			
			if (Convert.ToInt32(obj) < 1) { MessageBox.Show("保存失败!"); return; }
		
			MessageBox.Show("保存成功!");

			ClientCommon._UserInfo.UserBc = this.comboBox1.SelectedValue.ToString();
			ClientCommon._UserInfo.UserBb = this.comboBox2.SelectedValue.ToString();
			ClientCommon._UserInfo.UserRz = Convert.ToString(this.comboBox3.SelectedIndex + 1);
			
			_boFlag = true;
			this.Close();
		}
	}
}
