using System;
using System.Windows.Forms;
using System.IO; 
using JXC_MIS.DataTier ;
namespace JXC_MIS.MyClass
{
	/// <summary>
	/// ClsInitData 初始数据类。
	/// </summary>
	public class ClsInitData
	{
		private static string driveLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
		ClsDataBaseAccess newADO=new ClsDataBaseAccess();
		public ClsInitData()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		/// <summary>
		/// 将界面中指定网格单元格对象添加到控件数组中。
		/// </summary>
		private TextBox[] AddToArray(ljs.MyGrid p_Grid)
		{
			 TextBox[] ArrCell=null;
			int rows;
			int cols;
			int p_Index=0;
			rows=p_Grid.Rows ;
			cols=p_Grid.Cols;
			ArrCell=new TextBox[rows*cols];
			for (int r=0;r<rows;r++)
			{
				for (int c=0;c<cols;c++)
				{
					//将单元格对象添加到控件数组中
					ArrCell[p_Index]=p_Grid.GridCell(r,c);
					p_Index++;
				}
			}
			return ArrCell;
		}

		

		/// <summary>
		///  设置打开的数据源绑定到MYGRID网格输入的单元格中
		/// </summary>
		public void RecordToGrid(ljs.MyGrid p_MyGrid,string p_SQL) 
		{
			if (p_SQL!="")
			{
				TextBox[] ArrCell=AddToArray(p_MyGrid);
				int IdxCount=0;
				JXC_MIS.DataTier.ClsDataBaseAccess newADO=new JXC_MIS.DataTier.ClsDataBaseAccess();

				System.Data.DataSet dst = new System.Data.DataSet();
				dst= newADO.GetDataSet(p_SQL);
				int rs=dst.Tables[0].Rows.Count ;
				if (rs>0)
				{
					System.Data.DataRow dr =dst.Tables[0].Rows[0];
					int j=ArrCell.GetUpperBound(0)+1;
					for (int r=0;r<j;r++)
					{
						if (r%2!=0)
						{
							ArrCell[r].Text =dr[IdxCount].ToString();
							IdxCount++;
						}
					}
				}
			}
		}

		/// <summary>
		/// 打开数据记录加入到网格（MyFlexGrid）中(带标题、行号)
		/// </summary>

		public void ShowGridData(ljs.MyFlexGrid FlexGrid,string p_SQL)
		{
			if (p_SQL=="") return;
			try
			{
				System.Data.DataSet dst = new System.Data.DataSet();
				dst=newADO.GetDataSet(p_SQL);
				int rs=dst.Tables[0].Rows.Count+1 ;
				int cs=dst.Tables[0].Columns.Count+1  ;
				string sCaption="№";
				FlexGrid.Rows =rs+1;
				FlexGrid.Cols=cs;
				for (int i=1;i<cs;i++)
				{
					//				FlexGrid.SetCellText(0,i,dst.Tables[0].Columns[i-1].Caption);
					sCaption=sCaption+"|"+dst.Tables[0].Columns[i-1].Caption;
				}
				FlexGrid.FormatString=sCaption;
				FlexGrid.FormatString1=sCaption;
				if (rs>0)
				{
					System.Data.DataRow dr =null;
					for (int r=1;r<rs;r++)
					{
						dr = dst.Tables[0].Rows[r-1];
						FlexGrid.SetCellText(r,0,r.ToString());
						for (int c=1;c<cs;c++)
						{
							FlexGrid.SetCellText(r,c,dr[c-1].ToString());
						}
					}
				
				}
			}
			catch(System.Exception ex)
			{
				System.Windows.Forms.MessageBox.Show(ex.Message,"提示",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Warning);
			}

		}

//		private void InitDataGrid()
//		{
//			DataTable dt =new DataTable();
//			int intRowIndex;
//			int intColIndex;
//			for (intRowIndex=0;intRowIndex<9;intRowIndex++)
//			{
//				dt.Rows.Add(dt.NewRow());
//				dt.Columns.Add();
//			}	
//
//			for (intRowIndex=0;intRowIndex<9;intRowIndex++)
//			{				
//				for (intColIndex=0;intColIndex<9;intColIndex++)
//				{
//					dt.Rows[intRowIndex][intColIndex]=intRowIndex.ToString()+"行"+intColIndex.ToString()+"列";
//				}
//			}	
//
//			
//			this.dataGrid1.DataSource=dt;
//		}

