Beispiel #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);
                }
            }
        }
Beispiel #2
0
 private void contactComboBox_Select(object sender, RoutedEventArgs e)
 {
     if (contactComboBox.ContactID > 0)
     {
         entity.contact contact  = db.contacts.Where(x => x.id_contact == contactComboBox.ContactID).FirstOrDefault();
         entity.project _project = projectViewSource.View.CurrentItem as entity.project;
         _project.id_contact = contact.id_contact;
         _project.contact    = contact;
     }
 }
Beispiel #3
0
        private ContactInfo matchContact(entity.contact _Contact)
        {
            ContactInfo NewContact = new ContactInfo();

            NewContact.ID               = _Contact.id_contact;
            NewContact.Code             = _Contact.code;
            NewContact.Name             = _Contact.name;
            NewContact.GovCode          = _Contact.gov_code;
            NewContact.SubscriptionItem = _Contact.contact_subscription.FirstOrDefault() != null?_Contact.contact_subscription.FirstOrDefault().item != null?_Contact.contact_subscription.FirstOrDefault().item.name : "" : "";

            if (_Contact.date_birth != null)
            {
                NewContact.DateBirth = (System.DateTime)_Contact.date_birth;
            }

            NewContact.StartDate = _Contact.timestamp;

            return(NewContact);
        }
Beispiel #4
0
        private void btnSave_MouseUp(object sender, RoutedEventArgs e)
        {
            entity.contact contact = contactViewSource.View.CurrentItem as entity.contact;

            //This is helpful when we want to Automate the search of contact when saving is done.
            if (contact != null)
            {
                ContactName = contact.name;

                if (btnSave_Click != null)
                {
                    btnSave_Click(sender);
                }
            }

            if (ContactDB.SaveChanges() == 0)
            {
                MessageBox.Show("Saving Error");
            }

            btnCancel_MouseDown(null, null);
        }
Beispiel #5
0
        public void loadCarnetcontactReport(int id)
        {
            try
            {
                ReportDataSource reportDataSource = new ReportDataSource();
                reportDataSource.Name = "DataSet1"; // Name of the DataSet we set in .rdlc
                contact contact = db.contacts.Where(x => x.id_contact == id).FirstOrDefault();
                if (contact.child.Count > 0)
                {
                    List <contact> contact_detail = contact.child.ToList();
                    reportDataSource.Value = contact_detail
                                             .Select(g => new
                    {
                        id_contact    = g.id_contact,
                        contacts_name = g.parent.name,
                        date_birth    = g.parent.date_birth,
                        gove_code     = g.parent.gov_code,
                        trans_date    = g.parent.timestamp,
                        contacts_code = g.parent.code,
                        Product_code  = g.parent.contact_subscription.FirstOrDefault().item.name,
                        name          = g.name
                    }).ToList();
                }
                else
                {
                    List <contact> contact_detail = new List <entity.contact>();
                    contact_detail.Add(contact);
                    reportDataSource.Value = contact_detail
                                             .Select(g => new
                    {
                        id_contact    = g.id_contact,
                        contacts_name = g.name,
                        date_birth    = g.date_birth,
                        gove_code     = g.gov_code,
                        trans_date    = g.timestamp,
                        contacts_code = g.code,
                        Product_code  = g.contact_subscription.FirstOrDefault() != null ? g.contact_subscription.FirstOrDefault().item != null ? g.contact_subscription.FirstOrDefault().item.name : "" : "",
                        name          = ""
                    }).ToList();
                }



                string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                path = path + "\\CogntivoERP";
                string SubFolder = "";
                SubFolder = "\\TemplateFiles";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                    Directory.CreateDirectory(path + SubFolder);
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Carnet_Contact.rdlc", path + SubFolder + "\\Carnet_Contact.rdlc");
                }
                else if (!Directory.Exists(path + SubFolder))
                {
                    Directory.CreateDirectory(path + SubFolder);
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Carnet_Contact.rdlc", path + SubFolder + "\\Carnet_Contact.rdlc");
                }
                else if (!File.Exists(path + SubFolder + "\\Carnet_Contact.rdlc"))
                {
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\debug\\Carnet_Contact.rdlc", path + SubFolder + "\\Carnet_Contact.rdlc");
                }

                reportViewer.LocalReport.ReportPath = path + SubFolder + "\\Carnet_Contact.rdlc"; // Path of the rdlc file
                reportViewer.LocalReport.DataSources.Add(reportDataSource);
                reportViewer.RefreshReport();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #6
0
        public decimal get_SalesPrice(int id_item, contact Contact, int CurrencyFX_ID)
        {
            int PriceList_ID = 0;

            if (id_item > 0)
            {
                if (Contact != null)
                {
                    if (Contact.id_price_list != null)
                    {
                        PriceList_ID = (int)Contact.id_price_list;
                    }
                    else
                    {
                        PriceList_ID = 0;
                    }
                }

                //Step 1. If 'PriceList_ID' is 0, Get Default PriceList.
                if (PriceList_ID == 0 && PriceList_ID != null)
                {
                    using (db db = new db())
                    {
                        if (db.item_price_list.Where(x => x.is_active == true && x.id_company == Properties.Settings.Default.company_ID) != null)
                        {
                            PriceList_ID = db.item_price_list.Where(x => x.is_active == true && x.is_default == true && x.id_company == CurrentSession.Id_Company).FirstOrDefault().id_price_list;
                        }
                    }
                }

                //Step 1 1/2. Check if Quantity gets us a better Price List.


                //Step 2. Get Price in Currency.
                using (db db = new db())
                {
                    app_currencyfx app_currencyfx = null;
                    if (db.app_currencyfx.Where(x => x.id_currencyfx == CurrencyFX_ID).FirstOrDefault() != null)
                    {
                        app_currencyfx = db.app_currencyfx.Where(x => x.id_currencyfx == CurrencyFX_ID).FirstOrDefault();

                        //Check if we have available Price for this Product, Currency, and List.
                        item_price item_price = db.item_price.Where(x => x.id_item == id_item &&
                                                                    x.id_currency == app_currencyfx.id_currency &&
                                                                    x.id_price_list == PriceList_ID)
                                                .FirstOrDefault();

                        if (item_price != null)
                        {   //Return Perfect Value
                            return(item_price.value);
                        }
                        else
                        {
                            //If Perfect Value not found, get one pased on Product and List. (Ignore Currency and Convert Later basd on Current Rate.)
                            if (db.item_price.Where(x => x.id_item == id_item && x.id_price_list == PriceList_ID).FirstOrDefault() != null)
                            {
                                item_price     = db.item_price.Where(x => x.id_item == id_item && x.id_price_list == PriceList_ID).FirstOrDefault();
                                app_currencyfx = db.app_currencyfx.Where(x => x.id_currency == item_price.id_currency && x.is_active == true).FirstOrDefault();
                                return(Currency.convert_BackValue(item_price.value, app_currencyfx.id_currencyfx, App.Modules.Sales));
                            }
                        }
                    }
                }
            }

            return(0);
        }