using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using JXC_MIS.MyClass;
using JXC_MIS.DataTier;

namespace JXC_MIS.UserTier.NewForm
{
	public class frmCheckManage : JXC_MIS.UserTier.BaseForm.frmTreeFlexGrid
	{
		private System.ComponentModel.IContainer components = null;


			private  string sCheckReceiptName ; //审核单据的名字
			private System.Data.DataSet dst = new System.Data.DataSet();
			protected ClsDataBase newDB=new ClsDataBase() ;
			protected ClsReceiptAttrib newR_Attrib=new ClsReceiptAttrib();
//			protected ClsReceiptMethod newR_Method=new ClsReceiptMethod();
//			protected ClsInitData InitData=new ClsInitData();
		protected ClsDataBaseAccess newADO=new ClsDataBaseAccess();
		protected ClsCellAttrib newCellAttrib=new ClsCellAttrib();
			private ToolTip nToolTip=new ToolTip();  //控件提示
			private string m_ColExpress;                   //计算列表达式
			private string m_ShowFormat;                    //显示格式
			string MasterSql="";
			string DetailSql="";
			string sReceiptNO="";
			private System.Windows.Forms.Label label1;
			private System.Windows.Forms.DateTimePicker dtp_End;
			private System.Windows.Forms.DateTimePicker dtp_Start;
		private System.Windows.Forms.ComboBox cbo_Checker;
		private System.Windows.Forms.Button cmd_Check;
		private System.Windows.Forms.DateTimePicker dateTimePicker1;
			string sReceiptType="销售收款";

		public frmCheckManage()
		{
			// 该调用是 Windows 窗体设计器所必需的。
			InitializeComponent();

			// TODO: 在 InitializeComponent 调用后添加任何初始化
		}

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

