//dll:System.dll
//dll:ZrProcessInterface.dll
//dll:ZrCHKFormBase.dll
//dll:System.Windows.Forms.dll

//2019年6月27日14:54:55 郑少宝 针对众安达的要求
using ZrCHKFormBase;
using System.Windows.Forms;

namespace CHK_CementCore
{
    public class TrustLoadingDone
    {
        /// <summary>
        /// LoadingDone
        /// </summary>
        public void LoadingDone(Control parnet, SaveTypeEnum saveType)
        {
            var dtpCheckDateStarts = parnet.Controls.Find("dtpCheckDateStart", false);
			var cmb养护方法s = parnet.Controls.Find("cmb养护方法", false);
			var txb龄期s = parnet.Controls.Find("txb龄期", false);
			var dtp成型日期s = parnet.Controls.Find("dtp成型日期", false);
			#if DEBUG
			System.Diagnostics.Debug.Assert(dtpCheckDateStarts.Length == 1, "没有预计试验日期控件");   
			System.Diagnostics.Debug.Assert(cmb养护方法s.Length == 1, "没有找到养护方法控件");     
			System.Diagnostics.Debug.Assert(dtp成型日期s.Length == 1, "没有找到成型日期控件");    
			System.Diagnostics.Debug.Assert(txb龄期s.Length == 1, "没有找到龄期控件");  
            #endif
            if (dtpCheckDateStarts != null && dtpCheckDateStarts.Length == 1 && (dtpCheckDateStarts[0] is System.Windows.Forms.DateTimePicker)
				&& cmb养护方法s != null && cmb养护方法s.Length == 1 && (cmb养护方法s[0] is System.Windows.Forms.ComboBox)
				&& txb龄期s != null && txb龄期s.Length == 1 && (txb龄期s[0] is System.Windows.Forms.TextBox)
				&& dtp成型日期s != null && dtp成型日期s.Length == 1 && (dtp成型日期s[0] is System.Windows.Forms.DateTimePicker))
            {
                System.Action calcAgeDay = () =>
                {
					if(cmb养护方法s[0].Text == "标准养护")
					{
						(dtpCheckDateStarts[0] as System.Windows.Forms.DateTimePicker).Value = (dtp成型日期s[0] as System.Windows.Forms.DateTimePicker).Value.AddDays(28);						
					}
					else
					{
						(dtpCheckDateStarts[0] as System.Windows.Forms.DateTimePicker).Value = System.DateTime.Now;	
					}
					 txb龄期s[0].Text = ((dtpCheckDateStarts[0] as System.Windows.Forms.DateTimePicker).Value.Date - (dtp成型日期s[0] as System.Windows.Forms.DateTimePicker).Value.Date).Days.ToString();
                };
                (cmb养护方法s[0] as System.Windows.Forms.ComboBox).SelectedIndexChanged += (s, e) => calcAgeDay();
                (dtp成型日期s[0] as System.Windows.Forms.DateTimePicker).ValueChanged += (s, e) => calcAgeDay();
				(dtpCheckDateStarts[0] as System.Windows.Forms.DateTimePicker).ValueChanged += (s, e) => txb龄期s[0].Text = ((dtpCheckDateStarts[0] as System.Windows.Forms.DateTimePicker).Value.Date - (dtp成型日期s[0] as System.Windows.Forms.DateTimePicker).Value.Date).Days.ToString();
				if(saveType == SaveTypeEnum.Insert)
				{
					calcAgeDay();					
				}
            }
            else
			{
				return;
            }
        }
    }
}
