Isdate

check for if is date if so continue
mail@pastecode.io avatar
unknown
csharp
2 years ago
6.7 kB
5
Indexable
Never
// **************************************************
// Custom code for VendorForm
// Created: 3/17/2022 3:39:43 PM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.UI;
using Ice.Lib;
using Ice.BO;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Ice.Lib.Broadcast;
using System.Reflection;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
	BAQDataView baqViewDateRange;
	Ice.Lib.Framework.EpiUltraGrid dateRangeGrid;
	public static bool IsDate(string tempDate)
	{ 
		DateTime fromDateValue; 
		var formats = new[] { "dd/MM/yyyy", "yyyy-MM-dd" }; 
		if (DateTime.TryParseExact(tempDate, formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out fromDateValue))
		{ 
			return true;
		} 
			else
		{ 
			return false;
		}
	}
	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls
		this.btnAddDates.Click += new System.EventHandler(this.btnAddDates_Click);
		this.ugInvRange.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.ugInvRange_InitializeLayout);
		this.txtVendorID.TextChanged += new System.EventHandler(this.txtVendorID_TextChanged);
		this.dtStartDate.TextChanged += new System.EventHandler(this.dtStartDate_TextChanged);
		this.dtEndDate.TextChanged += new System.EventHandler(this.dtEndDate_TextChanged);
		// End Wizard Added Custom Method Calls
		CreateDateRangeBAQView();
	}
	public void CreateDateRangeBAQView()
	{
			baqViewDateRange = new BAQDataView("JBIS-SupplierListQry"); 
			oTrans.Add("JBIS-SupplierListQry",baqViewDateRange);
			string pubBinding = "VendorDetail.VendorID";
			IPublisher pub = oTrans.GetPublisher(pubBinding);
			if(pub==null){
				oTrans.PublishColumnChange(pubBinding, "vendorNumPub");
				pub = oTrans.GetPublisher(pubBinding);
			}
			if(pub != null){
				baqViewDateRange.SubscribeToPublisher(pub.PublishName, "Vendor_VendorID"); 
			}
	}
	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal
		this.btnAddDates.Click -= new System.EventHandler(this.btnAddDates_Click);
		this.ugInvRange.InitializeLayout -= new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.ugInvRange_InitializeLayout);
		this.txtVendorID.TextChanged -= new System.EventHandler(this.txtVendorID_TextChanged);
		this.dtStartDate.TextChanged -= new System.EventHandler(this.dtStartDate_TextChanged);
		this.dtEndDate.TextChanged -= new System.EventHandler(this.dtEndDate_TextChanged);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}
	private void ClearBAQDataView(BAQDataView iBaqView)
	{
	    FieldInfo dqAdapter = iBaqView.GetType().GetField("dqAdapter", BindingFlags.Instance | BindingFlags.NonPublic);
	    Ice.Adapters.DynamicQueryAdapter dsQ = (Ice.Adapters.DynamicQueryAdapter)dqAdapter.GetValue(iBaqView);
	    dsQ.QueryResults.Clear();
	}
	private void btnAddDates_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		if (string.IsNullOrEmpty(txtVendorID.Text)) 
		{
			MessageBox.Show("please enter Vendor");
		} else 
		{
			DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
			dqa.BOConnect();
			QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("JBIS-SupInvLkUp");
			qeds.ExecutionParameter.Clear();
			qeds.ExecutionParameter.AddExecutionParameterRow("ConfirmSupplier", txtVendorID.Text, "nvarchar",false, Guid.NewGuid(),"A");
			qeds.ExecutionParameter.AddExecutionParameterRow("FromDate", dtStartDate.Text, "date",false, Guid.NewGuid(),"d");
			qeds.ExecutionParameter.AddExecutionParameterRow("ToDate", dtEndDate.Text, "date",false, Guid.NewGuid(),"d");
			dqa.ExecuteByID("JBIS-SupInvLkUp",qeds);
			ugInvRange.DataSource = dqa.QueryResults.Tables["Results"];
		}
	}
	
	private void ugInvRange_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs args)
	{
			// ** Place Event Handling Code Here **
				args.Layout.Bands[0].Columns[3].Format = "###,###,##0.00";
				args.Layout.Bands[0].Columns[4].Format = "###,###,##0.00";
				args.Layout.Bands[0].Columns[7].Format = "###,###,##0.00";
				args.Layout.Bands[0].Columns[10].Format = "###,###,##0.00";
				args.Layout.Bands[0].Columns[11].Format = "###,###,##0.00";
				args.Layout.Bands[0].Columns[12].Format = "###,###,##0.00";
				args.Layout.Bands[0].Columns[27].Format = "###,###,##0.00";
				args.Layout.Bands[0].Columns[40].Format = "###,###,##0.00";
				args.Layout.Bands[0].Columns[41].Format = "###,###,##0.00";
	}

	private void txtVendorID_TextChanged(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		if (string.IsNullOrEmpty(txtVendorID.Text)) 
		{
			ugInvRange.DataSource = null;
			dtStartDate.Text = "";
			dtEndDate.Text = "";
		}
	}

	private void dtStartDate_TextChanged(object sender, System.EventArgs args)
	{
		DateTime startDate = DateTime.Parse(dtStartDate.Text);
		string sD = startDate.ToString();
		if (IsDate(sD))
		{
			if(dtEndDate.Text != "" && dtEndDate.Text != null) 
			{
				DateTime endDate = DateTime.Parse(dtEndDate.Text);
				if(DateTime.Parse(dtStartDate.Text)>(DateTime.Parse(dtEndDate.Text)))
				{
					MessageBox.Show("Start date is greater than End date, please fix this before continuing");
					startDate = endDate.AddDays(-1);
					dtStartDate.Text = sD;
				}
			}
		}
	}

	private void dtEndDate_TextChanged(object sender, System.EventArgs args)
	{
		DateTime endDate = DateTime.Parse(dtEndDate.Text);
		string eD = endDate.ToString();
		if (IsDate(eD))
		{
			if(dtStartDate.Text != "" && dtStartDate.Text != null)
			{
				DateTime startDate = DateTime.Parse(dtStartDate.Text);
				if(DateTime.Parse(dtEndDate.Text)<(DateTime.Parse(dtStartDate.Text)))
				{
					MessageBox.Show("End date is less than Start date, please fix this before continuing");
					endDate = startDate.AddDays(1);
					dtEndDate.Text = eD;
				}
			}
		}
	}
}