			#region 设计器生成的代码
			/// <summary>
			/// 设计器支持所需的方法 - 不要使用代码编辑器修改
			/// 此方法的内容。
			/// </summary>
			private void InitializeComponent()
			{
				System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmCheckManage));
				this.cmd_Check = new System.Windows.Forms.Button();
				this.label1 = new System.Windows.Forms.Label();
				this.dtp_End = new System.Windows.Forms.DateTimePicker();
				this.dtp_Start = new System.Windows.Forms.DateTimePicker();
				this.cbo_Checker = new System.Windows.Forms.ComboBox();
				this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
				this.SuspendLayout();
				// 
				// panel1
				// 
				this.panel1.Name = "panel1";
				this.panel1.Size = new System.Drawing.Size(780, 446);
				// 
				// spt_H
				// 
				this.spt_H.Location = new System.Drawing.Point(144, 256);
				this.spt_H.Name = "spt_H";
				this.spt_H.Size = new System.Drawing.Size(636, 4);
				// 
				// spt_V
				// 
				this.spt_V.Location = new System.Drawing.Point(140, 0);
				this.spt_V.Name = "spt_V";
				this.spt_V.Size = new System.Drawing.Size(4, 446);
				// 
				// tv_Tree
				// 
				this.tv_Tree.Name = "tv_Tree";
				this.tv_Tree.Size = new System.Drawing.Size(140, 446);
				// 
				// cbo_SetupName
				// 
				this.cbo_SetupName.Name = "cbo_SetupName";
				this.cbo_SetupName.Size = new System.Drawing.Size(124, 20);
				// 
				// pnl_Filter
				// 
				this.pnl_Filter.Name = "pnl_Filter";
				// 
				// cmd_Cancel
				// 
				this.cmd_Cancel.Name = "cmd_Cancel";
				// 
				// cmd_ExeQuery
				// 
				this.cmd_ExeQuery.Name = "cmd_ExeQuery";
				// 
				// grd_Filter
				// 
				this.grd_Filter.Name = "grd_Filter";
				// 
				// sbr_StatusBar
				// 
				this.sbr_StatusBar.Name = "sbr_StatusBar";
				this.sbr_StatusBar.Size = new System.Drawing.Size(780, 25);
				// 
				// t_s4
				// 
				this.t_s4.Visible = false;
				// 
				// tbr_Toolbar
				// 
				this.tbr_Toolbar.Name = "tbr_Toolbar";
				this.tbr_Toolbar.Size = new System.Drawing.Size(780, 28);
				this.tbr_Toolbar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbr_Toolbar_ButtonClick);
				// 
				// t_Refresh
				// 
				this.t_Refresh.Visible = false;
				// 
				// grd_Top
				// 
				this.grd_Top.Location = new System.Drawing.Point(144, 0);
				this.grd_Top.Name = "grd_Top";
				this.grd_Top.Size = new System.Drawing.Size(636, 256);
				this.grd_Top.Row_Click += new ljs.FlexGridRow_Click(this.grd_Top_Row_Click);
				this.grd_Top.Row_DoubleClick += new ljs.FlexGridRow_DoubleClick(this.grd_Top_Row_DoubleClick);
				// 
				// grd_Bottom
				// 
				this.grd_Bottom.Location = new System.Drawing.Point(144, 260);
				this.grd_Bottom.Name = "grd_Bottom";
				this.grd_Bottom.Size = new System.Drawing.Size(634, 186);
				// 
				// t_Menu
				// 
				this.t_Menu.Visible = false;
				// 
				// img_ImageList
				// 
				this.img_ImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("img_ImageList.ImageStream")));
				// 
				// cmd_Check
				// 
				this.cmd_Check.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
				this.cmd_Check.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
				this.cmd_Check.ForeColor = System.Drawing.Color.Red;
				this.cmd_Check.Location = new System.Drawing.Point(716, 2);
				this.cmd_Check.Name = "cmd_Check";
				this.cmd_Check.Size = new System.Drawing.Size(64, 24);
				this.cmd_Check.TabIndex = 23;
				this.cmd_Check.Text = "审 核(&C)";
				this.cmd_Check.Click += new System.EventHandler(this.cmd_Check_Click);
				// 
				// label1
				// 
				this.label1.Location = new System.Drawing.Point(146, 8);
				this.label1.Name = "label1";
				this.label1.Size = new System.Drawing.Size(520, 12);
				this.label1.TabIndex = 24;
				this.label1.Text = "起止日期：                             审核人：                审核日期：";
				// 
				// dtp_End
				// 
				this.dtp_End.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
				this.dtp_End.Location = new System.Drawing.Point(296, 4);
				this.dtp_End.Name = "dtp_End";
				this.dtp_End.Size = new System.Drawing.Size(84, 21);
				this.dtp_End.TabIndex = 27;
				// 
				// dtp_Start
				// 
				this.dtp_Start.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
				this.dtp_Start.Location = new System.Drawing.Point(204, 4);
				this.dtp_Start.Name = "dtp_Start";
				this.dtp_Start.Size = new System.Drawing.Size(90, 21);
				this.dtp_Start.TabIndex = 28;
				// 
				// cbo_Checker
				// 
				this.cbo_Checker.Location = new System.Drawing.Point(428, 4);
				this.cbo_Checker.Name = "cbo_Checker";
				this.cbo_Checker.Size = new System.Drawing.Size(96, 20);
				this.cbo_Checker.TabIndex = 29;
				// 
				// dateTimePicker1
				// 
				this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Short;
				this.dateTimePicker1.Location = new System.Drawing.Point(586, 4);
				this.dateTimePicker1.Name = "dateTimePicker1";
				this.dateTimePicker1.Size = new System.Drawing.Size(90, 21);
				this.dateTimePicker1.TabIndex = 30;
				// 
				// frmCheckManage
				// 
				this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
				this.ClientSize = new System.Drawing.Size(780, 499);
				this.Controls.Add(this.dateTimePicker1);
				this.Controls.Add(this.cmd_Check);
				this.Controls.Add(this.cbo_Checker);
				this.Controls.Add(this.dtp_Start);
				this.Controls.Add(this.dtp_End);
				this.Controls.Add(this.label1);
				this.Name = "frmCheckManage";
				this.Load += new System.EventHandler(this.frmCheckManage_Load);
				this.Controls.SetChildIndex(this.tbr_Toolbar, 0);
				this.Controls.SetChildIndex(this.sbr_StatusBar, 0);
				this.Controls.SetChildIndex(this.panel1, 0);
				this.Controls.SetChildIndex(this.pnl_Filter, 0);
				this.Controls.SetChildIndex(this.label1, 0);
				this.Controls.SetChildIndex(this.dtp_End, 0);
				this.Controls.SetChildIndex(this.dtp_Start, 0);
				this.Controls.SetChildIndex(this.cbo_Checker, 0);
				this.Controls.SetChildIndex(this.cmd_Check, 0);
				this.Controls.SetChildIndex(this.dateTimePicker1, 0);
				this.ResumeLayout(false);

			}
			#endregion

			private void frmCheckManage_Load(object sender, System.EventArgs e)
			{

				tv_Tree.Width =140;
				spt_H.Visible =true;
				this.grd_Top.Height =200;
				spt_H.BringToFront() ;
				this.ShowResize();
				grd_Top.OnlyRead=true;
				grd_Bottom.OnlyRead=true;
//				dtp_Start.Text=System.DateTime.Today.ToString("yyyy-mm-dd") ;
//				dtp_End.Text =System.DateTime.Today.ToString("yyyy-mm-dd") ;
//				InitData.InitComboBox(cbo_Customer,"SELECT fcName FROM I_Customer ");
				MasterSql=newR_Attrib.MasterViewFeildName;
				DetailSql=newR_Attrib.DetailViewFeildName;
//				this.InitTreeData("SELECT I_Enum.fcname FROM I_EnumType INNER JOIN  I_Enum ON I_EnumType.fgEnumTypeID = I_Enum.fgEnumTypeID WHERE (I_EnumType.fcName = '收款类型')");
				this.InitTreeData("Select fcReceiptName From S_receiptSetup where left(fcReceiptNo,3)='N04' and fcClass='1'");
				ShowData(grd_Top,MasterSql);
				ShowData(grd_Bottom,DetailSql);
				grd_Bottom.SetCellWidth =newR_Attrib.GetDetailColWidth("销售收款单");
			}
			protected override void InitTreeData(string p_TreeDataSource)
			{
				if (p_TreeDataSource!=null && p_TreeDataSource!="")
				{
					InitData.InitTreeView (tv_Tree,p_TreeDataSource,"审核管理");
				}

			}
			private  void ShowData(ljs.MyFlexGrid p_FlexGrid ,string p_Filter)
			{
				//添加行号
				p_FlexGrid.Clear();
				InitData.ShowGridData(p_FlexGrid,p_Filter);

			}
			protected override void tv_Tree_Click(object sender, EventArgs e)
			{

				TreeNode tn = new TreeNode();
				tn = tv_Tree.SelectedNode;
				if (tn != null)
				{
					string[] arrTemp=tn.Text.Split(':')  ;
				
					sReceiptType=arrTemp[0];
					//				CboReceiptNo.Text=sReceiptNO;
					//替换主从SQL语句中的单据编号变量
					newR_Attrib.LoadData(tn.Text) ;
                    MasterSql=newR_Attrib.MasterViewFeildName.ToLower() ;
					DetailSql=newR_Attrib.DetailViewFeildName.ToLower() ;
					string MasterSql1=MasterSql.Replace("@startdate",dtp_Start.Text);
					MasterSql1=MasterSql1.Replace("@enddate",dtp_End.Text);
					ShowData(grd_Top,MasterSql1);

				}

			}

