示例#1
0
        public int ReceiveBalanceInvoice(balanceInvoice invoice)
        {
            Trace.WriteLine("ReceiveBalanceInvoice");
            int result = 0;
            try
            {
                DataManager dataMan = new DataManager();
                ContractData cData = dataMan.GetContractData(Int64.Parse(invoice.contractId));
                if (cData.EndDate < new DateTime(1990, 1, 1))
                {
                    Trace.WriteLine("Contract is not terminated. Message not saved, returning 1, finishing.");
                    return 1;
                }

                if (dataMan.SaveInvoice(invoice) == 1)
                {
                    try
                    {

                        MailMessage mail = new MailMessage("*****@*****.**", cData.ClientEmail);
                        mail.Subject = "T1ES1: Invoice nr." + invoice.invoiceNo;
                        mail.Body = String.Format("Congratulations: you have received invoice nr. {0}, dated by {1}, made by {5}. Please make payment with amount {2} before {3}, or you will be banned with our mighty banhammer!\n You can see your invoices in our User frontend at {4} on the 'Invoices' page.", invoice.invoiceNo, invoice.date.ToString("dd.MM.yyyy"), invoice.amount.ToString("0.00"), invoice.dueDate.ToString("dd.MM.yyyy"), "http://sandstorm.cs.ut.ee/ESI/2011/otido/Frontend/", invoice.kradoId);

                        SmtpClient sc = new SmtpClient("mailhost.ut.ee");
                        sc.Send(mail);
                        result = 1;
                    }
                    catch (Exception mailSendExc)
                    {
                        Trace.WriteLine("Error sending email: " + mailSendExc.Message);
                        result = 0;
                    }

                };
            }
            catch (Exception rbiExc)
            {
                Trace.WriteLine("Error receiving balance invoice: " + rbiExc.Message);
                result = 0;
            }
            return result;
        }
示例#2
0
        internal t1rk1.balanceInvoice[] GetUserInvoices(string clientRegno)
        {
            List<balanceInvoice> result = new List<balanceInvoice>();
            try
            {
                using (SqlConnection dbConn = new SqlConnection(connectionString))
                {
                    string qsGetInvoices = @"SELECT [ID], [DATE], [CONTRACT_ID], [DUE_DATE], [EXPLANATION], [AMOUNT], [INVOICE_NR], [KRADO_ID] FROM [INVOICE] where [CONTRACT_ID] in (SELECT  [ID] FROM [CONTRACT] where [CLIENT_ID] = ( SELECT [ID] FROM [CLIENT] where [REG_NR]=@CLIENT_REGNO )) order by [DATE] desc";
                    SqlCommand dbCommand = new SqlCommand(qsGetInvoices, dbConn);
                    dbCommand.Parameters.AddWithValue("@CLIENT_REGNO", Int64.Parse(clientRegno));
                    dbConn.Open();

                    SqlDataReader dbReader = dbCommand.ExecuteReader();

                    while (dbReader.Read())
                    {
                        try
                        {
                            balanceInvoice bi = new balanceInvoice();
                            bi.invoiceNo = dbReader.GetString(6);
                            bi.date = dbReader.GetDateTime(1);
                            bi.dueDate = (dbReader.GetValue(3) == DBNull.Value) ? DateTime.Now
                            : dbReader.GetDateTime(3);
                            bi.explanation = dbReader.GetString(4);
                            bi.amount = dbReader.GetDouble(5);
                            bi.kradoId = dbReader.GetString(7);

                            result.Add(bi);

                        }
                        catch (Exception rowExc)
                        {
                            Debug.WriteLine("Error reading invoice row: " + rowExc.Message);
                        }
                    }
                    dbReader.Close();
                    dbCommand.Connection.Close();

                }
            }
            catch (Exception invoiceDataExc)
            {
                Debug.WriteLine("Error getting user invoices: " + invoiceDataExc.Message);
            }

            return result.ToArray();
        }
示例#3
0
 public balanceInvoice[] Frontend_GetInvoicesByClientRegno(string clientRegno)
 {
     Trace.WriteLine("Frontend_GetInvoicesByClientRegno");
     balanceInvoice[] result = new balanceInvoice[0];
     DataManager dataMan = new DataManager();
     return dataMan.GetUserInvoices(clientRegno);
 }