where am i fucking up

mail@pastecode.io avatar
unknown
csharp
2 years ago
8.1 kB
1
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.dtEndDate.AfterExitEditMode += new System.EventHandler(this.dtEndDate_AfterExitEditMode);
		this.dtStartDate.AfterExitEditMode += new System.EventHandler(this.dtStartDate_AfterExitEditMode);
		// 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);
		this.dtEndDate.AfterExitEditMode -= new System.EventHandler(this.dtEndDate_AfterExitEditMode);
		this.dtStartDate.AfterExitEditMode -= new System.EventHandler(this.dtStartDate_AfterExitEditMode);
		// 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_AfterExitEditMode(object sender, System.EventArgs args)
	{
		if (IsDate(dtEndDate.Text))
		{
			MessageBox.Show("about to parse datetime to startdate");
			DateTime? endDate = DateTime.Parse(dtEndDate.Text);
			MessageBox.Show("parsed datetime to enddate");
			DateTime? startDate = DateTime.Parse(dtStartDate.Text);
			MessageBox.Show("parsed datetime to startDate");
			string eD = endDate.ToString();
			MessageBox.Show("sent string to ED");
			string sD = startDate.ToString();
			MessageBox.Show("sent string to SD");
			// ** Place Event Handling Code Here **
	
				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.Value.AddDays(-1);
					string startDatePlusOne = startDate.ToString();
					dtStartDate.Text = startDatePlusOne;
					MessageBox.Show("passed startdateDateplusOne to strartdate");
				}
		}
		else 
		{
			MessageBox.Show(dtEndDate.Text);
			MessageBox.Show("please enter an end date date");
		}
	}
	private void dtEndDate_AfterExitEditMode(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		if (IsDate(dtEndDate.Text))
		{
			MessageBox.Show(dtEndDate.Text);
			MessageBox.Show("about to parse datetime to enddate");
			DateTime? endDate = DateTime.Parse(dtEndDate.Text);
			MessageBox.Show("parsed datetime to enddate");
			DateTime? startDate= DateTime.Parse(dtStartDate.Text);
			MessageBox.Show("parsed datetime to startDate");
			string eD = endDate.ToString();
			MessageBox.Show("sent string to ED");
			string sD = startDate.ToString();
			MessageBox.Show("sent string to SD");
			//if (IsDate(sD))	
			//MessageBox.Show("isdate is true");
			//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.Value.AddDays(1);
				string endDatePlusOne = endDate.ToString();
				dtEndDate.Text = endDatePlusOne;
				MessageBox.Show("passed endDateplusOne to enddate");
			}	
		}
		else 
		{
			MessageBox.Show(dtEndDate.Text);
			MessageBox.Show("please enter an end date date");
		}
	}
}