Untitled

 avatar
unknown
plain_text
3 years ago
9.1 kB
4
Indexable
// **************************************************
// 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;
	private EpiTextBox venID;
	private EpiTextBox venID1;
	string venOld;
	string venNew;
	EpiButton btnVenID;
	public static bool IsDateMin(string input)
	{
		DateTime temp;
		return DateTime.TryParse(input, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out temp) &&
	      temp.Hour == 0 &&
	      temp.Minute == 0 &&
	      temp.Second == 0 &&
	      temp.Millisecond == 0 &&
	      temp > DateTime.MinValue;
	}
	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this.baseToolbarsManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClick);
		// 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.dtStartDate.AfterExitEditMode += new System.EventHandler(this.dtStartDate_AfterExitEditMode);
		this.dtEndDate.AfterExitEditMode += new System.EventHandler(this.dtEndDate_AfterExitEditMode);
		venID = (EpiTextBox)csm.GetNativeControlReference("4ce376bb-225b-4b04-ac18-0c6bdc69820b");
		venOld = venID.Text;
		MessageBox.Show("initiailze storing venID", venID.Text.ToString());
		venNew = "";
		EpiButton btnVenID = (EpiButton)csm.GetNativeControlReference("fd5cdf41-9d75-4e56-aeb3-b305e2cafd6d");
		btnVenID.Click += new EventHandler(btnVenID_Click);
		// End Wizard Added Custom Method Calls
		
	}
	private void btnVenID_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		MessageBox.Show("btnclick");
		if (venID1 == null )
		{
			MessageBox.Show("btn clicked venid1 is equal to null saving ven id1 this is what we are storing:",venID.Text.ToString());
		}
		if (venID != null)
		{
			//MessageBox.Show(venID.Text.ToString());
			//MessageBox.Show(venOld);
			if (String.Equals(venOld, venNew))
			{	
				//MessageBox.Show("venid1 and venid are equal venID1:", venID1.Text.ToString());
				MessageBox.Show("venID:", venID.Text.ToString());
				MessageBox.Show("those should have been the same ");
				
			} else {
				//MessageBox.Show(venNew);
				MessageBox.Show(venOld);
				//MessageBox.Show("venid1 is NOT null here is what it is:", venID1.Text.ToString());
				MessageBox.Show("venid1 is NOT null here is venID:", venID.Text.ToString());
				MessageBox.Show("they shouldnt be the same");
				ugInvRange.DataSource = null;
				dtStartDate.Text = "12/31/2021";
				dtEndDate.Text = "12/31/2021";
				venID1 = (EpiTextBox)csm.GetNativeControlReference("4ce376bb-225b-4b04-ac18-0c6bdc69820b");
				venNew = venID1.Text;
			}
		}
	}


	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal
		//this.btnVenID.Click -= new System.EventHandler(this.btnVenID_Click);
		this.btnAddDates.Click -= new System.EventHandler(this.btnAddDates_Click);
		this.ugInvRange.InitializeLayout -= new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.ugInvRange_InitializeLayout);
		this.dtEndDate.AfterExitEditMode -= new System.EventHandler(this.dtEndDate_AfterExitEditMode);
		this.dtStartDate.AfterExitEditMode -= new System.EventHandler(this.dtStartDate_AfterExitEditMode);
		venID.Text = string.Empty;
		this.baseToolbarsManager.ToolClick -= new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClick);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}
	private void RefreshBAQDataView(BAQDataView iBaqView)
	{
    	MethodInfo mi = iBaqView.GetType().GetMethod("invokeExecute", BindingFlags.Instance | BindingFlags.NonPublic);
    	mi.Invoke(iBaqView, new object[]{ true });
	}
	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(venID.Text)) 
		{
			MessageBox.Show("Please enter customer");
		} else 
		{
			DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
			dqa.BOConnect();
			QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("JBIS-SuppInvLkUp");
			qeds.ExecutionParameter.Clear();
			qeds.ExecutionParameter.AddExecutionParameterRow("ConfirmSupplier", venID.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-SuppInvLkUp",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 dtStartDate_AfterExitEditMode(object sender, System.EventArgs args)
	{
		if (IsDateMin(dtStartDate.Text))
		{
			DateTime? endDate = DateTime.Parse(dtEndDate.Text);
			DateTime? startDate = DateTime.Parse(dtStartDate.Text);
			//string eD = endDate.ToString();
			//string sD = startDate.ToString();
			// ** 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;
				}
		}
		else 
		{
			MessageBox.Show("please enter an start date");
			DateTime? endDate = DateTime.Parse(dtEndDate.Text);
			DateTime? startDate;
			startDate = endDate.Value.AddDays(-1);
			string startDatePlusOne = startDate.ToString();
			dtStartDate.Text = startDatePlusOne;
		}
	}
	private void dtEndDate_AfterExitEditMode(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		if (IsDateMin(dtEndDate.Text))
		{
			DateTime? endDate = DateTime.Parse(dtEndDate.Text);
			DateTime? startDate = DateTime.Parse(dtStartDate.Text);
			endDate = endDate.Value.AddDays(1);
			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;
			}	
		}
		else 
		{
			MessageBox.Show("please enter an end date");
			DateTime? startDate= DateTime.Parse(dtStartDate.Text);
			DateTime? endDate;
			endDate = startDate.Value.AddDays(1);
			string endDatePlusOne = endDate.ToString();
			dtEndDate.Text = endDatePlusOne;
		}
	}
	

	private void baseToolbarsManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
	{
		{
			if (args.Tool.Key == "ClearTool")
			{
				ugInvRange.DataSource = null;
				dtStartDate.Text = "12/31/2021";
				dtEndDate.Text = "12/31/2021";
				venID.Text = "";	
			}
		}
	}

	private void dateRange_GotFocus(object sender, System.EventArgs args)
	{

	}
}
Editor is loading...