Пример #1
0
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            crud_modal.Visibility = System.Windows.Visibility.Visible;
            cntrl.Curd.price_list objPriceList    = new cntrl.Curd.price_list();
            item_price_list       item_price_list = new item_price_list();

            entity.db.item_price_list.Add(item_price_list);
            item_price_listViewSource.View.MoveCurrentToLast();
            objPriceList.item_price_listViewSource = item_price_listViewSource;
            objPriceList._entity = entity;
            crud_modal.Children.Add(objPriceList);
        }
Пример #2
0
        private void sync_PriceList()
        {
            DataTable dt = exeDT("SELECT * FROM TIPOCLIENTE");

            foreach (DataRow row in dt.Rows)
            {
                item_price_list price = new item_price_list();
                price.name       = (string)row["DESTIPOCLIENTE"];
                price.id_company = id_company;
                price.is_active  = true;
                dbContext.item_price_list.Add(price);
            }
            dt.Clear();
            dbContext.SaveChanges();
        }
Пример #3
0
        private void EditPricelist_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            item_price      item_price      = item_priceDataGrid.SelectedItem as item_price;
            item_price_list item_price_list = item_price.item_price_list;

            if (item_price_list != null)
            {
                crud_modal.Visibility = Visibility.Visible;
                cntrl.Curd.price_list _price_list = new cntrl.Curd.price_list();
                _price_list.item_price_listViewSource = item_price_listViewSource;
                _price_list.MainViewSource            = itemViewSource;
                _price_list.curMainObject             = itemViewSource.View.CurrentItem;
                // _price_list._entity = dbContext;
                _price_list.price_listobject = item_price_list;
                _price_list.operationMode    = cntrl.Class.clsCommon.Mode.Edit;
                _price_list.isExternalCall   = true;
                crud_modal.Children.Add(_price_list);
            }
        }
