示例#1
0
        /// <summary>
        /// Load Purchase Order controls from xml file data
        /// </summary>
        /// <returns>Successfully loaded Word document</returns>
        public bool LoadPurchaseDelivery()
        {
            try
            {
                xsTaskCode xmlTask = new xsTaskCode();
                xmlTask.ReadXml(Schema.TaskSingleXmlFileName);
                xsTaskCode.TaskRow taskRow = (xsTaskCode.TaskRow)xmlTask.Task.Rows[0];

                #region header
                WriteControl("ContactName", taskRow.ContactName);
                WriteControl("AccountName", taskRow.AccountName);
                WriteControl("InvoiceAddress", taskRow.IsInvoiceAddressNull() ? string.Empty : taskRow.InvoiceAddress);
                WriteControl("TaskCode", taskRow.TaskCode);
                WriteControl("SecondReference", taskRow.IsSecondReferenceNull() ? string.Empty : taskRow.SecondReference);
                WriteControl("TaskTitle", taskRow.IsTaskTitleNull() ? string.Empty : taskRow.TaskTitle);
                WriteControl("TaskNotes", taskRow.IsTaskNotesNull() ? string.Empty : taskRow.TaskNotes);
                WriteControl("CollectionAccountName", taskRow.IsCollectionAccountNameNull() ? string.Empty : taskRow.CollectionAccountName);
                WriteControl("CollectionAddress", taskRow.IsCollectionAddressNull() ? string.Empty : taskRow.CollectionAddress);
                WriteControl("DeliveryAccountName", taskRow.IsDeliveryAccountNameNull() ? string.Empty : taskRow.DeliveryAccountName);
                WriteControl("DeliveryAddress", taskRow.IsDeliveryAddressNull() ? string.Empty : taskRow.DeliveryAddress);
                WriteControl("Quantity", taskRow.Quantity.ToQuantity());
                WriteControl("UnitOfMeasure", taskRow.UnitOfMeasure);
                WriteControl("ActionOn", taskRow.ActionOn.ToString());
                WriteControl("TotalCharge", taskRow.TotalCharge.ToCurrency());
                WriteControl("TaxRate", taskRow.TaxRate.ToPercentage());
                WriteControl("PaymentTerms", taskRow.PaymentTerms);
                WriteControl("UserName", taskRow.UserName);
                WriteControl("CompanyName", taskRow.CompanyName);
                WriteControl("CompanyWebsite", taskRow.CompanyWebsite);
                #endregion

                return(true);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, $"{err.Source}.{err.TargetSite.Name}", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// Load Purchase Order controls from xml file data
        /// </summary>
        /// <returns>Successfully loaded Word document</returns>
        public bool LoadPurchaseOrder()
        {
            try
            {
                xsTaskCode xmlTask = new xsTaskCode();
                xmlTask.ReadXml(Schema.TaskSingleXmlFileName);
                xsTaskCode.TaskRow taskRow = (xsTaskCode.TaskRow)xmlTask.Task.Rows[0];

                #region header
                WriteControl("ContactName", taskRow.ContactName);
                WriteControl("AccountName", taskRow.AccountName);
                WriteControl("InvoiceAddress", taskRow.IsInvoiceAddressNull() ? string.Empty : taskRow.InvoiceAddress);
                WriteControl("TaskCode", taskRow.TaskCode);
                WriteControl("SecondReference", taskRow.IsSecondReferenceNull() ? string.Empty : taskRow.SecondReference);
                WriteControl("NickName", taskRow.NickName);
                WriteControl("TaskTitle", taskRow.IsTaskTitleNull() ? string.Empty : taskRow.TaskTitle);
                WriteControl("DeliveryAddress", taskRow.IsDeliveryAddressNull() ? string.Empty : taskRow.DeliveryAddress);
                WriteControl("Quantity", taskRow.Quantity.ToQuantity());
                WriteControl("UnitOfMeasure", taskRow.UnitOfMeasure);
                WriteControl("ActionOn", taskRow.ActionOn.ToString());
                WriteControl("TotalCharge", taskRow.TotalCharge.ToCurrency());
                WriteControl("TaxRate", taskRow.TaxRate.ToPercentage());
                WriteControl("PaymentTerms", taskRow.PaymentTerms);
                WriteControl("TaskNotes", taskRow.IsTaskNotesNull() ? string.Empty : taskRow.TaskNotes);
                WriteControl("UserName", taskRow.UserName);
                WriteControl("CompanyName", taskRow.CompanyName);
                WriteControl("PaymentTerms", taskRow.PaymentTerms);
                WriteControl("DeliveryAddress", taskRow.DeliveryAddress);
                #endregion

                #region Attributes
                Word.Table attributeTable = null;
                Word.Row   attributeRow   = null;
                object     attribObj      = null;
                int[]      idxAttrib      = new int[] { 1, 2 };

                foreach (Word.Table table in document.Tables)
                {
                    foreach (Word.Row row in table.Rows)
                    {
                        foreach (Word.Cell cell in row.Range.Cells)
                        {
                            foreach (Word.ContentControl ctl in cell.Range.ContentControls)
                            {
                                switch (ctl.Tag)
                                {
                                case "a1":
                                    attributeTable = table;
                                    attribObj      = (object)row;
                                    attributeRow   = row;
                                    idxAttrib[0]   = cell.ColumnIndex;
                                    break;

                                case "a2":
                                    idxAttrib[1] = cell.ColumnIndex;
                                    break;
                                }
                            }
                        }
                        if (attributeRow != null)
                        {
                            break;
                        }
                    }
                    if (attributeRow != null)
                    {
                        break;
                    }
                }

                if (attributeRow != null)
                {
                    var attributes = from tb in xmlTask.Attributes
                                     select tb;

                    foreach (xsTaskCode.AttributesRow row in attributes)
                    {
                        if (((AttributeType)row.AttributeTypeCode == AttributeType.Order) ||
                            ((AttributeType)row.AttributeTypeCode == AttributeType.Quote && (TaskStatus)taskRow.TaskStatusCode == TaskStatus.Pending))

                        {
                            Word.Row newRow = attributeTable.Rows.Add(ref attribObj);
                            newRow.Cells[idxAttrib[0]].Range.Text = row.Attribute;
                            newRow.Cells[idxAttrib[1]].Range.Text = row.AttributeDescription;
                        }
                    }

                    attributeRow.Delete();
                }
                #endregion

                #region Schedule
                Word.Table scheduleTable = null;
                Word.Row   scheduleRow   = null;
                object     scheduleObj   = null;
                int[]      idxSched      = new int[] { 1, 2, 3 };

                foreach (Word.Table table in document.Tables)
                {
                    foreach (Word.Row row in table.Rows)
                    {
                        foreach (Word.Cell cell in row.Range.Cells)
                        {
                            foreach (Word.ContentControl ctl in cell.Range.ContentControls)
                            {
                                switch (ctl.Tag)
                                {
                                case "s1":
                                    scheduleTable = table;
                                    scheduleObj   = (object)row;
                                    scheduleRow   = row;
                                    idxSched[0]   = cell.ColumnIndex;
                                    break;

                                case "s2":
                                    idxSched[1] = cell.ColumnIndex;
                                    break;

                                case "s3":
                                    idxSched[2] = cell.ColumnIndex;
                                    break;
                                }
                            }
                        }
                        if (scheduleRow != null)
                        {
                            break;
                        }
                    }
                    if (scheduleRow != null)
                    {
                        break;
                    }
                }

                if (scheduleRow != null)
                {
                    var schedule = from tb in xmlTask.Schedule
                                   select tb;

                    foreach (xsTaskCode.ScheduleRow row in schedule)
                    {
                        Word.Row newRow = scheduleTable.Rows.Add(ref scheduleObj);
                        newRow.Cells[idxSched[0]].Range.Text = row.Operation;
                        newRow.Cells[idxSched[1]].Range.Text = row.EndOn.ToShortDateString();
                        newRow.Cells[idxSched[2]].Range.Text = row.IsNoteNull() ? string.Empty : row.Note;
                    }

                    scheduleRow.Delete();
                }
                #endregion

                return(true);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, $"{err.Source}.{err.TargetSite.Name}", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
示例#3
0
        /// <summary>
        /// Load quotation controls from xml file data
        /// </summary>
        /// <returns>Successfully loaded Word document</returns>
        public bool LoadQuotation()
        {
            try
            {
                xsTaskCode xmlTask = new xsTaskCode();
                xmlTask.ReadXml(Schema.TaskSingleXmlFileName);
                xsTaskCode.TaskRow taskRow = (xsTaskCode.TaskRow)xmlTask.Task.Rows[0];

                #region header
                WriteControl("ContactName", taskRow.ContactName);
                WriteControl("AccountCode", taskRow.AccountCode);
                WriteControl("AccountName", taskRow.AccountName);
                WriteControl("InvoiceAddress", taskRow.IsInvoiceAddressNull() ? string.Empty : taskRow.InvoiceAddress);
                WriteControl("NickName", taskRow.IsNickNameNull() ? string.Empty : taskRow.NickName);
                WriteControl("TaskCode", taskRow.TaskCode);
                WriteControl("TaskTitle", taskRow.IsTaskTitleNull() ? string.Empty : taskRow.TaskTitle);
                WriteControl("SecondReference", taskRow.IsSecondReferenceNull() ? string.Empty : taskRow.SecondReference);
                WriteControl("TaskNotes", taskRow.IsTaskNotesNull() ? string.Empty : taskRow.TaskNotes);
                WriteControl("UserName", taskRow.UserName);
                WriteControl("CompanyName", taskRow.CompanyName);
                #endregion

                #region Attributes
                Word.Table attributeTable = null;
                Word.Row   attributeRow   = null;
                object     attribObj      = null;
                int[]      idxAttrib      = new int[] { 1, 2 };

                foreach (Word.Table table in document.Tables)
                {
                    foreach (Word.Row row in table.Rows)
                    {
                        foreach (Word.Cell cell in row.Range.Cells)
                        {
                            foreach (Word.ContentControl ctl in cell.Range.ContentControls)
                            {
                                switch (ctl.Tag)
                                {
                                case "a1":
                                    attributeTable = table;
                                    attribObj      = (object)row;
                                    attributeRow   = row;
                                    idxAttrib[0]   = cell.ColumnIndex;
                                    break;

                                case "a2":
                                    idxAttrib[1] = cell.ColumnIndex;
                                    break;
                                }
                            }
                        }
                        if (attributeRow != null)
                        {
                            break;
                        }
                    }
                    if (attributeRow != null)
                    {
                        break;
                    }
                }

                if (attributeRow != null)
                {
                    var attributes = from tb in xmlTask.Attributes
                                     select tb;

                    foreach (xsTaskCode.AttributesRow row in attributes)
                    {
                        if (((AttributeType)row.AttributeTypeCode == AttributeType.Order) ||
                            ((AttributeType)row.AttributeTypeCode == AttributeType.Quote && (TaskStatus)taskRow.TaskStatusCode == TaskStatus.Pending))
                        {
                            Word.Row newRow = attributeTable.Rows.Add(ref attribObj);
                            newRow.Cells[idxAttrib[0]].Range.Text = row.Attribute;
                            newRow.Cells[idxAttrib[1]].Range.Text = row.AttributeDescription;
                        }
                    }

                    attributeRow.Delete();
                }
                #endregion

                #region quote
                Word.Table quoteTable = null;
                Word.Row   quoteRow   = null;
                object     quoteObj   = null;
                int[]      idxQuote   = new int[] { 1, 2, 3, 4, 5, 6 };

                foreach (Word.Table table in document.Tables)
                {
                    foreach (Word.Row row in table.Rows)
                    {
                        foreach (Word.Cell cell in row.Range.Cells)
                        {
                            foreach (Word.ContentControl ctl in cell.Range.ContentControls)
                            {
                                switch (ctl.Tag)
                                {
                                case "q1":
                                    quoteTable  = table;
                                    quoteObj    = (object)row;
                                    quoteRow    = row;
                                    idxQuote[0] = cell.ColumnIndex;
                                    break;

                                case "q2":
                                    idxQuote[1] = cell.ColumnIndex;
                                    break;

                                case "q3":
                                    idxQuote[2] = cell.ColumnIndex;
                                    break;

                                case "q4":
                                    idxQuote[3] = cell.ColumnIndex;
                                    break;

                                case "q5":
                                    idxQuote[4] = cell.ColumnIndex;
                                    break;

                                case "q6":
                                    idxQuote[5] = cell.ColumnIndex;
                                    break;
                                }
                            }
                        }
                        if (quoteRow != null)
                        {
                            break;
                        }
                    }
                    if (quoteRow != null)
                    {
                        break;
                    }
                }

                if (quoteRow != null)
                {
                    var quote = from tb in xmlTask.QuotedPrices
                                orderby tb.QuoteQuantity
                                select tb;

                    foreach (xsTaskCode.QuotedPricesRow row in quote)
                    {
                        Word.Row newRow = attributeTable.Rows.Add(ref quoteObj);
                        newRow.Cells[idxQuote[0]].Range.Text = row.QuoteQuantity.ToQuantity();
                        newRow.Cells[idxQuote[1]].Range.Text = row.QuotePrice.ToCurrency();
                        newRow.Cells[idxQuote[2]].Range.Text = row.RunOnQuantity.ToQuantity();
                        newRow.Cells[idxQuote[3]].Range.Text = row.RunOnPrice.ToCurrency();
                        newRow.Cells[idxQuote[4]].Range.Text = row.RunBackQuantity.ToQuantity();
                        newRow.Cells[idxQuote[5]].Range.Text = row.RunBackPrice.ToCurrency();
                    }

                    quoteRow.Delete();
                }

                #endregion

                return(true);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, $"{err.Source}.{err.TargetSite.Name}", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// Generate Task Xml File for orders/quotes
        /// </summary>
        /// <param name="_templateName">Word template.dot file name</param>
        /// <param name="_taskCode">Task code for generation</param>
        /// <param name="_includeQuotedAttributes">Include attributes where state is set to quoted only</param>
        /// <returns>Xml file successfully written to XmlFolder</returns>
        private bool LoadTask(dbTradeControlDataContext context, string _templateName, string _taskCode, bool _includeQuotedAttributes)
        {
            try
            {
                xsTaskCode taskXml = new xsTaskCode();
                taskXml.Clear();
                xsTaskCode.TaskRow taskRow = taskXml.Task.NewTaskRow();

                vwDocCompany company = (from tb in context.vwDocCompanies
                                        select tb).FirstOrDefault();

                if (company != null)
                {
                    taskRow.CompanyName         = company.CompanyName;
                    taskRow.CompanyAddress      = company.CompanyAddress;
                    taskRow.CompanyNumber       = company.CompanyNumber;
                    taskRow.CompanyEmailAddress = company.CompanyEmailAddress;
                    taskRow.CompanyWebsite      = company.CompanyWebsite;
                    taskRow.CompanyPhoneNumber  = company.CompanyPhoneNumber;
                    taskRow.CompanyNumber       = company.CompanyNumber;
                    taskRow.CompanyVatNumber    = company.VatNumber;
                }

                vwDocTaskCode task = (from tb in context.vwDocTaskCodes
                                      where tb.TaskCode == _taskCode
                                      select tb).First();

                documentFileName = $"{Repository}\\{task.AccountCode}_{_templateName}_{task.TaskCode}";

                if (task.EmailAddress == null)
                {
                    taskRow.EmailAddress = string.Empty;
                }
                else
                {
                    taskRow.EmailAddress = task.EmailAddress;
                }

                emailAddress = taskRow.EmailAddress;

                taskRow.TaskCode        = task.TaskCode;
                taskRow.SecondReference = task.SecondReference;
                taskRow.PaymentTerms    = task.PaymentTerms;
                taskRow.TaskStatus      = task.TaskStatus;
                taskRow.TaskStatusCode  = task.TaskStatusCode;
                taskRow.TaskNotes       = task.TaskNotes;
                taskRow.TaskTitle       = task.TaskTitle;
                taskRow.TaxCode         = task.TaxCode;
                taskRow.TaxRate         = (decimal)task.TaxRate;
                taskRow.TotalCharge     = task.TotalCharge;
                taskRow.UnitCharge      = task.UnitCharge;
                taskRow.UnitOfMeasure   = task.UnitOfMeasure;
                taskRow.ContactName     = task.ContactName;
                taskRow.UserName        = task.UserName;
                taskRow.AccountCode     = task.AccountCode;
                taskRow.AccountName     = task.AccountName;
                taskRow.NickName        = task.NickName;
                taskRow.InvoiceAddress  = task.InvoiceAddress;
                taskRow.ActionOn        = task.ActionOn;
                taskRow.Quantity        = task.Quantity;

                taskRow.TaxCharge             = (double)task.TotalCharge * (double)task.TaxRate;
                taskRow.CollectionAddress     = task.CollectionAddress;
                taskRow.DeliveryAddress       = task.DeliveryAddress;
                taskRow.CollectionAccountName = task.CollectionAccountName;
                taskRow.DeliveryAccountName   = task.DeliveryAccountName;

                taskXml.Task.AddTaskRow(taskRow);

                var attributes = from tb in context.tbAttributes
                                 where tb.TaskCode == _taskCode
                                 orderby tb.PrintOrder
                                 select tb;

                foreach (tbAttribute attribute in attributes)
                {
                    if (_includeQuotedAttributes || attribute.AttributeTypeCode == (short)AttributeType.Order)
                    {
                        xsTaskCode.AttributesRow attribRow = taskXml.Attributes.NewAttributesRow();
                        attribRow.Attribute            = attribute.Attribute;
                        attribRow.AttributeDescription = attribute.AttributeDescription;
                        attribRow.AttributeTypeCode    = attribute.AttributeTypeCode;
                        taskXml.Attributes.AddAttributesRow(attribRow);
                    }
                }

                var quotes = from tb in context.tbQuotes
                             where tb.TaskCode == _taskCode
                             orderby tb.Quantity
                             select tb;

                foreach (tbQuote quote in quotes)
                {
                    xsTaskCode.QuotedPricesRow priceRow = taskXml.QuotedPrices.NewQuotedPricesRow();
                    priceRow.QuoteQuantity   = quote.Quantity;
                    priceRow.RunBackPrice    = quote.RunBackPrice;
                    priceRow.RunBackQuantity = quote.RunBackQuantity;
                    priceRow.RunOnPrice      = quote.RunOnPrice;
                    priceRow.RunOnQuantity   = quote.RunOnQuantity;
                    priceRow.QuotePrice      = quote.TotalPrice;
                    taskXml.QuotedPrices.AddQuotedPricesRow(priceRow);
                }

                var schedule = from tb in context.proc_Op(_taskCode)
                               orderby tb.OperationNumber
                               select tb;

                foreach (proc_OpResult op in schedule)
                {
                    xsTaskCode.ScheduleRow opRow = taskXml.Schedule.NewScheduleRow();
                    opRow.Duration        = (decimal)op.Duration;
                    opRow.EndOn           = op.EndOn;
                    opRow.Note            = op.Note;
                    opRow.Operation       = op.Operation;
                    opRow.OperationNumber = op.OperationNumber;
                    opRow.StartOn         = op.StartOn;
                    taskXml.Schedule.AddScheduleRow(opRow);
                }

                taskXml.WriteXml(Schema.TaskSingleXmlFileName);

                return(true);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, $"{err.Source}.{err.TargetSite.Name}", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
示例#5
0
        /// <summary>
        /// Load enquiry controls from xml file data
        /// </summary>
        /// <returns>Successfully loaded Word document</returns>
        public bool LoadEnquiry()
        {
            try
            {
                xsTaskCode xmlTask = new xsTaskCode();
                xmlTask.ReadXml(Schema.TaskSingleXmlFileName);
                xsTaskCode.TaskRow taskRow = (xsTaskCode.TaskRow)xmlTask.Task.Rows[0];

                #region header
                WriteControl("ContactName", taskRow.ContactName);
                WriteControl("AccountCode", taskRow.AccountCode);
                WriteControl("AccountName", taskRow.AccountName);
                WriteControl("InvoiceAddress", taskRow.IsInvoiceAddressNull() ? string.Empty : taskRow.InvoiceAddress);
                WriteControl("TaskCode", taskRow.TaskCode);
                WriteControl("TaskTitle", taskRow.IsTaskTitleNull() ? string.Empty : taskRow.TaskTitle);
                WriteControl("TaskNotes", taskRow.IsTaskNotesNull() ? string.Empty : taskRow.TaskNotes);
                WriteControl("Quantity", taskRow.Quantity.ToQuantity());
                WriteControl("UnitOfMeasure", taskRow.UnitOfMeasure);
                WriteControl("UserName", taskRow.UserName);
                WriteControl("CompanyName", taskRow.CompanyName);
                #endregion

                #region Attributes
                Word.Table attributeTable = null;
                Word.Row   attributeRow   = null;
                object     attribObj      = null;
                int[]      idxAttrib      = new int[] { 1, 2 };

                foreach (Word.Table table in document.Tables)
                {
                    foreach (Word.Row row in table.Rows)
                    {
                        foreach (Word.Cell cell in row.Range.Cells)
                        {
                            foreach (Word.ContentControl ctl in cell.Range.ContentControls)
                            {
                                switch (ctl.Tag)
                                {
                                case "a1":
                                    attributeTable = table;
                                    attribObj      = (object)row;
                                    attributeRow   = row;
                                    idxAttrib[0]   = cell.ColumnIndex;
                                    break;

                                case "a2":
                                    idxAttrib[1] = cell.ColumnIndex;
                                    break;
                                }
                            }
                        }
                        if (attributeRow != null)
                        {
                            break;
                        }
                    }
                    if (attributeRow != null)
                    {
                        break;
                    }
                }

                if (attributeRow != null)
                {
                    var attributes = from tb in xmlTask.Attributes
                                     select tb;

                    foreach (xsTaskCode.AttributesRow row in attributes)
                    {
                        if (((AttributeType)row.AttributeTypeCode == AttributeType.Order) ||
                            ((AttributeType)row.AttributeTypeCode == AttributeType.Quote && (TaskStatus)taskRow.TaskStatusCode == TaskStatus.Pending))
                        {
                            Word.Row newRow = attributeTable.Rows.Add(ref attribObj);
                            newRow.Cells[idxAttrib[0]].Range.Text = row.Attribute;
                            newRow.Cells[idxAttrib[1]].Range.Text = row.AttributeDescription;
                        }
                    }

                    attributeRow.Delete();
                }
                #endregion

                return(true);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, $"{err.Source}.{err.TargetSite.Name}", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }