using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using ljs;
using JXC_MIS.MyClass;
using JXC_MIS.DataTier ;
using JXC_MIS.UserTier.BaseForm ;
using JXC_MIS.UserTier.CommonForm  ;

namespace JXC_MIS.UserTier.NewForm
{
	public class frmSell : JXC_MIS.UserTier.BaseForm.frmReceiptBase
	{
		private System.ComponentModel.IContainer components = null;
		private System.Windows.Forms.ContextMenu MenuList;
		private System.Windows.Forms.MenuItem mnu_ItemQuery;
		private System.Windows.Forms.MenuItem mnu_FindPrice;
		private System.Windows.Forms.MenuItem mnu_findSellLR;
		private System.Windows.Forms.MenuItem mnu_CusQuery;
		private System.Windows.Forms.MenuItem mnu_CustInf;
		private System.Windows.Forms.MenuItem mnu_ProductInfor;
		private System.Windows.Forms.MenuItem mnu_InvoiceInf;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem mnu_MakeContract;
		private System.Windows.Forms.MenuItem mnu_MakeSend;
		private System.Windows.Forms.MenuItem mnu_MakeInvoiceZZ;
		private System.Windows.Forms.MenuItem mnu_MakeInvoicePT;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.MenuItem mnu_WriteCheck;
		private System.Windows.Forms.MenuItem mnu_ItemBatch;
		private System.Windows.Forms.MenuItem mnu_Managecheck;
		private System.Windows.Forms.MenuItem mnu_UnManagecheck;
		private System.Windows.Forms.MenuItem menuItem7;
		private System.Windows.Forms.MenuItem mnu_CountPrice;
		private System.Windows.Forms.MenuItem mnu_CountNoPrice;
		private System.Windows.Forms.MenuItem menuItem10;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.StatusBarPanel statusBarPanel1;
		private System.Windows.Forms.StatusBarPanel statusBarPanel2;
		//		ClsReceiptMethod newReceipt=new ClsReceiptMethod();
//		ClsCellAttrib newCellAttrib=new ClsCellAttrib();
		public frmSell()
		{
			// 该调用是 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()
		{
			this.MenuList = new System.Windows.Forms.ContextMenu();
			this.mnu_ItemQuery = new System.Windows.Forms.MenuItem();
			this.mnu_FindPrice = new System.Windows.Forms.MenuItem();
			this.mnu_findSellLR = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.mnu_CusQuery = new System.Windows.Forms.MenuItem();
			this.mnu_CustInf = new System.Windows.Forms.MenuItem();
			this.mnu_ProductInfor = new System.Windows.Forms.MenuItem();
			this.mnu_InvoiceInf = new System.Windows.Forms.MenuItem();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.mnu_MakeContract = new System.Windows.Forms.MenuItem();
			this.mnu_MakeSend = new System.Windows.Forms.MenuItem();
			this.mnu_MakeInvoiceZZ = new System.Windows.Forms.MenuItem();
			this.mnu_MakeInvoicePT = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this.mnu_WriteCheck = new System.Windows.Forms.MenuItem();
			this.mnu_ItemBatch = new System.Windows.Forms.MenuItem();
			this.mnu_Managecheck = new System.Windows.Forms.MenuItem();
			this.mnu_UnManagecheck = new System.Windows.Forms.MenuItem();
			this.menuItem7 = new System.Windows.Forms.MenuItem();
			this.mnu_CountPrice = new System.Windows.Forms.MenuItem();
			this.mnu_CountNoPrice = new System.Windows.Forms.MenuItem();
			this.menuItem10 = new System.Windows.Forms.MenuItem();
			this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
			this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
			// 
			// TxtTemp
			// 
			this.TxtTemp.Name = "TxtTemp";
			// 
			// sbr_statusBar
			// 
			this.sbr_statusBar.Name = "sbr_statusBar";
			this.sbr_statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																							 this.statusBarPanel1,
																							 this.statusBarPanel2});
			this.sbr_statusBar.Size = new System.Drawing.Size(671, 22);
			// 
			// tbr_Toolbar
			// 
			this.tbr_Toolbar.Name = "tbr_Toolbar";
			this.tbr_Toolbar.Size = new System.Drawing.Size(671, 29);
			this.tbr_Toolbar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbr_Toolbar_ButtonClick_1);
			// 
			// t_Menu
			// 
			this.t_Menu.DropDownMenu = this.MenuList;
			this.t_Menu.Text = "";
			// 
			// t_new
			// 
			this.t_new.Text = "";
			// 
			// t_Modify
			// 
			this.t_Modify.Text = "";
			// 
			// t_Save
			// 
			this.t_Save.Enabled = false;
			this.t_Save.Text = "";
			// 
			// t_Cancel
			// 
			this.t_Cancel.Enabled = false;
			this.t_Cancel.Text = "";
			// 
			// t_Preview
			// 
			this.t_Preview.Text = "";
			// 
			// t_Print
			// 
			this.t_Print.Text = "";
			// 
			// t_Refresh
			// 
			this.t_Refresh.Text = "";
			// 
			// t_Find
			// 
			this.t_Find.Text = "";
			// 
			// t_First
			// 
			this.t_First.Text = "";
			// 
			// t_Up
			// 
			this.t_Up.Text = "";
			// 
			// t_Down
			// 
			this.t_Down.Text = "";
			// 
			// t_Last
			// 
			this.t_Last.Text = "";
			// 
			// t_Exit
			// 
			this.t_Exit.Text = "";
			// 
			// ToolMenu
			// 
			this.ToolMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.menuItem1,
																					 this.mnu_MakeContract,
																					 this.mnu_MakeSend,
																					 this.mnu_MakeInvoiceZZ,
																					 this.mnu_MakeInvoicePT,
																					 this.menuItem6,
																					 this.mnu_WriteCheck,
																					 this.mnu_ItemBatch,
																					 this.mnu_Managecheck,
																					 this.mnu_UnManagecheck,
																					 this.menuItem7,
																					 this.mnu_CountPrice,
																					 this.mnu_CountNoPrice,
																					 this.menuItem10});
			// 
			// t_Menu1
			// 
			this.t_Menu1.Text = "";
			// 
			// CboReceiptNo
			// 
			this.CboReceiptNo.Name = "CboReceiptNo";
			this.CboReceiptNo.Size = new System.Drawing.Size(102, 20);
			// 
			// cbo_Year
			// 
			this.cbo_Year.Name = "cbo_Year";
			this.cbo_Year.Size = new System.Drawing.Size(48, 20);
			// 
			// cbo_Month
			// 
			this.cbo_Month.Name = "cbo_Month";
			this.cbo_Month.Size = new System.Drawing.Size(44, 20);
			// 
			// grd_Detail
			// 
			this.grd_Detail.Name = "grd_Detail";
			// 
			// grd_Footer
			// 
			this.grd_Footer.Name = "grd_Footer";
			// 
			// grd_Other
			// 
			this.grd_Other.Name = "grd_Other";
			// 
			// btnDown
			// 
			this.btnDown.Name = "btnDown";
			// 
			// grd_Header
			// 
			this.grd_Header.Name = "grd_Header";
			// 
			// grd_Bottom
			// 
			this.grd_Bottom.Name = "grd_Bottom";
			// 
			// grd_Top
			// 
			this.grd_Top.Name = "grd_Top";
			// 
			// pnl_Back
			// 
			this.pnl_Back.Name = "pnl_Back";
			this.pnl_Back.Size = new System.Drawing.Size(671, 30);
			// 
			// MenuList
			// 
			this.MenuList.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.mnu_ItemQuery,
																					 this.mnu_FindPrice,
																					 this.mnu_findSellLR,
																					 this.menuItem2,
																					 this.mnu_CusQuery,
																					 this.mnu_CustInf,
																					 this.mnu_ProductInfor,
																					 this.mnu_InvoiceInf});
			// 
			// mnu_ItemQuery
			// 
			this.mnu_ItemQuery.Index = 0;
			this.mnu_ItemQuery.Text = "存货查询";
			// 
			// mnu_FindPrice
			// 
			this.mnu_FindPrice.Index = 1;
			this.mnu_FindPrice.Text = "查看成本单价";
			// 
			// mnu_findSellLR
			// 
			this.mnu_findSellLR.Index = 2;
			this.mnu_findSellLR.Text = "查看本单销售利润";
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 3;
			this.menuItem2.Text = "查看客户对应的产品价格";
			// 
			// mnu_CusQuery
			// 
			this.mnu_CusQuery.Index = 4;
			this.mnu_CusQuery.Text = "客户销售查询";
			this.mnu_CusQuery.Click += new System.EventHandler(this.menuItem1_Click);
			// 
			// mnu_CustInf
			// 
			this.mnu_CustInf.Index = 5;
			this.mnu_CustInf.Text = "客户信息";
			// 
			// mnu_ProductInfor
			// 
			this.mnu_ProductInfor.Index = 6;
			this.mnu_ProductInfor.Text = "产品详细信息";
			// 
			// mnu_InvoiceInf
			// 
			this.mnu_InvoiceInf.Index = 7;
			this.mnu_InvoiceInf.Text = "发票清单详细信息";
			this.mnu_InvoiceInf.Click += new System.EventHandler(this.mnu_InvoiceInf_Click);
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 4;
			this.menuItem1.Text = "-";
			// 
			// mnu_MakeContract
			// 
			this.mnu_MakeContract.Index = 5;
			this.mnu_MakeContract.Text = "生成销售合同";
			this.mnu_MakeContract.Visible = false;
			this.mnu_MakeContract.Click += new System.EventHandler(this.mnu_MakeContract_Click);
			// 
			// mnu_MakeSend
			// 
			this.mnu_MakeSend.Index = 6;
			this.mnu_MakeSend.Text = "生成送货单";
			this.mnu_MakeSend.Visible = false;
			this.mnu_MakeSend.Click += new System.EventHandler(this.mnu_MakeSend_Click);
			// 
			// mnu_MakeInvoiceZZ
			// 
			this.mnu_MakeInvoiceZZ.Index = 7;
			this.mnu_MakeInvoiceZZ.Text = "生成增殖税发票清单";
			this.mnu_MakeInvoiceZZ.Visible = false;
			// 
			// mnu_MakeInvoicePT
			// 
			this.mnu_MakeInvoicePT.Index = 8;
			this.mnu_MakeInvoicePT.Text = "生成普通发票清单";
			this.mnu_MakeInvoicePT.Visible = false;
			// 
			// menuItem6
			// 
			this.menuItem6.Index = 9;
			this.menuItem6.Text = "-";
			this.menuItem6.Visible = false;
			// 
			// mnu_WriteCheck
			// 
			this.mnu_WriteCheck.Index = 10;
			this.mnu_WriteCheck.Text = "回写产品核对人";
			this.mnu_WriteCheck.Click += new System.EventHandler(this.mnu_WriteCheck_Click);
			// 
			// mnu_ItemBatch
			// 
			this.mnu_ItemBatch.Index = 11;
			this.mnu_ItemBatch.Text = "产品分批";
			// 
			// mnu_Managecheck
			// 
			this.mnu_Managecheck.Index = 12;
			this.mnu_Managecheck.Text = "提请主管审核";
			this.mnu_Managecheck.Click += new System.EventHandler(this.mnu_Managecheck_Click);
			// 
			// mnu_UnManagecheck
			// 
			this.mnu_UnManagecheck.Index = 13;
			this.mnu_UnManagecheck.Text = "注销审核";
			this.mnu_UnManagecheck.Click += new System.EventHandler(this.mnu_UnManagecheck_Click);
			// 
			// menuItem7
			// 
			this.menuItem7.Index = 14;
			this.menuItem7.Text = "-";
			// 
			// mnu_CountPrice
			// 
			this.mnu_CountPrice.Index = 15;
			this.mnu_CountPrice.Text = "计算含税单价";
			this.mnu_CountPrice.Visible = false;
			// 
			// mnu_CountNoPrice
			// 
			this.mnu_CountNoPrice.Index = 16;
			this.mnu_CountNoPrice.Text = "计算不含税单价";
			this.mnu_CountNoPrice.Visible = false;
			// 
			// menuItem10
			// 
			this.menuItem10.Index = 17;
			this.menuItem10.Text = "";
			this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
			// 
			// statusBarPanel1
			// 
			this.statusBarPanel1.Width = 300;
			// 
			// frmSell
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(598, 329);
			this.Name = "frmSell";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "单据名称";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.frmSell_Closing);
			this.Load += new System.EventHandler(this.frmSell_Load);
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();

		}
		#endregion

		private void frmSell_Load(object sender, System.EventArgs e)
		{
			this.ReceiptName="销售单";   
			this.ToolBarType(false);
			this.InitInterface();
		}

		private void frmSell_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
		
		}
		protected override void grd_Detail_Cell_Leave(object sender, System.EventArgs e)
		{
			base.grd_Detail_Cell_Leave(sender, e);
			//			MessageBox.Show("hello！", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
			if (grd_Detail.Col ==26 || grd_Detail.Col ==27 || grd_Detail.Col ==28)
			{
				string  a=grd_Detail.GetCellText(grd_Detail.Rows-1,26).ToString();
                string b=grd_Detail.GetCellText(grd_Detail.Rows-1,27).ToString();
				string c=grd_Detail.GetCellText(grd_Detail.Rows-1,28).ToString();
				if (a!="" && b!="" && c!="")
				{
					double d=double.Parse(c)-double.Parse(b);
					grd_Other.CellText(0,1,b) ;//
					grd_Other.CellText(0,3,d.ToString()) ;//
					grd_Other.CellText(0,7,c) ;
					grd_Other.CellText(0,5,this.newR_Method.SmallToBig(c)) ;
				}
			}
		}
		protected override void tbr_Toolbar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
		{
			base.tbr_Toolbar_ButtonClick (sender, e);

			switch (e.Button.Tag.ToString())
			{
					//				case "新增":
					//					ReceiptAdd();
					//
					//					break;
					//				case "修改":
					//					ReceiptModify();
					//					break;
				case "保存":
					//					if (ReceiptCheck()==false) {return ;}
					break;
				default:
 
					break;
			}
			//			grd_Detail.SetCellFocus(grd_Detail.Row,grd_Detail.Col+1);
		}
		//		/// <summary>
		//		/// 单据完整性验证
		//		/// </summary>
		//		public  bool ReceiptCheck() 
		//		{
		////			bool returnValue;
		////			string sCheckType;
		//			
		////			int j=ArrCell.GetUpperBound(0)+1;
		////			for (int i=0 ;i<j;i++)
		////			{
		////				if (i%2!=0)
		////				{
		////					newCellAttrib.FormatString =ArrCell[i].Tag.ToString();
		////					sCheckType=newCellAttrib.CheckType ; 
		////					returnValue=newReceipt.ReceiptCheck(ArrCell[i-1].Text.ToString(),ArrCell[i].Text.ToString(),sCheckType);
		////					if (returnValue==false)
		////					{return returnValue;}
		////				}
		////			}
		//			return false;
		//
		//		}

		
		private void mnu_InvoiceInf_Click(object sender, System.EventArgs e)
		{
			frmInputBox f=new frmInputBox();
			f.Prompt ="请输入发票类型：";
			f.Title ="设置发票类型";
			f.ShowDialog();
			string r=f.GetInputText();
			
		}

		private void menuItem1_Click(object sender, System.EventArgs e)
		{
			frmLookList f=new frmLookList();
			f.Title ="查看销售情况";
			f.SetShowListType="1";
			f.SetSQLSource="SELECT fcOperator  制单人, fdMakeDate 制单日期, fcSellNo 销售单号, fcCustomerCode 客户代码, fcContact 联系人, fcContactTel 联系电话, fcAddress, fcInvoiceType, fnTaxRate, FnTaxSum, fnSum, fnTotalSum FROM R_Sell" ;
			f.ShowDialog();
		}

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

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

		protected override void grd_Detail_Cell_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			base.grd_Detail_Cell_KeyPress(sender,e);

		}

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

		protected override void btnDown_Click(object sender, EventArgs e)
		{
//			int T=0;
//			this.newCellAttrib.FormatString =this.TxtTemp.Tag.ToString();
//			if (newCellAttrib.RefertoType=="") return;
//			T=int.Parse(newCellAttrib.RefertoType);
//			if (T>10)
//			{
//				JXC_MIS.UserTier.CommonForm.frmRefertoList ff=new JXC_MIS.UserTier.CommonForm.frmRefertoList();
////				JXC_MIS.UserTier.NewForm.frmItemStore ff=new JXC_MIS.UserTier.NewForm.frmItemStore();
//				ff.ShowDialog (this.Parent);
////				System.Data.DataTable dt =new System.Data.DataTable();
////				dt=ff.GetDataTable;
////				int rs=dt.Rows.Count;
////				int row=this.grd_Detail.Row;
////
////				this.grd_Detail.RowInsert("",this.grd_Detail.Row,rs);
////
////			
////				for (int r=0;r<rs;r++)
////				{
////					if (dt.Rows[r][1]!=null)
////					{
////						this.grd_Detail.SetCellText(row+r,1,dt.Rows[r][1].ToString());
////						this.grd_Detail.SetCellText(row+r,2,dt.Rows[r][2].ToString());
////						this.grd_Detail.SetCellText(row+r,7,dt.Rows[r][4].ToString());
////						this.grd_Detail.SetCellText(row+r,14,dt.Rows[r][10].ToString());
////					}
////
////				}
////				//添加行号
////				rs=this.grd_Detail.Rows;
////
////				for (int r=1;r<rs;r++)
////				{
////					this.grd_Detail.SetCellText(r,0,r.ToString());
////				}
//
//			}
//			else
//			{
				OtherFilter="";

			if (m_MouseEnterPlace=="Master")
			{
//				if (this.TxtTemp.TabIndex ==9) OtherFilter=this.TxtTemp.Text;
			}
			if (m_MouseEnterPlace=="Detail")
			{
				OtherFilter="";
				if (this.grd_Detail.Col ==23) OtherFilter="'"+ArrCell[9].Text+"','"+this.grd_Detail.GetCellText(this.grd_Detail.Row,1)+"'" ;
				if (this.grd_Detail.Col ==30) OtherFilter="'"+this.grd_Detail.GetCellText(this.grd_Detail.Row,5)+"'" ;
			
			}
				base.btnDown_Click (sender, e);

			


		}

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

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

			if (this.ArrCell[49].Text =="") 
			{
				MessageBox.Show("这张销售单还没有备货,不能核对！", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
				return;
			}
			if (this.ArrCell[51].Text!="") 
			{
				MessageBoxButtons buttons = MessageBoxButtons.YesNo;
//				DialogResult result;

				if (MessageBox.Show("这张销售单已经核对了,是否继续核对？", "提示", buttons , System.Windows.Forms.MessageBoxIcon.Information)==DialogResult.No )
				{
					return;
				}
			}

			frmInputBox f=new frmInputBox();
			f.Prompt ="请输入产品核对人：";
			f.Title ="产品核对";
			f.Default =GlobalData.Operator ;
			f.ShowDialog();
			string sName=f.GetInputText();
			if (sName!="")
			{
				newADO.BeginTrans(); //事务开始
				newADO.ExeSql("Update "+newR_Attrib.MasterTableName+" Set fcCheck='"+sName+"' Where "+newR_Attrib.KeyFieldName+"='"+CboReceiptNo.Text +"'"); 
				newADO.Commit();					  //事务提交

			this.ArrCell[51].Text =sName;
			}
		}

		private void mnu_UnManagecheck_Click(object sender, System.EventArgs e)
		{
			if (this.ArrCell[47].Text!="") 
			{
				MessageBoxButtons buttons = MessageBoxButtons.YesNo;
				if (MessageBox.Show("这张销售单已经审核了,是否注销审核？", "提示", buttons , System.Windows.Forms.MessageBoxIcon.Information)==DialogResult.No )
				{
					return;
				}
			}

				newADO.BeginTrans(); //事务开始
				newADO.ExeSql("Update "+newR_Attrib.MasterTableName+" Set fcManager='' Where "+newR_Attrib.KeyFieldName+"='"+CboReceiptNo.Text +"'"); 
				newADO.Commit();					  //事务提交

				this.ArrCell[47].Text ="";
		}

		private void tbr_Toolbar_ButtonClick_1(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
		
		}

		private void mnu_Managecheck_Click(object sender, System.EventArgs e)
		{
			if (this.ArrCell[47].Text=="") 
			{
				MessageBoxButtons buttons = MessageBoxButtons.YesNo;
				if (MessageBox.Show("这张销售单是否提请审核？", "提示", buttons , System.Windows.Forms.MessageBoxIcon.Information)==DialogResult.No )
				{
					return;
				}
			}
			else
			{
				if (this.ArrCell[47].Text!="待审核") 
				{
					MessageBox.Show("这张销售单已经审核完！", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
					return;
				}

			}

			newADO.BeginTrans(); //事务开始
			newADO.ExeSql("Update "+newR_Attrib.MasterTableName+" Set fcManager='待审核' Where "+newR_Attrib.KeyFieldName+"='"+CboReceiptNo.Text +"'"); 
			newADO.Commit();					  //事务提交

			this.ArrCell[47].Text ="待审核";
		}




		

	}
}