		public void InitListBox(System.Windows.Forms.ListBox  p_ListBox,string[,] p_Arrary)
		{
			if (p_Arrary ==null){return;}

			int rs=p_Arrary.GetUpperBound(0)+1;
			int cs=p_Arrary.GetUpperBound(1)+1;
			try
			{
				p_ListBox.Items.Clear();
				for (int r=0;r<rs;r++)
				{
					if (p_Arrary[r,0]==null && p_Arrary[r,0]==""){} 
					else { p_ListBox.Items.Add( p_Arrary[r,0]);}
				}
				p_Arrary=null;
			}
			catch
			{
				return;
			}
			
		}
		public void InitComboBox(System.Windows.Forms.ComboBox p_ComboBox,string[,] p_Arrary)
		{
			if (p_Arrary ==null){return;}

			int rs=p_Arrary.GetUpperBound(0)+1;
			int cs=p_Arrary.GetUpperBound(1)+1;
			try
			{
				p_ComboBox.Items.Clear();
				for (int r=0;r<rs;r++)
				{
					if (p_Arrary[r,1]==null && p_Arrary[r,1]==""){} 
					else { p_ComboBox.Items.Add( p_Arrary[r,1]);}
				}
				p_Arrary=null;
			}
			catch
			{
				return;
			}
			
		}
		public void InitComboBox(System.Windows.Forms.ComboBox p_ComboBox,string[] p_Arrary)
		{
			if (p_Arrary ==null){return;}

			int cs=p_Arrary.Length ;
			try
			{
				p_ComboBox.Items.Clear();

				for (int r=0;r<cs;r++)
				{
					if (p_Arrary[r]==null && p_Arrary[r]==""){} 
					else { p_ComboBox.Items.Add( p_Arrary[r]);}
				}
				p_Arrary=null;
			}
			catch
			{
				return;
			}
			
		}
		public void InitComboBox(System.Windows.Forms.ComboBox p_ComboBox,string p_SQL)
		{
			JXC_MIS.DataTier.ClsDataBaseAccess newADO=new JXC_MIS.DataTier.ClsDataBaseAccess();

			System.Data.DataSet dst = new System.Data.DataSet();
			dst=newADO.GetDataSet(p_SQL);
			int rs=dst.Tables[0].Rows.Count ;
			p_ComboBox.Items.Add("<全部>");
			if (rs>0)
			{
				try
				{
					System.Data.DataRow dr =null;
					p_ComboBox.Items.Clear();

					for (int r=0;r<rs;r++)
					{
						 dr = dst.Tables[0].Rows[r];
						 p_ComboBox.Items.Add(dr[0].ToString());
					}
					p_ComboBox.SelectionStart=0;
				}
				catch
				{
					return;
				}
			}
			
		}
		public void InitListView(System.Windows.Forms.ListView p_ListView,string[,] p_Arrary)
		{
			if (p_Arrary ==null){return;}

			int rs=p_Arrary.GetUpperBound(0)+1;
			int cs=p_Arrary.GetUpperBound(1)+1;
			string[] lv=new String[cs];

				p_ListView.Clear() ;
		
			try
			{
				// 第零行数组是设置标题
				for (int i=0;i<cs;i++)
				{
					p_ListView.Columns.Add(p_Arrary[0,i],p_Arrary[0,i].Length*20, HorizontalAlignment.Left);

				}
				
				// 从第一行数组开始加载数据
				for (int r=1;r<rs;r++)
				{
					for (int c=0;c<cs;c++)
					{
						lv[c]=p_Arrary[r,c] ;
					}
					p_ListView.Items.Add (new ListViewItem(lv,0));
				}
					p_Arrary=null;
					lv=null;
			}
			catch
			{
				return;
			}
		}
//重载
		public void InitListView(System.Windows.Forms.ListView p_ListView,string[,] p_Arrary,string p_Columns)
		{
			if (p_Arrary ==null){return;}
			int rs=p_Arrary.GetUpperBound(0)+1;
			int cs=p_Arrary.GetUpperBound(1)+1;
			string[] lv=new String[cs];

			p_ListView.Clear() ;
		
			try
			{
				string [] ArrSplit = null; //     临时数组变量
                ArrSplit=p_Columns.Split(',');

				// 设置标题
				for (int i=0;i<ArrSplit.Length;i++)
				{
					p_ListView.Columns.Add(ArrSplit[i],ArrSplit[i].Length*20, HorizontalAlignment.Left);

				}
				
				// 从第一行数组开始加载数据
				for (int r=0;r<rs;r++)
				{
					for (int c=0;c<cs;c++)
					{
						lv[c]=p_Arrary[r,c] ;
					}
					p_ListView.Items.Add (new ListViewItem(lv,0));
				}
				p_Arrary=null;
				lv=null;
			}
			catch
			{
				return;
			}
		}
		public void InitTreeView(System.Windows.Forms.TreeView p_TreeView,string p_SQL)
		{
			InitTreeView(p_TreeView,p_SQL,"<全部>");
		}
		public void InitTreeView(System.Windows.Forms.TreeView p_TreeView,string p_SQL,string p_RootName)
		{
			JXC_MIS.DataTier.ClsDataBaseAccess newADO=new JXC_MIS.DataTier.ClsDataBaseAccess();
			System.Data.DataSet dst = new System.Data.DataSet();
			dst=newADO.GetDataSet(p_SQL);
			int rs=dst.Tables[0].Rows.Count ;
			p_TreeView.Nodes.Clear() ;

			TreeNode tnRoot = new TreeNode();
//			TreeNode tnParent1 = new TreeNode();
			TreeNode tn = new TreeNode(p_RootName);
			p_TreeView.Nodes.Add(tn);
			tnRoot=tn;
			tnRoot.Expand();
			if (rs>0)
			{
				try
				{
					System.Data.DataRow dr =null;
					for (int r=0;r<rs;r++)
					{
						dr = dst.Tables[0].Rows[r];
						TreeNode tnParent1 = new TreeNode(dr[0].ToString());
						tnRoot.Nodes.Add(tnParent1);
//						tnRoot=tnParent1;
						tnRoot.Expand();

					}
				}
				catch
				{
					return;
				}
			}


		}

