Esempio n. 1
0
        private void sync_zone()
        {
            DataTable dt = exeDT("SELECT *,(select DESCIUDAD from CIUDAD where CIUDAD.CODCIUDAD=ZONA.CODCIUDAD) as DESCIUDAD FROM ZONA");

            foreach (DataRow row in dt.Rows)
            {
                app_geography app_geography = new app_geography();
                app_geography.code = (string)row["DESZONA"];
                app_geography.name = (string)row["DESZONA"];
                app_geography.type = Status.geo_types.Zone;
                if (!(row["DESCIUDAD"] is DBNull))
                {
                    string        name           = (string)row["DESCIUDAD"];
                    app_geography _app_geography = dbContext.app_geography.Where(x => x.name == name).FirstOrDefault();
                    if (_app_geography != null)
                    {
                        app_geography.parent = _app_geography;
                    }
                }


                dbContext.app_geography.Add(app_geography);
            }
            dt.Clear();
            dbContext.SaveChanges();
        }
Esempio n. 2
0
        private void SmartBox_Geography_Select(object sender, RoutedEventArgs e)
        {
            app_geography app_geography = (app_geography)objCollectionViewSource.View.CurrentItem;

            if (sbxGeo.GeographyID > 0)
            {
                app_geography.parent = entity.db.app_geography.Where(p => p.id_geography == sbxGeo.GeographyID).FirstOrDefault();
            }
        }
Esempio n. 3
0
        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            crud_modal.Visibility = System.Windows.Visibility.Visible;
            cntrl.Curd.Geography _Geography     = new cntrl.Curd.Geography();
            app_geography        _app_geography = new app_geography();

            entity.db.app_geography.Add(_app_geography);
            app_geographyViewSource.View.MoveCurrentToLast();
            _Geography.objCollectionViewSource = app_geographyViewSource;
            _Geography.entity = entity;
            crud_modal.Children.Add(_Geography);
        }
Esempio n. 4
0
        private void sync_country()
        {
            DataTable dt = exeDT("SELECT * FROM PAIS");

            foreach (DataRow row in dt.Rows)
            {
                app_geography app_geography = new app_geography();
                app_geography.code = (string)row["DESPAIS"];
                app_geography.name = (string)row["DESPAIS"];
                app_geography.type = Status.geo_types.Country;
                dbContext.app_geography.Add(app_geography);
            }
            dt.Clear();
            dbContext.SaveChanges();
        }
Esempio n. 5
0
        private void sync_state()
        {
            DataTable dt = exeDT("SELECT *,(select DESPAIS from PAIS where PAIS.CODPAIS=DEPARTAMENTO.CODPAIS) as DESPAIS FROM DEPARTAMENTO");

            foreach (DataRow row in dt.Rows)
            {
                app_geography app_geography = new app_geography();
                app_geography.code = (string)row["DESDEPARTAMENTO"];
                app_geography.name = (string)row["DESDEPARTAMENTO"];
                app_geography.type = Status.geo_types.State;
                string        name           = (string)row["DESPAIS"];
                app_geography _app_geography = dbContext.app_geography.Where(x => x.name == name).FirstOrDefault();
                if (_app_geography != null)
                {
                    app_geography.parent = _app_geography;
                }
                dbContext.app_geography.Add(app_geography);
            }
            dt.Clear();
            dbContext.SaveChanges();
        }
Esempio n. 6
0
        private void sync_city()
        {
            DataTable dt = exeDT("SELECT *,(select DESDEPARTAMENTO from DEPARTAMENTO where DEPARTAMENTO.CODDEPARTAMENTO=CIUDAD.CODDEPARTAMENTO) as DESDEPARTAMENTO,(select DESPAIS from PAIS where PAIS.CODPAIS=CIUDAD.CODPAIS) as DESPAIS FROM CIUDAD");

            foreach (DataRow row in dt.Rows)
            {
                app_geography app_geography = new app_geography();
                app_geography.code = (string)row["DESCIUDAD"];
                app_geography.name = (string)row["DESCIUDAD"];
                app_geography.type = Status.geo_types.City;
                if (row["DESDEPARTAMENTO"] is DBNull)
                {
                    if (!(row["DESPAIS"] is DBNull))
                    {
                        string        name           = (string)row["DESPAIS"];
                        app_geography _app_geography = dbContext.app_geography.Where(x => x.name == name).FirstOrDefault();
                        if (_app_geography != null)
                        {
                            app_geography.parent = _app_geography;
                        }
                    }
                }
                else
                {
                    string        name           = (string)row["DESDEPARTAMENTO"];
                    app_geography _app_geography = dbContext.app_geography.Where(x => x.name == name).FirstOrDefault();
                    if (_app_geography != null)
                    {
                        app_geography.parent = _app_geography;
                    }
                }

                dbContext.app_geography.Add(app_geography);
            }
            dt.Clear();
            dbContext.SaveChanges();
        }
