Пример #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>
        /// 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);
            }
        }