		public void InitTreeView(System.Windows.Forms.TreeView p_TreeView,string[,] p_Arrary)
		{
			//加载
			//			p_Arrary[i,0]  代码
			//			p_Arrary[i,1]  名称
			//			p_Arrary[i,2]  级别标志
			p_TreeView.Nodes.Clear() ;
			TreeNode tnRoot = new TreeNode();
			TreeNode tnParent1 = new TreeNode();
			TreeNode tnParent2 = new TreeNode();
			TreeNode tnParent3 = new TreeNode();
			TreeNode tnParent4 = new TreeNode();
			TreeNode tnParent5 = new TreeNode();
			TreeNode tnParent6 = new TreeNode();
        try
		{
			for (int i = 0 ; i < p_Arrary.GetUpperBound(0)+1  ; i++ )
			{
				if (p_Arrary[i,1]=="" || p_Arrary[i,1]==null)
				{
				}
				else
				{
					TreeNode tn = new TreeNode(p_Arrary[i,1]);
					tn.Tag = p_Arrary[i,0];
					switch (p_Arrary[i,2])
					{
						case "0":
							p_TreeView.Nodes.Add(tn);
							tnRoot=tn;
							tnRoot.Expand();
							break;

						case "1":
							tnRoot.Nodes.Add(tn);
							tnParent1=tn;
							tnParent1.Expand();
							break;

						case "2":
							tnParent1.Nodes.Add(tn);
							tnParent2=tn;
							tnParent2.Expand();
							break;

						case "3":
							tnParent2.Nodes.Add(tn);
							tnParent3=tn;
							tnParent3.Expand();
							break;

						case "4":
							tnParent3.Nodes.Add(tn);
							tnParent4=tn;
							tnParent4.Expand();
							break;
						case "5":
							tnParent4.Nodes.Add(tn);
							tnParent5=tn;
							break;

						case "6":
							tnParent5.Nodes.Add(tn);
							tnParent6=tn;
							break;
						default:
							tnRoot.Nodes.Add(tn);
							tnParent1=tn;
							break;
					}
				}
			}
			tnRoot.Expand();

			p_Arrary=null;
		}
		catch
			{
				return;
			}
		}

