コード例 #1
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                if (ContactDB != null)
                {
                    ///Get Role List.
                    cbxRole.ItemsSource = ContactDB.contact_role.Where(a => a.id_company == CurrentSession.Id_Company && a.is_active == true).OrderBy(a => a.name).AsNoTracking().ToList();
                    contactViewSource   = (CollectionViewSource)this.FindResource("contactViewSource");

                    ///Check for ContactID to check if this form is in EDIT mode or NEW mode.
                    if (ContactID > 0)
                    {
                        ///If Contact IsNot Null, then this form is in EDIT MODE. Must add Contact into Context.
                        _contact = ContactDB.contacts.Where(x => x.id_contact == ContactID).FirstOrDefault();
                        ContactDB.contacts.Add(_contact);
                    }
                    else
                    {
                        ///If ContactID is Null, then this form is in NEW MODE. Must create Contact and add into Context.
                        if (ContactDB.contacts.Local.Where(x => x.id_contact == 0).Count() == 0)
                        {
                            _contact = ContactDB.New();
                            ContactDB.contacts.Add(_contact);
                        }
                    }

                    if (IsCustomer)
                    {
                        cbPriceList.ItemsSource = ContactDB.item_price_list.Where(a => a.is_active == true && a.id_company == CurrentSession.Id_Company).OrderBy(a => a.name).AsNoTracking().ToList();
                        _contact.is_customer    = true;
                        _contact.is_supplier    = false;
                        _contact.is_employee    = false;
                    }

                    if (IsSupplier)
                    {
                        cbCostCenter.ItemsSource = ContactDB.app_cost_center.Where(a => a.is_active == true && a.id_company == CurrentSession.Id_Company).OrderBy(a => a.name).AsNoTracking().ToList();
                        _contact.is_supplier     = true;
                        _contact.is_employee     = false;
                        _contact.is_customer     = false;
                    }

                    if (IsEmployee)
                    {
                        _contact.is_employee = true;
                        _contact.is_supplier = false;
                        _contact.is_customer = false;
                    }

                    ///Bring only InMemoria Data.
                    contactViewSource.Source = ContactDB.contacts.Local;
                    contactViewSource.View.MoveCurrentTo(_contact);
                }
            }
        }
コード例 #2
0
ファイル: Contact.xaml.cs プロジェクト: mercaditu/ERP
        private void toolBar_btnNew_Click(object sender)
        {
            contact contact = ContactDB.New();

            contact.is_employee = false;
            contact.State       = EntityState.Added;
            contact.IsSelected  = true;
            ContactDB.contacts.Add(contact);
            contactViewSource.View.Refresh();
            contactViewSource.View.MoveCurrentToLast();
        }