Пример #4
0
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (!isExternalCall)
         {
             MessageBoxResult res = MessageBox.Show("Are you sure want to Delete?", "Cognitivo", MessageBoxButton.YesNo, MessageBoxImage.Question);
             if (res == MessageBoxResult.Yes)
             {
                 item_price_list item_price_list = item_price_listViewSource.View.CurrentItem as entity.item_price_list;
                 item_price_list.is_active = false;
                 btnSave_Click(sender, e);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #5
0
        public void product()
        {
            string sql = " SELECT dbo.FAMILIA.DESFAMILIA, dbo.LINEA.DESLINEA, dbo.RUBRO.DESRUBRO, dbo.IVA.DESIVA, dbo.CODIGOS.DESCODIGO1, dbo.CODIGOS.CODIGO, dbo.CODIGOS.PESABLE, dbo.CODIGOS.VENCIMIENTO, dbo.CODIGOS.BALANZA, dbo.PRODUCTOS.DESPRODUCTO, dbo.PRODUCTOS.STOCKMINIMO, dbo.PRODUCTOS.STOCKMAXIMO, "
                         + " dbo.PRODUCTOS.SERVICIO, dbo.PRODUCTOS.ESTADO, dbo.PRODUCTOS.ESPECIFICACIONES, dbo.PRODUCTOS.PRODUCTO, dbo.UNIDADMEDIDA.DESMEDIDA, dbo.CODIGOS.CODCODIGO"
                         + " FROM dbo.CODIGOS LEFT OUTER JOIN"
                         + " dbo.PRODUCTOS ON dbo.CODIGOS.CODPRODUCTO = dbo.PRODUCTOS.CODPRODUCTO LEFT OUTER JOIN"
                         + " dbo.UNIDADMEDIDA ON dbo.PRODUCTOS.CODMEDIDA = dbo.UNIDADMEDIDA.CODMEDIDA LEFT OUTER JOIN"
                         + " dbo.RUBRO ON dbo.PRODUCTOS.CODRUBRO = dbo.RUBRO.CODRUBRO LEFT OUTER JOIN"
                         + " dbo.FAMILIA ON dbo.PRODUCTOS.CODFAMILIA = dbo.FAMILIA.CODFAMILIA LEFT OUTER JOIN"
                         + " dbo.LINEA ON dbo.PRODUCTOS.CODLINEA = dbo.LINEA.CODLINEA LEFT OUTER JOIN"
                         + " dbo.IVA ON dbo.PRODUCTOS.CODIVA = dbo.IVA.CODIVA";

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

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

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

            int value = 0;

            Dispatcher.BeginInvoke((Action)(() => progItem.Maximum = count));
            Dispatcher.BeginInvoke((Action)(() => progItem.Value += value));
            Dispatcher.BeginInvoke((Action)(() => itemMaximum.Text = count.ToString()));
            Dispatcher.BeginInvoke((Action)(() => itemValue.Text = value.ToString()));

            string sql_price = " SELECT dbo.TIPOCLIENTE.DESTIPOCLIENTE, dbo.PRECIO.CANTIDAD, dbo.PRECIO.PRECIOVENTA, dbo.MONEDA.DESMONEDA, dbo.PRODUCTOS.DESPRODUCTO"
                               + " FROM  dbo.PRECIO LEFT OUTER JOIN"
                               + " dbo.MONEDA ON dbo.PRECIO.CODMONEDA = dbo.MONEDA.CODMONEDA LEFT OUTER JOIN"
                               + " dbo.PRODUCTOS ON dbo.PRECIO.CODPRODUCTO = dbo.PRODUCTOS.CODPRODUCTO LEFT OUTER JOIN"
                               + " dbo.TIPOCLIENTE ON dbo.PRECIO.CODTIPOCLIENTE = dbo.TIPOCLIENTE.CODTIPOCLIENTE";
            DataTable dt_Price = exeDT(sql_price);

            conn.Open();
            cmd.Connection  = conn;
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.Text;
            DataTable dt_product = exeDT(sql);

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

                    item item = new item();
                    item.id_company = id_company;

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

                    item.code        = (reader[5] is DBNull) ? string.Empty : reader[5].ToString();
                    item.variation   = (reader[9] is DBNull) ? string.Empty : reader[9].ToString();
                    item.is_active   = (reader[13] is DBNull) ? false : true;
                    item.description = (reader[14] is DBNull) ? string.Empty : reader[14].ToString();

                    string name = (reader[16] is DBNull) ? string.Empty : reader[16].ToString();
                    if (db.app_measurement.Where(x => x.name == name && x.id_company == id_company).FirstOrDefault() != null)
                    {
                        item.id_measurement = db.app_measurement.Where(x => x.name == name && x.id_company == id_company).FirstOrDefault().id_measurement;
                    }

                    //string FAMILIA;
                    if (!(reader[0] is DBNull))
                    {
                        string          tagname       = reader[0].ToString();
                        item_tag        item_tagFam   = db.item_tag.Where(x => x.name == tagname && x.id_company == id_company).FirstOrDefault();
                        item_tag_detail tag_detailFam = new item_tag_detail();
                        tag_detailFam.id_tag = item_tagFam.id_tag;
                        item.item_tag_detail.Add(tag_detailFam);
                    }

                    //string LINEA;
                    if (!(reader[1] is DBNull))
                    {
                        string          tagLinname    = reader[1].ToString();
                        item_tag        item_tagLin   = db.item_tag.Where(x => x.name == tagLinname && x.id_company == id_company).FirstOrDefault();
                        item_tag_detail tag_detailLin = new item_tag_detail();
                        tag_detailLin.id_tag = item_tagLin.id_tag;
                        item.item_tag_detail.Add(tag_detailLin);
                    }

                    //string RUBRO;
                    if (!(reader[2] is DBNull))
                    {
                        string          tagrubro      = reader[2].ToString();
                        item_tag        item_tagRub   = db.item_tag.Where(x => x.name == tagrubro && x.id_company == id_company).FirstOrDefault();
                        item_tag_detail tag_detailRub = new item_tag_detail();
                        tag_detailRub.id_tag = item_tagRub.id_tag;
                        item.item_tag_detail.Add(tag_detailRub);
                    }

                    if (!(reader[15] is DBNull))
                    {
                        if (Convert.ToInt32(reader[15]) == 1)
                        {
                            //Product
                            item.id_item_type = item.item_type.Product;

                            item_product product = new item_product();
                            product.id_company = id_company;
                            product.can_expire = (reader[7] is DBNull || Convert.ToInt32(reader[7]) == 0) ? false : true;
                            product.is_weigted = (reader[6] is DBNull || Convert.ToInt32(reader[6]) == 0) ? false : true;
                            product.stock_max  = (reader[11] is DBNull) ? 0M : (decimal)reader[11];
                            product.stock_min  = (reader[10] is DBNull) ? 0M : (decimal)reader[10];
                            item.item_product.Add(product);
                        }
                        else
                        {
                            item.id_item_type = item.item_type.Task; //Generic Service
                            //item_service service
                        }
                    }
                    else
                    {
                        item.id_item_type = item.item_type.Task; //Generic Service
                        //item_service service
                    }
                    decimal _vat_coeficient = 0;

                    if (!(reader[3] is DBNull))
                    {
                        string        vatname       = reader[3].ToString();
                        app_vat_group app_vat_group = db.app_vat_group.Where(x => x.name == vatname && x.id_company == id_company).FirstOrDefault();
                        item.id_vat_group = app_vat_group.id_vat_group;
                    }

                    decimal coefficient = 0;
                    List <app_vat_group_details> app_vat_group_details = db.app_vat_group_details.Where(x => x.id_vat_group == item.id_vat_group).ToList();

                    foreach (app_vat_group_details app_vat_group in app_vat_group_details)
                    {
                        coefficient = coefficient + app_vat_group.app_vat.coefficient;
                    }

                    string _DESPRODUCTO = reader["DESPRODUCTO"].ToString();
                    _DESPRODUCTO = _DESPRODUCTO.Replace("'", "");
                    try
                    {
                        foreach (DataRow price_row in dt_Price.Select("DESPRODUCTO = '" + _DESPRODUCTO + "'"))
                        {
                            string _desTipoCliente = (price_row.IsNull("DESTIPOCLIENTE")) ? string.Empty : price_row["DESTIPOCLIENTE"].ToString();
                            string _desMoneda      = (price_row.IsNull("DESMONEDA")) ? string.Empty : price_row["DESMONEDA"].ToString();

                            if (_desTipoCliente != string.Empty && _desMoneda != string.Empty)
                            {
                                item_price_list item_price_list = db.item_price_list.Where(x => x.name == _desTipoCliente && x.id_company == id_company).FirstOrDefault();
                                app_currency    app_currency    = db.app_currency.Where(x => x.name == _desMoneda && x.id_company == id_company).FirstOrDefault();

                                if (item_price_list != null && app_currency != null && _vat_coeficient != -1)
                                {
                                    item_price item_price = new item_price();
                                    item_price.item = item;
                                    if (price_row["PRECIOVENTA"] is DBNull)
                                    {
                                        item_price.value = 0;
                                    }
                                    else
                                    {
                                        if (coefficient != -1)
                                        {
                                            item_price.value = ((decimal)price_row["PRECIOVENTA"] / (1 + coefficient));
                                        }
                                    }
                                    item_price.min_quantity  = (price_row.IsNull("CANTIDAD")) ? 0 : Convert.ToDecimal(price_row["CANTIDAD"]);
                                    item_price.id_currency   = app_currency.id_currency;
                                    item_price.id_price_list = item_price_list.id_price_list;
                                    item.item_price.Add(item_price);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    try
                    {
                        if (item.Error == null)
                        {
                            db.items.Add(item);
                            db.SaveChanges();
                            value += 1;
                            Dispatcher.BeginInvoke((Action)(() => progItem.Value = value));
                            Dispatcher.BeginInvoke((Action)(() => itemValue.Text = value.ToString()));
                        }
                    }
                    catch { }
                }
            }


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

            _product_Current = _product_Max;
        }
Пример #6
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;
        }