       // 初始驱动目录
		public void InitDriveTree(System.Windows.Forms.TreeView p_TreeView)
		{
			DirectoryInfo directory;
			string sCurPath = ""; // 重新清空
			p_TreeView.Nodes.Clear();

			// 将硬盘上的所有的驱动器都列举出来
			foreach( char c in driveLetters )
			{
				sCurPath = c + ":\\";
				try 
				{
					// 获得该路径的目录信息
					directory = new DirectoryInfo(sCurPath);

					// 如果获得的目录信息正确，则将它添加到目录树视中
					if ( directory.Exists == true )
					{
						TreeNode newNode = new TreeNode(directory.FullName);
						p_TreeView.Nodes.Add(newNode); // 添加新的节点到根节点
						getSubDirs(newNode);
						// 调用getSubDirs（）函数，检查该驱动器上的任何存在子目录
					}
				}
				catch( Exception doh)
				{
					Console.WriteLine(doh.Message);
				}
			}
		}

		private void getSubDirs( TreeNode parent )
		{
			DirectoryInfo directory;
			try
			{
				// 如果还没有检查过这个文件夹，则检查之
				if ( parent.Nodes.Count == 0 )
				{
					directory = new DirectoryInfo(parent.FullPath);
					foreach( DirectoryInfo dir in directory.GetDirectories())
					{
						// 新建一个数节点，并添加到目录树视
						TreeNode newNode = new TreeNode(dir.Name);
						parent.Nodes.Add(newNode);
					}
				}

				foreach(TreeNode node in parent.Nodes)
				{
					// 如果还没有检查过这个文件夹，则检查
					if (node.Nodes.Count == 0)
					{
						directory = new DirectoryInfo(node.FullPath);

						// 检查该目录上的任何子目录
						foreach( DirectoryInfo dir in directory.GetDirectories())
						{
							// 新建一个数节点，并添加到目录树视
							TreeNode newNode = new TreeNode(dir.Name);
							node.Nodes.Add(newNode);
						}
					}
				}
			}
			catch( Exception doh )
			{
				Console.WriteLine(doh.Message);
			}
		}

		private string fixPath( TreeNode node )
		{
			string sRet = "";
			try
			{
				sRet = node.FullPath;
				int index = sRet.IndexOf("\\\\");
				if (index > 1 )
				{
					sRet = node.FullPath.Remove(index, 1);
				}
			}
			catch( Exception doh )
			{
				Console.WriteLine(doh.Message);
			}
			return sRet;
		}
		public object  LoadForm(string p_FormName)
		{
//			string strFormName = "frmSell";

			Type type = Type.GetType(p_FormName);
//				"JXC_MIS.UserTier.NewForm." +
			System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(type);

