Ejemplo n.º 1
0
        public void ImportPyments()
        {
            Payment p = null;

            try
            {
                SqlCompactConnection conn = new SqlCompactConnection();
                conn.connect();
                lblStatus.Text = "Connected to mobile database";
                RefreshForm();
                string    sql        = "select * from payment";
                DataTable dtPayments = conn.GetDataTable(sql);
                int       rows       = dtPayments.Rows.Count;
                if (rows == 0)
                {
                    lblStatus.Text += "\nNo payments found";
                    //MessageBox.Show("There are no records to import", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                lblStatus.Text       = "Importing Payments..";
                progressBar1.Minimum = 0;
                progressBar1.Maximum = rows;
                RefreshForm();
                int count = 0;
                foreach (DataRow dr in dtPayments.Rows)
                {
                    p             = new Payment();
                    p.InvoiceID   = Int32.Parse(dr["InvoiceId"].ToString());
                    p.PaymentType = "S";
                    p.PaymentDate = DateTime.Parse(dr["PaymentDate"].ToString());
                    p.Amount      = decimal.Parse(dr["Amount"].ToString());
                    p.CheckNumber = dr["CheckNumber"].ToString();
                    p.Comments    = "Mobile Payment";
                    if (dr["Comments"].ToString() != String.Empty)
                    {
                        p.Comments += " : " + dr["Comments"].ToString();
                    }
                    //p.PaymentCode = dr["PaymentCode"].ToString();;
                    p.ModifiedDate = DateTime.Today;
                    p.AddPayment(p);
                    lblStatus.Text = "removing mobile payment..";
                    sql            = "delete payment where InvoiceId=" + p.InvoiceID;
                    conn.Execute(sql);
                    UpdatePaymentStatus(p.InvoiceID);
                    progressBar1.Value = count++;
                    RefreshForm();
                }
                lblStatus.Text     = rows.ToString() + " payments imported successfully";
                progressBar1.Value = rows;
                RefreshForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }