public void return_ValueWithVAT() { int id_vat_group; if (id_item > 0) { using (db db = new db()) { id_vat_group = db.items.Where(x => x.id_item == id_item).FirstOrDefault().id_vat_group; } _valuewithVAT = Brillo.Vat.return_ValueWithVAT(id_vat_group, _value); } else { // id_vat_group = db.items.Where(x => x.id_item == id_item).FirstOrDefault().id_vat_group; _valuewithVAT = Brillo.Vat.return_ValueWithVAT(item.id_vat_group, _value); } RaisePropertyChanged("valuewithVAT"); }
public item New() { item item = new item(); item.State = System.Data.Entity.EntityState.Added; item.IsSelected = true; item.unit_cost = 0; using (db db = new db()) { if (db.app_vat_group.Where(x => x.is_default == true && x.id_company == CurrentSession.Id_Company).FirstOrDefault() != null) { item.id_vat_group = db.app_vat_group.Where(x => x.is_default == true && x.id_company == CurrentSession.Id_Company).FirstOrDefault().id_vat_group; } else { item.id_vat_group = 0; } } item.item_price.Add(New_ItemPrice(item)); return(item); }
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); }
public void ApproveImport() { foreach (impex impex in base.impex.Local.Where(x => x.status != Status.Documents_General.Approved && x.impex_type == entity.impex._impex_type.Import && x.IsSelected)) { if (impex.Error == null) { if (impex.id_impex == 0) { SaveChanges(); } //fill up virtual class List <entity.Class.Impex_CostDetail> ImpexImportDetails = Fill_ViewModel(impex); List <impex_expense> impex_expenses = impex.impex_expense.ToList(); if (ImpexImportDetails.Count > 0) { //To make sure we have a Purchase Total decimal purchaseTotal = ImpexImportDetails.Sum(i => i.sub_total); if (purchaseTotal != 0) { foreach (entity.Class.Impex_CostDetail Impex_CostDetail in ImpexImportDetails) { //Get total value of a Product Row decimal itemTotal = Impex_CostDetail.quantity * Impex_CostDetail.unit_cost; purchase_invoice purchase_invoice = base.purchase_invoice.Where(x => x.id_purchase_invoice == Impex_CostDetail.id_invoice).FirstOrDefault(); item_movement item_movement = base.item_movement.Where(x => x.id_purchase_invoice_detail == Impex_CostDetail.id_invoice_detail).FirstOrDefault(); foreach (impex_expense _impex_expense in impex_expenses) { decimal condition_value = _impex_expense.value; if (condition_value != 0 && itemTotal != 0) { //Coeficient is used to get prorated cost of one item item_movement_value item_movement_detail = new item_movement_value(); decimal Cost = Math.Round(_impex_expense.value / ImpexImportDetails.Sum(x => x.quantity), 2); //decimal Cost = Impex_CostDetail.unit_cost * coeficient; //Improve this in future. For now take from Purchase using (db db = new db()) { int ID_CurrencyFX_Default = CurrentSession.CurrencyFX_Default.id_currencyfx; decimal DefaultCurrency_Cost = Currency.convert_Values(Cost, purchase_invoice.id_currencyfx, ID_CurrencyFX_Default, null); item_movement_detail.unit_value = DefaultCurrency_Cost; item_movement_detail.id_currencyfx = ID_CurrencyFX_Default; } item_movement_detail.comment = _impex_expense.impex_incoterm_condition.name; if (item_movement != null) { item_movement.item_movement_value.Add(item_movement_detail); } } } } impex.status = Status.Documents_General.Approved; base.SaveChanges(); } } } } }
public static void Start(string UserName, string Password) { Security_CurdList = new List <security_curd>(); Security_role_privilageList = new List <security_role_privilage>(); using (db ctx = new db()) { //Set the User User = ctx.security_user.Where(x => x.name == UserName && x.password == Password && x.id_company == Id_Company) .FirstOrDefault(); UserRole = User.security_role; if (User != null) { //Set the User Id_User = User.id_user; Properties.Settings.Default.user_Name = User.name_full; Properties.Settings.Default.Save(); //Set the Company Id_Company = User.app_company.id_company; //Check if Branch Exists if (User.app_company.app_branch.Where(branch => branch.id_company == Id_Company && branch.id_branch == Properties.Settings.Default.branch_ID) .FirstOrDefault() != null) { Id_Branch = User.app_company.app_branch.Where(branch => branch.id_company == Id_Company && branch.id_branch == Properties.Settings.Default.branch_ID) .FirstOrDefault().id_branch; } //Check if Terminal Exists inside Branch if (ctx.app_terminal.Where(terminal => terminal.id_branch == Id_Branch && terminal.id_terminal == Properties.Settings.Default.terminal_ID) .FirstOrDefault() != null) { Id_Terminal = ctx.app_terminal.Where(terminal => terminal.id_branch == Id_Branch && terminal.id_terminal == Properties.Settings.Default.terminal_ID) .FirstOrDefault().id_terminal; } //Default Currency Currency_Default = ctx.app_currency.Where(x => x.is_priority && x.id_company == Id_Company).FirstOrDefault(); CurrencyFX_Default = Currency_Default.app_currencyfx.Where(x => x.is_active).FirstOrDefault(); //Setting Security, once CurrentSession Data is set. Refresh_Security(); //Basic Data like Salesman, Contracts, VAT, Currencies, etc to speed up Window Load. Load_BasicData(); } } }
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; }
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; }