private void toolStripOpen_Click(object sender, EventArgs e) { openFileDialog1.Title = "Open an XML file"; openFileDialog1.Filter = "XML Documents|*.xml"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { path = openFileDialog1.FileName; using (FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(BindingList <Employee>)); BindingList <Employee> employees = (BindingList <Employee>)xmlSerializer.Deserialize(fStream); persons.Clear(); BindList.AddRange(employees, persons); comboBox1.DataSource = persons; comboBox1.DisplayMember = "FullName"; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private double AddAdvancePayments() { double remainder = total - payments.Sum(p => p.Quantity); List <Payment> displayedAdvancePayments = new List <Payment> (); foreach (Payment advance in advances) { // Find an already used advance with the same payment type Payment payment = displayedAdvancePayments.Find(p => p.TypeId == advance.TypeId); if (payment == null) { payment = (Payment)advance.Clone(); payment.OperationId = operation.Id; payment.LocationId = operation.LocationId; payment.ParentOperation = operation; payment.Quantity = 0; displayedAdvancePayments.Add(payment); } // Record the usage of the advance payment with the similar payment type if (!usedAdvances.ContainsKey(payment)) { usedAdvances [payment] = new List <long> (); } usedAdvances [payment].Add(advance.Id); double sum = Math.Min(remainder, advance.Quantity); payment.Quantity += sum; remainder -= sum; if (remainder.IsZero()) { break; } } foreach (Payment advancePayment in displayedAdvancePayments) { advancePayment.PropertyChanged += payment_PropertyChanged; } payments.AddRange(displayedAdvancePayments); return(remainder); }
protected override void InitializeForm() { XML form = FormHelper.LoadGladeXML("Dialogs.EditNewPayment.glade", "dlgEditNewPayment"); form.Autoconnect(this); dlgEditNewPayment.Icon = FormHelper.LoadImage("Icons.TradePoint32.png").Pixbuf; btnOK.SetChildImage(FormHelper.LoadImage("Icons.Ok24.png")); btnCancel.SetChildImage(FormHelper.LoadImage("Icons.Cancel24.png")); txtDueDate.Text = BusinessDomain.GetFormattedDate(GetDueDate()); base.InitializeForm(); InitializeFormStrings(); paymentWidget.RefreshGrid(); chkUseAdvances.Visible = operation.UseAdvancePayments && operation.Id < 0; if (!chkUseAdvances.Visible) { return; } advances.AddRange(Payment.GetAdvances(operation.PartnerId)); foreach (Payment payment in advances) { payment.Type.BaseType = BasePaymentType.Advance; } if (advances.Count == 0) { chkUseAdvances.Visible = false; } else { chkUseAdvances.Label = string.Format("{0} {1}", Translator.GetString("Use Advance Payments"), string.Format(Translator.GetString("(total: {0})"), Currency.ToString(advances.Sum(p => p.Quantity), operation.TotalsPriceType))); } }