Esempio n. 7
0
        public void customer()
        {
            string sql = " SELECT "
                         + " VENDEDOR.DESVENDEDOR,"
                         + " TIPOCLIENTE.DESTIPOCLIENTE, "
                         + " ZONA.DESZONA, "
                         + " CIUDAD.DESCIUDAD, "
                         + " PAIS.DESPAIS, "
                         + " CLIENTES.NUMCLIENTE, " //5
                         + " CLIENTES.NOMBRE, "
                         + " CLIENTES.RUC,"
                         + " CLIENTES.DIRECCION, "
                         + " CLIENTES.TELEFONO,"
                         + " CLIENTES.CELULAR, " //10
                         + " CLIENTES.FAX, "
                         + " CLIENTES.EMAIL, "
                         + " CLIENTES.WEB, "
                         + " CLIENTES.LIMCREDITO, "
                         + " CLIENTES.PORCENTAJE, " //15
                         + " CLIENTES.OBSERVACION, "
                         + " CLIENTES.SEPSA, "
                         + " CLIENTES.RELACION, "  // 18
                         + " CLIENTES.TIPOVENTA, "
                         + " CLIENTES.TELEFONO1, " //20
                         + " CLIENTES.EMAIL1, "
                         + " CLIENTES.DIASVENCIMIENTO, "
                         + " CLIENTES.CONDICIONVENTA, "
                         + " CLIENTES.NUMEROTOL, "
                         + " CLIENTES.PROVEEDOR_ID, " //25
                         + " CLIENTES.PERSONAJURIDICA, "
                         + " CLIENTES.TIMBRADORETENCION, "
                         + " CLIENTES.CODCATEGORIACLIENTE, "
                         + " CATEGORIACLIENTE.DESCATEGORIACLIENTE,"
                         + " CLIENTES.NOMBREFANTASIA, " //30
                         + " CLIENTES.CUSTOMFIELD, "
                         + " CLIENTES.CODCLIENTE, "
                         + " CLIENTES.SEXO, "
                         + " CLIENTES.FECHANACIMIENTO,"
                         + " CLIENTES.FECHAINGRESO,"   //35
                         + " PRODUCTOS.DESPRODUCTO,"
                         + " CLIENTES.EMPPRESACLIENTE" //35
                         + " FROM VENDEDOR "
                         + " RIGHT OUTER JOIN  CIUDAD RIGHT OUTER JOIN ZONA ON CIUDAD.CODCIUDAD = ZONA.CODCIUDAD RIGHT OUTER JOIN"
                         + " TIPOCLIENTE RIGHT OUTER JOIN CLIENTES LEFT OUTER JOIN CATEGORIACLIENTE ON CLIENTES.CODCATEGORIACLIENTE = CATEGORIACLIENTE.CODCATEGORIACLIENTE ON "
                         + " TIPOCLIENTE.CODTIPOCLIENTE = CLIENTES.CODTIPOCLIENTE ON ZONA.CODZONA = CLIENTES.CODZONA ON "
                         + " VENDEDOR.CODVENDEDOR = CLIENTES.CODVENDEDOR LEFT OUTER JOIN"
                         + " PAIS ON CIUDAD.CODPAIS = PAIS.CODPAIS  LEFT OUTER JOIN"
                         + " PRODUCTOS ON CLIENTES.PROVEEDOR_ID = PRODUCTOS.CODPRODUCTO ";

            SqlConnection conn = new SqlConnection(_connString);

            //Counts Total number of Rows we have to process
            SqlCommand cmd = new SqlCommand(sql, conn);

            conn.Open();
            cmd.CommandText = "SELECT COUNT(*) FROM CLIENTES";
            cmd.CommandType = CommandType.Text;
            int count = (int)cmd.ExecuteScalar();

            conn.Close();

            int value = 0;

            Dispatcher.BeginInvoke((Action)(() => customerMaximum.Text = count.ToString()));
            Dispatcher.BeginInvoke((Action)(() => customerValue.Text = value.ToString()));
            Dispatcher.BeginInvoke((Action)(() => progCustomer.Maximum = count));
            Dispatcher.BeginInvoke((Action)(() => progCustomer.Value = value));

            cmd = new SqlCommand(sql, conn);
            conn.Open();
            cmd.CommandType = CommandType.Text;
            // SqlDataReader reader = cmd.ExecuteReader();
            DataTable dt_customer = exeDT(sql);

            foreach (DataRow reader in dt_customer.Rows)
            {
                using (entity.db db = new entity.db())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    contact contacts = new contact();
                    contacts.id_company = id_company;

                    contacts.is_active   = true;
                    contacts.is_customer = true;
                    contacts.is_supplier = false;
                    contacts.is_employee = false;

                    if (!(reader[6] is DBNull))
                    {
                        contacts.name = reader[6].ToString();
                    }
                    else
                    {
                        continue;
                    }

                    contacts.code         = (reader[5] is DBNull) ? null : reader[5].ToString();
                    contacts.gov_code     = (reader[7] is DBNull) ? "xxx" : reader[7].ToString();
                    contacts.credit_limit = (reader[14] is DBNull) ? 0 : (decimal)reader[14];
                    contacts.address      = (reader[8] is DBNull) ? null : reader[8].ToString();
                    contacts.telephone    = (reader[9] is DBNull) ? null : reader[9].ToString();
                    contacts.email        = (reader[12] is DBNull) ? null : reader[12].ToString();
                    contacts.alias        = (reader[30] is DBNull) ? null : reader[30].ToString();

                    int    _dias        = Convert.ToInt32((reader["DIASVENCIMIENTO"] is DBNull) ? 0 : reader["DIASVENCIMIENTO"]);
                    string contrat_name = _dias + " " + "Días";
                    if (db.app_contract.Where(x => x.name == contrat_name).FirstOrDefault() != null)
                    {
                        app_contract app_contract = db.app_contract.Where(x => x.name == contrat_name).FirstOrDefault();
                        contacts.id_contract  = app_contract.id_contract;
                        contacts.app_contract = app_contract;
                    }

                    contacts.id_contact_role = db.contact_role.Where(x => x.is_principal == true && x.id_company == id_company).FirstOrDefault().id_contact_role;

                    if (_connString.Contains("Angelius"))
                    {
                        if (!(reader[18] is DBNull))
                        {
                            contacts.timestamp = Convert.ToDateTime(reader[35]);
                        }

                        contacts.is_person = true;

                        string role_name = (reader[31] is DBNull) ? null : reader[31].ToString();
                        if (db.contact_role.Where(x => x.name == role_name && x.id_company == id_company).FirstOrDefault() != null)
                        {
                            contacts.id_contact_role = db.contact_role.Where(x => x.name == role_name && x.id_company == id_company).FirstOrDefault().id_contact_role;
                        }
                        else
                        {
                            if (db.app_field.Where(x => x.field_type == app_field.field_types.Account).FirstOrDefault() != null)
                            {
                                app_field           app_field           = db.app_field.Where(x => x.field_type == app_field.field_types.Account).FirstOrDefault();
                                contact_field_value contact_field_value = new entity.contact_field_value();
                                contact_field_value.contact  = contacts;
                                contact_field_value.value    = role_name;
                                contact_field_value.id_field = app_field.id_field;
                                contacts.contact_field_value.Add(contact_field_value);
                            }
                        }

                        int relationid = Convert.ToInt32((reader[18] is DBNull) ? null : reader[18].ToString());
                        int code       = Convert.ToInt32((reader[32] is DBNull) ? null : reader[32].ToString());
                        if (relationid != code)
                        {
                            DataTable dt_newcustomer = exeDT("select NOMBRE from CLIENTES where CODCLIENTE=" + relationid);
                            string    name           = (dt_newcustomer.Rows[0][0]).ToString();
                            if (db.contacts.Where(x => x.name == name).FirstOrDefault() != null)
                            {
                                contacts.parent = db.contacts.Where(x => x.name == name).FirstOrDefault();
                            }
                        }

                        var SEXO = Convert.ToInt32((reader[33] is DBNull) ? null : reader[33].ToString());
                        if (SEXO != null)
                        {
                            if (SEXO == 0)
                            {
                                contacts.gender = contact.Genders.Male;
                            }
                            else
                            {
                                contacts.gender = contact.Genders.Female;
                            }
                        }

                        DateTime FECHANACIMINETO = Convert.ToDateTime((reader[34] is DBNull) ? null : reader[34].ToString());

                        if (FECHANACIMINETO != null)
                        {
                            if (FECHANACIMINETO.Year < 2014)
                            {
                                contacts.date_birth = FECHANACIMINETO;
                            }
                        }
                        contact_subscription contact_subscription = new contact_subscription();
                        if (!(reader[33] is DBNull))
                        {
                            if (Convert.ToInt32((reader[33])) > 0)
                            {
                                contact_subscription.unit_price = Convert.ToInt32((reader[33]));
                            }
                        }

                        if (!(reader[25] is DBNull))
                        {
                            string name = reader[36].ToString();
                            if (db.items.Where(x => x.name == name).FirstOrDefault() != null)
                            {
                                contact_subscription.id_item = db.items.Where(x => x.name == name).FirstOrDefault().id_item;
                                if (db.items.Where(x => x.name == name).FirstOrDefault() != null)
                                {
                                    contact_subscription.id_vat_group = db.items.Where(x => x.name == name).FirstOrDefault().id_vat_group;
                                }
                                else
                                {
                                    if (db.app_vat_group.Where(x => x.is_default).FirstOrDefault() != null)
                                    {
                                        contact_subscription.id_vat_group = db.app_vat_group.Where(x => x.is_default).FirstOrDefault().id_vat_group;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (contacts.parent != null)
                            {
                                contact_subscription.id_item = contacts.parent.contact_subscription.FirstOrDefault().id_item;

                                contact_subscription.id_vat_group = contacts.parent.contact_subscription.FirstOrDefault().id_vat_group;
                            }
                        }
                        if (db.app_contract.Where(x => x.is_active).FirstOrDefault() != null)
                        {
                            contact_subscription.id_contract = db.app_contract.Where(x => x.is_active).FirstOrDefault().id_contract;
                        }
                        contacts.contact_subscription.Add(contact_subscription);

                        if (!(reader[37] is DBNull))
                        {
                            string name = reader[37].ToString();
                            if (db.contact_tag.Local.Where(x => x.name == name).FirstOrDefault() == null)
                            {
                                if (reader[37].ToString() != "")
                                {
                                    contact_tag contact_tag = new contact_tag();
                                    contact_tag.name = reader[37].ToString();
                                    db.contact_tag.Add(contact_tag);
                                    contact_tag_detail contact_tag_detail = new contact_tag_detail();
                                    contact_tag_detail.contact     = contacts;
                                    contact_tag_detail.contact_tag = contact_tag;
                                    db.contact_tag_detail.Add(contact_tag_detail);
                                }
                            }
                            else
                            {
                                contact_tag_detail contact_tag_detail = new contact_tag_detail();
                                contact_tag_detail.contact     = contacts;
                                contact_tag_detail.contact_tag = db.contact_tag.Local.Where(x => x.name == name).FirstOrDefault();
                                db.contact_tag_detail.Add(contact_tag_detail);
                            }
                        }
                    }

                    if (!(reader["DESZONA"] is DBNull))
                    {
                        string        name           = (string)reader["DESZONA"];
                        app_geography _app_geography = db.app_geography.Where(x => x.name == name).FirstOrDefault();
                        if (_app_geography != null)
                        {
                            contacts.app_geography = _app_geography;
                            contacts.id_geography  = _app_geography.id_geography;
                        }
                    }
                    else if (!(reader["DESCIUDAD"] is DBNull))
                    {
                        string        name           = (string)reader["DESCIUDAD"];
                        app_geography _app_geography = db.app_geography.Where(x => x.name == name).FirstOrDefault();
                        if (_app_geography != null)
                        {
                            contacts.app_geography = _app_geography;
                            contacts.id_geography  = _app_geography.id_geography;
                        }
                    }
                    else if (!(reader["DESPAIS"] is DBNull))
                    {
                        string        name           = (string)reader["DESPAIS"];
                        app_geography _app_geography = db.app_geography.Where(x => x.name == name).FirstOrDefault();
                        if (_app_geography != null)
                        {
                            contacts.app_geography = _app_geography;
                            contacts.id_geography  = _app_geography.id_geography;
                        }
                    }

                    //db Related Insertion.
                    if (!(reader[1] is DBNull))
                    {
                        string          _price     = reader[1].ToString();
                        item_price_list price_list = db.item_price_list.Where(x => x.name == _price && x.id_company == id_company).FirstOrDefault();
                        contacts.id_price_list = price_list.id_price_list;
                    }

                    if (!(reader[0] is DBNull))
                    {
                        string    _sales_rep = reader[0].ToString();
                        sales_rep sales_rep  = db.sales_rep.Where(x => x.name == _sales_rep && x.id_company == id_company).FirstOrDefault();
                        contacts.id_sales_rep = (short)sales_rep.id_sales_rep;
                    }

                    if (contacts.Error == null)
                    {
                        db.contacts.Add(contacts);
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        value += 1;
                        Dispatcher.BeginInvoke((Action)(() => progCustomer.Value = value));
                        Dispatcher.BeginInvoke((Action)(() => customerValue.Text = value.ToString()));
                    }
                    else
                    {
                        //Add code to include error contacts into
                        Contact_ErrorList.Add(contacts);
                    }
                }
            }


            //cmd.Dispose();
            conn.Close();

            _customer_Current = _customer_Max;
        }
Esempio n. 8
0
        public void supplier()
        {
            string sql = " SELECT dbo.PROVEEDOR.NUMPROVEEDOR, dbo.PROVEEDOR.NOMBRE, dbo.PROVEEDOR.RUC_CIN, dbo.PROVEEDOR.DIRECCION, dbo.PROVEEDOR.TELEFONO, dbo.PROVEEDOR.EMAIL, dbo.PROVEEDOR.observacion, dbo.PROVEEDOR.CLIENTE_ID, dbo.PROVEEDOR.CONTACTO1, dbo.PROVEEDOR.CONTACTO2, dbo.PROVEEDOR.EMAILCONT1,"
                         + " dbo.PROVEEDOR.EMAILCONT2, dbo.PROVEEDOR.TELCONT1, dbo.PROVEEDOR.TELCONT2, dbo.PROVEEDOR.CELCONT1, dbo.PROVEEDOR.CELCONT2, dbo.PROVEEDOR.DIRECCIONCONT1, dbo.PROVEEDOR.DIRECCIONCONT2, dbo.PROVEEDOR.FORMAPAGO,"
                         + " dbo.PROVEEDOR.ESTADO, dbo.PROVEEDOR.DIASVENCIMIENTO, "
                         + " dbo.CATEGORIAPROVEEDOR.DESCATEGORIAPROVEEDOR, dbo.CENTROCOSTO.DESCENTRO, dbo.MONEDA.DESMONEDA,"
                         + " (select DESZONA from ZONA where ZONA.CODZONA=PROVEEDOR.CODZONA) as DESZONA,(select DESCIUDAD from CIUDAD where CIUDAD.CODCIUDAD=PROVEEDOR.CODCIUDAD) as DESCIUDAD,(select DESPAIS from PAIS where PAIS.CODPAIS=PROVEEDOR.CODPAIS) as DESPAIS"
                         + " FROM  dbo.PROVEEDOR LEFT OUTER JOIN"
                         + " dbo.CENTROCOSTO ON dbo.PROVEEDOR.CODCENTRO = dbo.CENTROCOSTO.CODCENTRO LEFT OUTER JOIN"
                         + " dbo.MONEDA ON dbo.PROVEEDOR.CODMONEDA = dbo.MONEDA.CODMONEDA LEFT OUTER JOIN"
                         + " dbo.CATEGORIAPROVEEDOR ON dbo.PROVEEDOR.CODCATEGORIAPROVEEDOR = dbo.CATEGORIAPROVEEDOR.CODCATEGORIAPROVEEDOR";

            SqlConnection conn = new SqlConnection(_connString);
            //Counts Total number of Rows we have to process
            SqlCommand cmd = new SqlCommand(sql, conn);

            conn.Open();
            cmd.CommandText = "SELECT COUNT(*) FROM PROVEEDOR";
            cmd.CommandType = CommandType.Text;
            int count = (int)cmd.ExecuteScalar();

            conn.Close();

            int value = 0;

            Dispatcher.BeginInvoke((Action)(() => progSupplier.Maximum = count));
            Dispatcher.BeginInvoke((Action)(() => progSupplier.Value = value));
            Dispatcher.BeginInvoke((Action)(() => supplierMaximum.Text = count.ToString()));
            Dispatcher.BeginInvoke((Action)(() => supplierValue.Text = value.ToString()));

            cmd = new SqlCommand(sql, conn);
            conn.Open();
            cmd.CommandType = CommandType.Text;
            //  SqlDataReader reader = cmd.ExecuteReader();
            DataTable dt_supplier = exeDT(sql);

            foreach (DataRow reader in dt_supplier.Rows)
            {
                using (entity.db db = new entity.db())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    contact contacts = new contact();
                    contacts.id_company = id_company;

                    if (!(reader[1] is DBNull))
                    {
                        contacts.name = reader[1].ToString();
                    }
                    else
                    {
                        continue;
                    }

                    if (!(reader[0] is DBNull))
                    {
                        string str = reader[0].ToString();
                        contacts.code = str;
                    }
                    else
                    {
                        contacts.code = "0";
                    }

                    contacts.gov_code    = ((reader[2] is DBNull) || reader[2].ToString() == string.Empty) ? "xxx" : reader[2].ToString();
                    contacts.is_active   = true;
                    contacts.is_customer = false;
                    contacts.is_supplier = true;
                    contacts.is_employee = false;
                    contacts.address     = (reader[3] is DBNull) ? null : reader[3].ToString();
                    contacts.telephone   = (reader[4] is DBNull) ? null : reader[4].ToString();
                    contacts.email       = (reader[5] is DBNull) ? null : reader[5].ToString();


                    int    _dias        = Convert.ToInt32((reader["DIASVENCIMIENTO"] is DBNull) ? 0 : reader["DIASVENCIMIENTO"]);
                    string contrat_name = _dias + " " + "Días";
                    if (db.app_contract.Where(x => x.name == contrat_name).FirstOrDefault() != null)
                    {
                        app_contract app_contract = db.app_contract.Where(x => x.name == contrat_name).FirstOrDefault();
                        contacts.id_contract  = app_contract.id_contract;
                        contacts.app_contract = app_contract;
                    }
                    //db Related Insertion.
                    if (!(reader[22] is DBNull))
                    {
                        string          CdC             = reader[22].ToString();
                        app_cost_center app_cost_center = db.app_cost_center.Where(x => x.name == CdC && x.id_company == id_company).FirstOrDefault();
                        contacts.id_cost_center = app_cost_center.id_cost_center;
                    }

                    contacts.id_contact_role = db.contact_role.Where(x => x.is_principal == true && x.id_company == id_company).FirstOrDefault().id_contact_role;

                    if (!(reader[23] is DBNull))
                    {
                        string       fx           = reader[23].ToString();
                        app_currency app_currency = db.app_currency.Where(x => x.name == fx && x.id_company == id_company).FirstOrDefault();
                        contacts.id_currency = (int)app_currency.id_currency;
                    }

                    if (!(reader["DESZONA"] is DBNull))
                    {
                        string        name           = (string)reader["DESZONA"];
                        app_geography _app_geography = db.app_geography.Where(x => x.name == name).FirstOrDefault();
                        if (_app_geography != null)
                        {
                            contacts.app_geography = _app_geography;
                            contacts.id_geography  = _app_geography.id_geography;
                        }
                    }
                    else if (!(reader["DESCIUDAD"] is DBNull))
                    {
                        string        name           = (string)reader["DESCIUDAD"];
                        app_geography _app_geography = db.app_geography.Where(x => x.name == name).FirstOrDefault();
                        if (_app_geography != null)
                        {
                            contacts.app_geography = _app_geography;
                            contacts.id_geography  = _app_geography.id_geography;
                        }
                    }
                    else if (!(reader["DESPAIS"] is DBNull))
                    {
                        string        name           = (string)reader["DESPAIS"];
                        app_geography _app_geography = db.app_geography.Where(x => x.name == name).FirstOrDefault();
                        if (_app_geography != null)
                        {
                            contacts.app_geography = _app_geography;
                            contacts.id_geography  = _app_geography.id_geography;
                        }
                    }

                    if (contacts.Error == null)
                    {
                        try
                        {
                            db.contacts.Add(contacts);
                            db.SaveChanges();
                            value += 1;
                            Dispatcher.BeginInvoke((Action)(() => progSupplier.Value = value));
                            Dispatcher.BeginInvoke((Action)(() => supplierValue.Text = value.ToString()));
                        }
                        catch
                        {
                            throw;
                        }
                    }
                    //db.Dispose();
                }
            }

            //cmd.Dispose();
            conn.Close();

            _supplier_Current = _supplier_Max;
        }