示例#1
0
        static void Main(string[] args)
        {
            using (SPCSConnection c = new SPCSConnection())
            {
                c.Open();

                if (c.IsConnected)
                {
                    SPCSInvoice i = new SPCSInvoice();
                    {
                        i.InvoiceCustomerNr = "101";
                        i.InvoiceDate = DateTime.Parse("2007-01-01");

                        SPCSInvoiceRow r = new SPCSInvoiceRow();
                        {
                            r.InvoiceRowArticleNr = "101";
                            r.InvoiceRowArticleText = "Artikel1";
                            r.InvoiceRowQuantity = 20;
                            //r.PriceEach = 50;
                            r.InvoiceRowUnit = "St";
                        }

                        i.InvoiceRows.Add(r);

                        i.Save();

                    }
                    c.Close();
                }
                else
                {
                    Console.WriteLine("NOT CONNECTED");
                }
            }

            Console.Read();
        }
        private List<SPCSInvoice> TestInvoices()
        {
            List<SPCSInvoice> invoices = new List<SPCSInvoice>();

            SPCSConnection connection = new SPCSConnection();
            {
                connection.Open();

                if (connection.IsConnected)
                {
                    SPCSCustomer c = new SPCSCustomer();
                    {
                        c.CustomerName = "FooBar AB";
                        c.CustomerNr = c.GetId();
                        c.CustomerReference = "Jonas Grimfelt";
                        c.SaveIfNotAvailable();
                        Console.WriteLine("Customer-nr: " + c.CustomerNr);
                    }

                    SPCSProject p = new SPCSProject();
                    {
                        p.ProjectName = "ABC-123";
                        p.ProjectNr = p.GetId();
                        p.ProjectCustomerNr = c.CustomerNr;
                        p.ProjectStartTime = DateTime.Today;
                        p.ProjectEndTime = DateTime.Today;
                        p.SaveIfNotAvailable();
                        Console.WriteLine("Project-nr: " + p.ProjectNr);
                    }

                    SPCSInvoice i = new SPCSInvoice();
                    {
                        i.InvoiceDate = DateTime.ParseExact("2007-07-14", "yyyy-MM-dd", null);

                        //i.InvoiceCustomerNr = c.CustomerNr;
                        i.Customer = c;
                        i.InvoiceCustomerOrderNr = "123AABB1234";

                        //i.InvoiceOurProject = p.ProjectNr;
                        i.Project = p;
                        i.InvoiceOurReferenceName = "Foo Bar";

                        SPCSInvoiceRow r1 = new SPCSInvoiceRow();
                        {
                            r1.InvoiceRowArticleText = "Lorem ipsum A";
                            r1.InvoiceRowPriceEach = 3.51;
                            r1.InvoiceRowQuantity = 425;
                            r1.InvoiceRowUnit = "Pieces";
                        }
                        SPCSInvoiceRow r2 = new SPCSInvoiceRow();
                        {
                            r2.InvoiceRowArticleText = "Lorem ipsum B";
                            r2.InvoiceRowPriceEach = 3.51;
                            r2.InvoiceRowQuantity = 300;
                            r2.InvoiceRowUnit = "Hr";
                        }
                        i.InvoiceRows.Add(r1);
                        i.InvoiceRows.Add(r2);
                    }

                    invoices.Add(i);
                }

                connection.Close();
                connection.Dispose();
            }

            return invoices;
        }
        private void ReadInvoiceRows(Connection connection, SPCSInvoice invoice, int invoiceId)
        {
            using (TypedDataReader reader = connection.GetInvoiceRowReader(invoiceId))
            {
                SPCSInvoiceRow invoiceRow = null;

                // For each invoice-row
                while (reader.Read())
                {
                    invoiceRow = new SPCSInvoiceRow();
                    {
                        invoiceRow.InvoiceRowArticleText = reader.GetString(DataBase.InvoiceRowColumnNameArticleText);
                        invoiceRow.InvoiceRowPriceEach = reader.GetDouble(DataBase.InvoiceRowColumnNamePriceEach);
                        invoiceRow.InvoiceRowQuantity = reader.GetDouble(DataBase.InvoiceRowColumnNameQuantity);
                        invoiceRow.InvoiceRowUnit = "TimAnt";
                    }

                    invoice.InvoiceRows.Add(invoiceRow);
                }
            }
        }