namespace PopulateJobLinkerRTE
{
public partial class frmViewJobLinker : DexUIForm
{
/* Keep a reference to the View Agencies By Jobs Form WinForm */
static frmLookupJob ViewAgenciesByJobsForm;
/* Create a reference to the Receivables Transaction Entry screen */
static RmSalesEntryForm RmSalesEntryForm = Dynamics.Forms.RmSalesEntry;
static RmSalesEntryForm.RmSalesEntryWindow RmSalesEntryWindow = RmSalesEntryForm.RmSalesEntry;
/* Create a reference to the Receivables Transaction Entry Distribution screen */
static RmSalesDistributionForm RmSalesDistributionForm = Dynamics.Forms.RmSalesDistribution;
static RmSalesDistributionForm.RmSalesDistributionWindow RmSalesDistributionWindow = RmSalesDistributionForm.RmSalesDistribution;
/* Define a string variable to hold connection string */
string ConnectionString;
/* Set up SQL Connection Handlers */
private System.Data.SqlClient.SqlConnection DataConnection;
private System.Data.DataSet DataDataSet;
private System.Data.SqlClient.SqlCommand DataCommand;
private System.Data.SqlClient.SqlDataAdapter DataDataAdapter;
private System.Data.DataSet TrxTypeDataSet;
private System.Data.SqlClient.SqlCommand TrxTypeDataCommand;
private System.Data.SqlClient.SqlDataAdapter TrxTypeDataAdapter;
private SqlCommandBuilder _commandBuilder;
/* Define variables to hold batch number and batch source */
string DocumentNumber;
string MasterType;
string DistSource;
string DocSource;
public frmViewJobLinker()
{
InitializeComponent();
txtCustomerID.Text = RmSalesEntryWindow.CustomerNumber;
txtCustomerName.Text = RmSalesEntryWindow.CustomerName;
txtDocumentNumber.Text = RmSalesEntryWindow.RmDocumentNumberWork;
DocumentNumber = RmSalesEntryWindow.RmDocumentNumberWork;
switch (RmSalesEntryWindow.DocumentType.Value.ToString())
{
case "1":
txtDocumentType.Text = "Sales/Invoices";
break;
case "2":
txtDocumentType.Text = "Debit Memos";
break;
case "3":
txtDocumentType.Text = "Finance Charges";
break;
case "4":
txtDocumentType.Text = "Service/Repairs";
break;
case "5":
txtDocumentType.Text = "Warranty";
break;
case "6":
txtDocumentType.Text = "Credit Memo";
break;
case "7":
txtDocumentType.Text = "Returns";
break;
default:
txtDocumentType.Text = "Unknown";
break;
}
txtDocumentAmount.Text = RmSalesEntryWindow.DocumentAmount.Value.ToString("c");
DocumentNumber = RmSalesEntryWindow.RmDocumentNumberWork;
txtBatchName.Text = RmSalesEntryWindow.BatchNumber;
/* Convert the posting date */
txtPostingDate.Text = RmSalesEntryWindow.GlPostingDate.Value.ToString();
try
{
if (txtPostingDate.Text != "")
{
txtPostingDate.Text = Convert.ToDateTime(txtPostingDate.Text).ToString("MM/dd/yyyy");
}
}
catch (Exception ex)
{
MessageBox.Show("ERROR::" + ex.Message);
this.Close();
}
/* Convert the document date */
txtDocumentDate.Text = RmSalesEntryWindow.DocumentDate.Value.ToString();
try
{
if (txtDocumentDate.Text.ToString() != "")
{
txtDocumentDate.Text = Convert.ToDateTime(txtDocumentDate.Text).ToString("MM/dd/yyyy");
}
}
catch (Exception ex)
{
MessageBox.Show("ERROR::" + ex.Message);
this.Close();
}
MasterType = "CUS";
DistSource = "Receivables Transaction Entry";
DocSource = "Receivables";
/* Populate the Job Linker table based on this Document Number */
try
{
SqlConnection con = GetConnection();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@DCMTNMBR", DocumentNumber));
cmd.Parameters.Add(new SqlParameter("@MASTERTYPE", MasterType));
cmd.Parameters.Add(new SqlParameter("@DISTSOURCE", DistSource));
cmd.Parameters.Add(new SqlParameter("@DOCSOURCE", DocSource));
cmd.CommandText = "rbsUpdateJobLinkerRTE";
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("ERROR::" + ex.Message);
this.Close();
}
/* Display the GL Distributions from the Job Linker table per Document Number */
try
{
SqlConnection DataConnection = GetConnection();
/* Define dataset for Transaction Types */
TrxTypeDataSet = new System.Data.DataSet();
TrxTypeDataSet.CaseSensitive = false;
TrxTypeDataCommand = new System.Data.SqlClient.SqlCommand();
TrxTypeDataCommand.Connection = DataConnection;
TrxTypeDataCommand.CommandText = "select LTRIM(DISTTRXTYPE) AS DISTTRXTYPE from JOB_TRX_TYPES where formtype='SALES' ORDER BY DISTTRXTYPE";
TrxTypeDataAdapter = new System.Data.SqlClient.SqlDataAdapter();
TrxTypeDataAdapter.SelectCommand = TrxTypeDataCommand;
TrxTypeDataAdapter.Fill(TrxTypeDataSet);
/* Define dataset for GL distribution amounts */
DataDataSet = new System.Data.DataSet();
DataDataSet.CaseSensitive = false;
DataCommand = new System.Data.SqlClient.SqlCommand();
DataCommand.Connection = DataConnection;
DataCommand.CommandText = "select JOBNUMBER,ACTNUMST,DEBITAMT,CRDTAMNT,DISTTYPE,DISTTRXTYPE,DISTREF,BCHSOURC,TRANSNMBR,TRXTYPE,DSTSQNUM,CNTRLTYP,APTVCHNM,SPCLDIST " +
"from JOB_LINKER WHERE TRANSNMBR ='" + DocumentNumber + "' order by DSTSQNUM";
DataDataAdapter = new System.Data.SqlClient.SqlDataAdapter();
DataDataAdapter.SelectCommand = DataCommand;
_commandBuilder = new SqlCommandBuilder(DataDataAdapter);
DataDataAdapter.Fill(DataDataSet);
dgvViewJobLinker.DataError += new DataGridViewDataErrorEventHandler(dgvJobLinker_DataError);
dgvViewJobLinker.RowHeadersVisible = false;
dgvViewJobLinker.DataSource = DataDataSet.Tables[0].DefaultView;
dgvViewJobLinker.AutoGenerateColumns = true;
dgvViewJobLinker.DefaultCellStyle.NullValue = ' ';
dgvViewJobLinker.AllowUserToAddRows = false;
DataGridViewButtonColumn colButton = new DataGridViewButtonColumn();
colButton.HeaderText = "";
colButton.Name = "btnLookupJob";
colButton.Text = "Lookup Job";
colButton.UseColumnTextForButtonValue = true;
dgvViewJobLinker.Columns.Insert(0, colButton);
dgvViewJobLinker.CellContentClick += new DataGridViewCellEventHandler(dgvViewJobLinker_CellContentClick);
dgvViewJobLinker.Columns[0].Width = 80;
dgvViewJobLinker.Columns[1].Width = 100;
dgvViewJobLinker.Columns[1].ReadOnly = false;
dgvViewJobLinker.Columns[1].HeaderText = "Job Number";
dgvViewJobLinker.Columns[2].Width = 100;
dgvViewJobLinker.Columns[2].ReadOnly = true;
dgvViewJobLinker.Columns[2].HeaderText = "GL Account";
dgvViewJobLinker.Columns[3].Width = 84;
dgvViewJobLinker.Columns[3].ReadOnly = true;
dgvViewJobLinker.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
dgvViewJobLinker.Columns[3].DefaultCellStyle.Format = "c";
dgvViewJobLinker.Columns[3].HeaderText = "Debit Amount";
dgvViewJobLinker.Columns[4].Width = 84;
dgvViewJobLinker.Columns[4].ReadOnly = true;
dgvViewJobLinker.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
dgvViewJobLinker.Columns[4].DefaultCellStyle.Format = "c";
dgvViewJobLinker.Columns[4].HeaderText = "Credit Amount";
dgvViewJobLinker.Columns[5].Width = 100;
dgvViewJobLinker.Columns[5].ReadOnly = true;
dgvViewJobLinker.Columns[5].HeaderText = "Dist Type";
/* Add a new Column (ComboBox) for the Transaction Type column */
DataGridViewComboBoxColumn colType = new DataGridViewComboBoxColumn();
colType.DefaultCellStyle.NullValue = " ";
colType.DataSource = TrxTypeDataSet.Tables[0];
colType.ValueMember = DataDataSet.Tables[0].Columns[5].ColumnName.ToString();
colType.DisplayMember = colType.ValueMember;
colType.HeaderText = "Transaction Type";
colType.DropDownWidth = 90;
colType.Width = 90;
colType.MaxDropDownItems = 7;
colType.DataPropertyName = DataDataSet.Tables[0].Columns[5].ColumnName.ToString();
colType.Name = DataDataSet.Tables[0].Columns[5].ColumnName.ToString();
dgvViewJobLinker.Columns.RemoveAt(6);
dgvViewJobLinker.Columns.Insert(6, colType);
dgvViewJobLinker.Columns[7].Width = 292;
dgvViewJobLinker.Columns[7].ReadOnly = false;
dgvViewJobLinker.Columns[7].HeaderText = "Dist Reference";
dgvViewJobLinker.Columns[8].Visible = false;
dgvViewJobLinker.Columns[9].Visible = false;
dgvViewJobLinker.Columns[10].Visible = false;
dgvViewJobLinker.Columns[11].Visible = false;
dgvViewJobLinker.Columns[12].Visible = false;
dgvViewJobLinker.Columns[13].Visible = false;
dgvViewJobLinker.Columns[14].Visible = false;
dgvViewJobLinker.EditMode = DataGridViewEditMode.EditOnEnter;
dgvViewJobLinker.Focus();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Hide();
this.Dispose();
}
private SqlConnection GetConnection()
{
/* Create reader and open file containing connection string */
TextReader tr = new StreamReader(@"C:\Program Files\Microsoft Dynamics\GP\Addins\GSE.INI");
/* Read line containing the connection string */
ConnectionString = tr.ReadLine();
/* Close the stream */
tr.Close();
DataConnection = new System.Data.SqlClient.SqlConnection(ConnectionString);
DataConnection.Open();
return DataConnection;
}
private void dgvViewJobLinker_SelectionChanged(object sender, EventArgs e)
{
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
//DataCommandBuilder = new SqlCommandBuilder(DataDataAdapter);
//DataDataAdapter.DeleteCommand = DataCommandBuilder.GetDeleteCommand();
//DataDataAdapter.InsertCommand = DataCommandBuilder.GetInsertCommand();
//DataDataAdapter.UpdateCommand = DataCommandBuilder.GetUpdateCommand();
_commandBuilder.GetUpdateCommand();
DataDataAdapter.Update(DataDataSet);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
this.Hide();
this.Dispose();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void dgvJobLinker_DataError(object sender, DataGridViewDataErrorEventArgs anError)
{
}
private void dgvViewJobLinker_CellClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dgvViewJobLinker_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 && e.RowIndex > 0)
{
if (ViewAgenciesByJobsForm == null)
{
ViewAgenciesByJobsForm = new frmLookupJob();
}
else
{
if (ViewAgenciesByJobsForm.Created == false)
{
ViewAgenciesByJobsForm = new frmLookupJob();
}
}
ViewAgenciesByJobsForm.ShowDialog();
/* ViewAgenciesByJobsForm.Show();
ViewAgenciesByJobsForm.Activate(); */
dgvViewJobLinker[1, dgvViewJobLinker.CurrentCell.RowIndex].Value = ViewAgenciesByJobsForm.CellValue;
}
}
}
}
|