//dll:System.dll
//dll:System.Core.dll
//dll:ZrProcessInterface.dll
//dll:ZrCHKFormBase.dll
//dll:System.Windows.Forms.dll
//dll:ZR.DragControl.dll

//2020年4月24日17:45:51 厦门交通
//预计试验日期=委托日期+第一个龄期
using ZrCHKFormBase;
using System.Windows.Forms;
using System.Collections.Generic;

namespace CHK_Currency	
{
	
    public class TrustLoadingDone
    {
		
		
        /// <summary>
        /// LoadingDone
        /// </summary>
        public void LoadingDone(Control parnet, SaveTypeEnum saveType)
        {
			System.Func<string,int> toInt = (s) =>
			{
				int x;
				if (int.TryParse(s, out x))
				{
					return x;
				}
				return 0;
			};
			var zrcode = (parnet as ZrCHKFormBase.CHKFormBase).ZrCode;
			if(zrcode!="ZRT00002"||zrcode!="ZRT00001")
				return;
                        var dtpCheckDateStarts = parnet.Controls.Find("dtpCheckDateStart", false);
			var dtpTrustDates = parnet.Parent.Controls.Find("dtpTrustDate", true);
			var txbFlows = parnet.Parent.Controls.Find("txbFlows", true);
			#if DEBUG
			System.Diagnostics.Debug.Assert(dtpCheckDateStarts.Length == 1, "没有预计试验日期控件");     			
			System.Diagnostics.Debug.Assert(dtpTrustDates.Length == 1, "没有找到委托日期控件");    
                        System.Diagnostics.Debug.Assert(txbFlows.Length == 1, "没有找到检测流程控件");  
                        #endif
			if (dtpCheckDateStarts != null && dtpCheckDateStarts.Length == 1 && (dtpCheckDateStarts[0] is System.Windows.Forms.DateTimePicker)
				&& txbFlows!= null && txbFlows.Length == 1 && (txbFlows[0] is System.Windows.Forms.TextBox)
				&& dtpTrustDates != null && dtpTrustDates.Length == 1 && (dtpTrustDates[0] is System.Windows.Forms.DateTimePicker))	
			{
				System.Action calcShiyan = () =>
                               {	
				    var Days=txbFlows[0].Text.ToString();
					string day = "0";
					if(txbFlows[0].Text.Length > 0)
					{
						var temp = Days.Split('、')[0];
						day = temp.Replace("d","");
					}

						(dtpCheckDateStarts[0] as System.Windows.Forms.DateTimePicker).Value=(dtpTrustDates[0] as  System.Windows.Forms.DateTimePicker).Value.AddDays(toInt(day));
                };
				(dtpTrustDates[0] as System.Windows.Forms.DateTimePicker).ValueChanged += (s, e) => calcShiyan();
				(txbFlows[0] as System.Windows.Forms.TextBox).TextChanged += (s, e) =>calcShiyan();
				if(saveType == SaveTypeEnum.Insert)
				{
					calcShiyan();
				}
			}
        }
    }
}