//			private void cmd_Look_Click(object sender, System.EventArgs e)
//			{
//				frmSellReceive f=new frmSellReceive();
//				f.SetReceiptType=sReceiptType;
//				f.ShowDialog();
//
//			}

			private void cbo_Customer_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
			{
		  		
				if (e.KeyChar == (char)13) 
				{
//					newR_Method.ComboListSearch(cbo_Customer);
				}
       
			}

			private void cbo_Customer_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
			{
			}

		private void cmd_Look_Click(object sender, System.EventArgs e)
		{
		
		}

		private void cmd_Check_Click(object sender, System.EventArgs e)
		{

           ExeCheck(cbo_Checker.Text ,grd_Top.GetCellText(grd_Top.Row,1));

		}
		private void ExeCheck(string sChecker,string sReceiptNo)
		{
			string sUpdate="";
			sUpdate=newR_Attrib.MasterFeildName.ToLower();
			sUpdate=sUpdate.Replace("@checker",sChecker);
			sUpdate=sUpdate.Replace("@receiptno",sReceiptNo);
			newADO.ExeSql(sUpdate);
//			newADO.ExeSql("Update R_Sell Set fcChecker='"+cbo_Checker.Text +"' where fcSellNo=''");


		}

		/// <summary>
		/// 获得字符串中存在有"@"字符后面到"'"或"空格"位置的字符串
		/// </summary>
		/// <param name="p_sSql"></param>
		private string GetReplace(string p_sSql)
		{
			string replace="";
			int iStart;
			int iEnd=0;
			int i=0;
			iStart=p_sSql.IndexOf("@");
			if (iStart!=-1)
			{
				while (p_sSql.Substring(iStart+i,1)!="'")
				{
					if (p_sSql.Substring(iStart+i,1)==" " || p_sSql.Substring(iStart+i,1)=="%") break;
					replace=replace+p_sSql.Substring(iStart+i,1);
					i++;
				}
			}
			iEnd=iStart+i;
			return replace;
		}

		private void grd_Top_Row_Click(object sender, System.EventArgs e)
		{
			
		}

		private void grd_Top_Row_DoubleClick(object sender, System.EventArgs e)
		{
			string DetailSql1=DetailSql.ToLower().Replace("@receiptno",grd_Top.GetCellText(grd_Top.Row,1));
			ShowData(grd_Bottom,DetailSql1);


		}

		private void tbr_Toolbar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch (e.Button.Tag.ToString())
			{

				case "放弃":
					////					RecordCancel();
					break;
				case "预览":

					break;
				case "打印":
					//					ReceiptPrint();
					break;
				case "刷新":

					
					break;
				case "查询":
					string MasterSql1=MasterSql.Replace("@startdate",dtp_Start.Text);
					MasterSql1=MasterSql1.Replace("@enddate",dtp_End.Text);
					ShowData(grd_Top,MasterSql1);
					break;
				case "退出":
					this.Close();
					break;

				default:
 
					break;
			}
		}















		}
	}