			object frmNew = assembly.CreateInstance(type.ToString());
//			Form frmNew = assembly.CreateInstance(type.ToString());
//			type.InvokeMember("Show",System.Reflection.BindingFlags.InvokeMethod,null,frmNew,null);
			return frmNew;

			//				Type type = Type.GetType(" strFormName);//JXC_MIS.UserTier.NewForm.frmSell" +
			//				
			//				System.Reflection.Assembly assembly = Assembly.GetAssembly(type);
			//
			//				object frmNew = assembly.CreateInstance(type.ToString());
			//
			//				type.InvokeMember("Show",System.Reflection.BindingFlags.InvokeMethod,null,frmNew,null);
			//				System.Reflection.Assembly MyAssembly = Assembly.GetExecutingAssembly();
			//				
			//				//System.Reflection.Module[] modules=  MyAssembly.GetModules();
			//
			//				System.Type[] typs =  MyAssembly.GetTypes();


		}


//		'－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－
//		'－－－－－ 计算移动加权平均成本单价－－－－－－－－
//－－－－－－0序号,1日期,  2单号,3摘要,4入库数量,5入库单价, 6入库金额,7出库数量,8出库单价,9出库金额,10库存数量,11成本单价,12成本金额－－－－－－－－－－－－－－－－－－－－－
		public double GetAvgPrice(string p_GBCode, string p_InLibDate)
		{
//			string [,] sArray=GetDataArray("up_ljsInOutLibDeitail","");
			double rkNum=0;
			double rkPrice=0;
			double rkSum=0;
			double ckNum=0;
			double ckPrice=0;
			double ckSum=0;
			double kcNum=0;
			double kcPrice=0;
			double kcSum=0;
			double AvgPrice=0;

			System.Data.DataSet dst = new System.Data.DataSet();
			dst=newADO.GetDataSet("up_ljsInOutLibDeitail");
			int rs=dst.Tables[0].Rows.Count+2 ;
			int cs=dst.Tables[0].Columns.Count+4  ;
			string [,] sArray=new string[rs,cs];
			for (int i=0;i<cs;i++)
			{
				sArray[0,i]=dst.Tables[0].Columns[i].Caption;
			}
			if (rs>0)
			{
				System.Data.DataRow dr =null;
				for (int r=1;r<rs;r++)
				{
					dr = dst.Tables[0].Rows[r-1];
					sArray[r,0]=r.ToString();
					for (int c=0;c<cs-3;c++)
					{
						
						sArray[r,c]=dr[c].ToString();
						rkNum=double.Parse(sArray[r,4]);
						rkPrice=double.Parse(sArray[r,5]);
						rkSum=double.Parse(sArray[r,6]);
						ckNum=double.Parse(sArray[r,7]);
						ckPrice=double.Parse(sArray[r,8]);
						ckSum=double.Parse(sArray[r,9]);

						if (r==1)
						{
							kcNum=rkNum-ckNum;
							kcPrice=rkPrice;
							kcSum=rkSum;
						
						}
						else  //平均成本单价=入库数量＊入库单价+期初库存数量＊入库单价/(入库数量+期初库存数量)
						{
								kcNum=double.Parse(sArray[r,4])+double.Parse(sArray[r-1,10])-double.Parse(sArray[r,7]);

								if (rkNum==0)
								{
									kcPrice=double.Parse(sArray[r-1,11]);
								}
								else
								{
									kcPrice=(rkSum+double.Parse(sArray[r-1,12]))/kcNum;
								}
								kcSum=kcNum*kcPrice;

						}
							sArray[r,10]=kcNum.ToString();
							sArray[r,11]=kcPrice.ToString();
							sArray[r,12]=kcSum.ToString();


					}
				}
				
				return AvgPrice;
			}
			else
			{
				return AvgPrice;
			}
		
		
//		  Set rstAccountBook = OpenRst(sSql)
//  If rstAccountBook.BOF And rstAccountBook.EOF Then
//         GetAvgPrice = 0
//          rstAccountBook.Close
//         Exit Function
//    Else
//        j = OrderSum(rstAccountBook)
//        ReDim MatrixTable(j + 1, 14)
//         rstAccountBook.MoveFirst
//            For k = 0 To j - 1
//                    MatrixTable(k, 0) = k + 1
//                    MatrixTable(k, 1) = FieldVal(rstAccountBook, "日期") 'Format(FieldVal(rstAccountBook, "日期"), "dddddd")
//                    MatrixTable(k, 2) = FieldVal(rstAccountBook, "单号")
//                    MatrixTable(k, 3) = FieldVal(rstAccountBook, "摘要")
//                    MatrixTable(k, 4) = FieldVal(rstAccountBook, "批号")
//                    MatrixTable(k, 5) = IIf(FieldVal(rstAccountBook, "入库数量") = "0", "", FieldVal(rstAccountBook, "入库数量"))
//                    MatrixTable(k, 6) = IIf(FieldVal(rstAccountBook, "入库单价") = "0", "", Format(FieldVal(rstAccountBook, "入库单价"), PriceFormat))
//                    MatrixTable(k, 7) = Format(NewCDbl(MatrixTable(k, 5)) * NewCDbl(MatrixTable(k, 6)), MoneyFormat)
//                      If NewCDbl(MatrixTable(k, 7)) = 0 Then MatrixTable(k, 7) = ""
//                    MatrixTable(k, 8) = IIf(FieldVal(rstAccountBook, "出库数量") = "0", "", FieldVal(rstAccountBook, "出库数量"))
//                    MatrixTable(k, 9) = IIf(FieldVal(rstAccountBook, "出库单价") = "0", "", Format(FieldVal(rstAccountBook, "出库单价"), PriceFormat))
//                    MatrixTable(k, 10) = Format(NewCDbl(MatrixTable(k, 9)) * NewCDbl(MatrixTable(k, 8)), MoneyFormat)
//                      If NewCDbl(MatrixTable(k, 10)) = 0 Then MatrixTable(k, 10) = ""
//                     
//                     If k = 0 Then
//                        MatrixTable(k, 11) = NewCDbl(MatrixTable(k, 5)) - NewCDbl(MatrixTable(k, 8))
//                        MatrixTable(k, 12) = IIf(MatrixTable(k, 6) = "", MatrixTable(1, 6), MatrixTable(k, 6))
//                     Else
//                        MatrixTable(k, 11) = RTrim(NewCDbl(MatrixTable(k - 1, 11)) + NewCDbl(MatrixTable(k, 5)) - NewCDbl(MatrixTable(k, 8)))
//                         If NewCDbl(MatrixTable(k, 7)) = 0 Then
//                          MatrixTable(k, 12) = MatrixTable(k - 1, 12)
//                         Else
//                         If NewCDbl(MatrixTable(k, 11)) = 0 Then
//                              MatrixTable(k, 12) = MatrixTable(k, 6)
//                            Else
//                             MatrixTable(k, 12) = Format((NewCDbl(MatrixTable(k - 1, 13)) + NewCDbl(MatrixTable(k, 7))) / NewCDbl(MatrixTable(k, 11)), PriceFormat)
//                          End If
//                         End If
//                     End If
//                        MatrixTable(k, 13) = Format(NewCDbl(MatrixTable(k, 11)) * NewCDbl(MatrixTable(k, 12)), MoneyFormat)
//                        '算合计
//                        MatrixTable(j, 5) = NewCDbl(MatrixTable(j, 5)) + NewCDbl(MatrixTable(k, 5))
//                        MatrixTable(j, 7) = NewCDbl(MatrixTable(j, 7)) + NewCDbl(MatrixTable(k, 7))
//                        MatrixTable(j, 8) = NewCDbl(MatrixTable(j, 8)) + NewCDbl(MatrixTable(k, 8))
//                        MatrixTable(j, 10) = NewCDbl(MatrixTable(j, 10)) + NewCDbl(MatrixTable(k, 10))
//                        MatrixTable(j, 11) = RTrim(NewCDbl(MatrixTable(j, 5)) - NewCDbl(MatrixTable(j, 8)))
//                        MatrixTable(j, 13) = MatrixTable(j - 1, 13)
//                        rstAccountBook.MoveNext
//            Next
//  End If
//       If rstAccountBook.State = adStateOpen Then
//            rstAccountBook.Close
//        End If
//    GetAvgPrice = Format(NewCDbl(MatrixTable(j - 1, 12)), PriceFormat)

		
		
		
		}

//
//		//		'－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－
//		//		'－－－－－ 计算移动加权平均成本单价－－－－－－－－
//		//－－－－－－0序号,1日期,  2单号,3摘要,4入库数量,5入库单价, 6入库金额,7出库数量,8出库单价,9出库金额,10库存数量,11成本单价,12成本金额－－－－－－－－－－－－－－－－－－－－－
//		private void GetAvgPrice(ljs.MyFlexGrid FlexGrid,string p_GBCode, string p_InLibDate)
//		{
//			//			string [,] sArray=GetDataArray("up_ljsInOutLibDeitail","");
//			double rkNum=0;
//			double rkPrice=0;
//			double rkSum=0;
//			double ckNum=0;
//			double ckPrice=0;
//			double ckSum=0;
//			double kcNum=0;
//			double kcPrice=0;
//			double kcSum=0;
//			double AvgPrice=0;
//			ShowGridData(FlexGrid,"up_ljsInOutLibDeitail");
//			//			System.Data.DataSet dst = new System.Data.DataSet();
//			//			dst=newADO.GetDataSet("up_ljsInOutLibDeitail");
//			int rs=FlexGrid.Rows ;//dst.Tables[0].Rows.Count+2 ;
//			int cs=FlexGrid.Cols;//dst.Tables[0].Columns.Count+4  ;
//			if (rs>0)
//			{
//				System.Data.DataRow dr =null;
//				for (int r=1;r<rs;r++)
//				{
//					for (int c=0;c<cs-3;c++)
//					{
//						rkNum=double.Parse(FlexGrid.GetCellText(r,4));
//						rkPrice=double.Parse(FlexGrid.GetCellText(r,5));
//						rkSum=double.Parse(FlexGrid.GetCellText(r,6));
//						ckNum=double.Parse(FlexGrid.GetCellText(r,7));
//						ckPrice=double.Parse(FlexGrid.GetCellText(r,8));
//						ckSum=double.Parse(FlexGrid.GetCellText(r,9));
//
//						if (r==1)
//						{
//							kcNum=rkNum-ckNum;
//							kcPrice=rkPrice;
//							kcSum=rkSum;
//						
//						}
//						else  //平均成本单价=入库数量＊入库单价+期初库存数量＊入库单价/(入库数量+期初库存数量)
//						{
//							kcNum=double.Parse(FlexGrid.GetCellText(r,4))+double.Parse(FlexGrid.GetCellText(r-1,10))-double.Parse(FlexGrid.GetCellText(r,7));
//
//							if (rkNum==0)
//							{
//								kcPrice=double.Parse(FlexGrid.GetCellText(r-1,11));
//							}
//							else
//							{
//								kcPrice=(rkSum+double.Parse(FlexGrid.GetCellText(r-1,12)))/kcNum;
//							}
//							kcSum=kcNum*kcPrice;
//
//						}
//						FlexGrid.SetCellText(r,10,kcNum.ToString());
//						FlexGrid.SetCellText(r,11,kcPrice.ToString());
//						FlexGrid.SetCellText(r,12,kcSum.ToString());
//
//
//					}
//				}
//				
//			}
//			else
//			{
//			}
//		
//		}





	}
}
