private void ButtonShowEdit_Click(object sender, RoutedEventArgs e) { MessageDialog Msg; try { long id = Convert.ToInt64(((TextBlock)DataGridCustomers.Columns[0].GetCellContent(DataGridCustomers.SelectedItem)).Text); CustomersTb RowEdited = Commons.Db.Customers.Find(id, Commons.CurrentYear); if (RowEdited != null) { CustomerId = id; TextBoxMeliCode.Text = RowEdited.MeliCode.Trim(); TextBoxName.Text = RowEdited.Name.Trim(); TextBoxFamily.Text = RowEdited.Family.Trim(); TextBoxFather.Text = RowEdited.Father.Trim(); TextBoxIdCard.Text = RowEdited.IdCard.Trim(); TextBoxCityCard.Text = RowEdited.CityCard.Trim(); TextBoxPhone.Text = RowEdited.Phone.Trim(); TextBoxCellPhone.Text = RowEdited.CellPhone.Trim(); TextBoxPostalCode.Text = RowEdited.PostalCode.Trim(); TextBoxAddress.Text = RowEdited.Address.Trim(); TextBoxComments.Text = RowEdited.Description.Trim(); ButtonCustomer_Click(ButtonCustomer, null); } else { Msg = new MessageDialog(Messages.EditMessageTitleCustomers, Messages.CustomerNotFound, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } } catch { Msg = new MessageDialog(Messages.EditMessageTitleCustomers, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } }
private void ReturnInfoCustomer(long CId) { MessageDialog Msg = null; try { CustomersTb Row = Commons.Db.Customers.Find(CId, Commons.CurrentYear); if (Row != null) { TextBlockName.Text = Row.Name; TextBlockFamily.Text = Row.Family; TextBlockFather.Text = Row.Father; TextBlockMelicode.Text = Row.MeliCode; TextBlockPostalCode.Text = Row.MeliCode; TextBlockAddress.Text = Row.Address; } else { Msg = new MessageDialog(Messages.SearchMessageTitleCustomers, Messages.NotFoundCustomers, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBlockName.Text = ""; TextBlockFamily.Text = ""; TextBlockFather.Text = ""; TextBlockMelicode.Text = ""; TextBlockPostalCode.Text = ""; TextBlockAddress.Text = ""; } } catch { Msg = new MessageDialog(Messages.SearchMessageTitleCustomers, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } }
private void TextBoxCustomerId_LostFocus(object sender, RoutedEventArgs e) { TextBox text = sender as TextBox; BindingOperations.GetBindingExpression(text, TextBox.TextProperty).UpdateSource(); MessageDialog Msg = null; try { bool IsValid = true; long CId = 0; try { CId = Convert.ToInt64(((TextBox)sender).Text); } catch { IsValid = false; Msg = new MessageDialog(Messages.SearchMessageTitleCustomers, Messages.ForceToCustomersId, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBlockName.Text = ""; TextBlockFamily.Text = ""; TextBlockFather.Text = ""; TextBlockMelicode.Text = ""; TextBlockPostalCode.Text = ""; TextBlockAddress.Text = ""; } if (IsValid == true) { CustomersTb Row = Commons.Db.Customers.Find(CId, Commons.CurrentYear); if (Row != null) { TextBlockName.Text = Row.Name; TextBlockFamily.Text = Row.Family; TextBlockFather.Text = Row.Father; TextBlockMelicode.Text = Row.MeliCode; TextBlockPostalCode.Text = Row.MeliCode; TextBlockAddress.Text = Row.Address; ((ComboBox)((ControlsTab)ControlsArray[sender]).Next).Focus(); ((ComboBox)((ControlsTab)ControlsArray[sender]).Next).IsDropDownOpen = true; } else { Msg = new MessageDialog(Messages.SearchMessageTitleCustomers, Messages.NotFoundCustomers, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBlockName.Text = ""; TextBlockFamily.Text = ""; TextBlockFather.Text = ""; TextBlockMelicode.Text = ""; TextBlockPostalCode.Text = ""; TextBlockAddress.Text = ""; } } } catch { Msg = new MessageDialog(Messages.SearchMessageTitleCustomers, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } }
private void ButtonDelete_Click(object sender, RoutedEventArgs e) { MessageDialog Msg; try { long id = Convert.ToInt64(((TextBlock)DataGridCustomers.Columns[0].GetCellContent(DataGridCustomers.SelectedItem)).Text); CustomersTb RowDeleted = Commons.Db.Customers.Find(id, Commons.CurrentYear); if (RowDeleted != null) { var Sub = Commons.Db.Subscriptions.Where(x => x.Customer.Id == id && x.Customer.Year == Commons.CurrentYear); if (Sub.Count <SubscriptionsTb>() == 0) { try { Msg = new MessageDialog(Messages.DeleteMessageTitleCustomers, Messages.DeleteMessageCustomers, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); if (Msg.ShowDialog() == true) { Commons.Db.Customers.Remove(RowDeleted); Commons.Db.SaveChanges(); Commons.SetFromEdited("Customers"); List <CustomersTb> L = (List <CustomersTb>)DataGridCustomers.ItemsSource; if (L != null) { L.Remove(RowDeleted); } DataGridCustomers.Items.Refresh(); SearchAgain = true; Msg = new MessageDialog(Messages.DeleteMessageTitleCustomers, Messages.DeleteMessageSuccessCustomers, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } } catch { Msg = new MessageDialog(Messages.DeleteMessageTitleCustomers, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } } else { Msg = new MessageDialog(Messages.DeleteMessageTitleCustomers, Messages.DeleteCustomerImpossible, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } } else { Msg = new MessageDialog(Messages.DeleteMessageTitleCustomers, Messages.CustomerNotFound, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } } catch { Msg = new MessageDialog(Messages.DeleteMessageTitleCustomers, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } }
private void ButtonSave_Click(object sender, RoutedEventArgs e) { ControlsValidate?Vd = Commons.ValidateData(FirstControlNew, ControlsArray); MessageDialog Msg = null; if (Vd != null) { Msg = new MessageDialog(Messages.SaveMessageTitleCustomers, Vd.Value.Message, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); Vd.Value.Control.Focus(); } else { DomainClasses.CustomersTb MyCustomer = null; if (CustomerId != -1) { MyCustomer = Commons.Db.Customers.Find(CustomerId, Commons.CurrentYear); } if (MyCustomer == null) { Msg = new MessageDialog(Messages.SaveMessageTitleCustomers, Messages.SaveMessageCustomers, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); if (Msg.ShowDialog() == true) { try { int?MaxId = Commons.Db.Customers.Where(x => x.Year == Commons.CurrentYear).Max(x => (int?)x.Id); if (MaxId == null) { MaxId = 0; } MaxId++; Commons.Db.Customers.Add(new DomainClasses.CustomersTb { Id = Convert.ToInt32(MaxId), Year = Commons.CurrentYear, MeliCode = TextBoxMeliCode.Text.Trim(), Name = TextBoxName.Text.Trim(), Family = TextBoxFamily.Text.Trim(), Father = TextBoxFather.Text.Trim(), Search = TextBoxName.Text.Trim() + " " + TextBoxFamily.Text.Trim() + " " + TextBoxFather.Text.Trim(), IdCard = TextBoxIdCard.Text.Trim(), CityCard = TextBoxCityCard.Text.Trim(), Phone = TextBoxPhone.Text.Trim(), CellPhone = TextBoxCellPhone.Text.Trim(), PostalCode = TextBoxPostalCode.Text.Trim(), Address = TextBoxAddress.Text.Trim(), Description = TextBoxComments.Text.Trim() }); Commons.Db.SaveChanges(); Commons.SetFromEdited("Customers"); DataGridCustomers.Items.Refresh(); SearchAgain = true; Msg = new MessageDialog(Messages.SaveMessageTitleCustomers, Messages.SaveMessageSuccessCustomers, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); ButtonNew_Click(null, null); } catch (Exception Ex) { if (Ex.InnerException != null) { if (Ex.InnerException.InnerException != null && Ex.InnerException.InnerException is SqlException) { SqlException SEx = (SqlException)Ex.InnerException.InnerException; if (SEx.Message.Contains("IX_Unique_CustomersTbs_MeliCode")) { Msg = new MessageDialog(Messages.SaveMessageTitleCustomers, Messages.MeliCodeIsRepetitive, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBoxMeliCode.Focus(); TextBoxMeliCode.SelectAll(); } } } else { Msg = new MessageDialog(Messages.SaveMessageTitleCustomers, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } } } } else { Msg = new MessageDialog(Messages.EditMessageTitleCustomers, Messages.EditMessageCustomers, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); if (Msg.ShowDialog() == true) { try { MyCustomer.MeliCode = TextBoxMeliCode.Text.Trim(); MyCustomer.Name = TextBoxName.Text.Trim(); MyCustomer.Family = TextBoxFamily.Text.Trim(); MyCustomer.Father = TextBoxFather.Text.Trim(); MyCustomer.Search = TextBoxName.Text.Trim() + " " + TextBoxFamily.Text.Trim() + " " + TextBoxFather.Text.Trim(); MyCustomer.IdCard = TextBoxIdCard.Text.Trim(); MyCustomer.CityCard = TextBoxCityCard.Text.Trim(); MyCustomer.Phone = TextBoxPhone.Text.Trim(); MyCustomer.CellPhone = TextBoxCellPhone.Text.Trim(); MyCustomer.PostalCode = TextBoxPostalCode.Text.Trim(); MyCustomer.Address = TextBoxAddress.Text.Trim(); MyCustomer.Description = TextBoxComments.Text.Trim(); Commons.Db.SaveChanges(); Commons.SetFromEdited("Customers"); List <CustomersTb> Lc = (List <CustomersTb>)DataGridCustomers.ItemsSource; if (Lc != null) { CustomersTb Rc = Lc.Find(x => x.Id == CustomerId && x.Year == Commons.CurrentYear); if (Rc != null) { Rc.MeliCode = TextBoxMeliCode.Text.Trim(); Rc.Name = TextBoxName.Text.Trim(); Rc.Family = TextBoxFamily.Text.Trim(); Rc.Father = TextBoxFather.Text.Trim(); Rc.Search = TextBoxName.Text.Trim() + " " + TextBoxFamily.Text.Trim() + " " + TextBoxFather.Text.Trim(); Rc.IdCard = TextBoxIdCard.Text.Trim(); Rc.CityCard = TextBoxCityCard.Text.Trim(); Rc.Phone = TextBoxPhone.Text.Trim(); Rc.CellPhone = TextBoxCellPhone.Text.Trim(); Rc.PostalCode = TextBoxPostalCode.Text.Trim(); Rc.Address = TextBoxAddress.Text.Trim(); Rc.Description = TextBoxComments.Text.Trim(); } } DataGridCustomers.Items.Refresh(); SearchAgain = true; Msg = new MessageDialog(Messages.EditMessageTitleCustomers, Messages.EditMessageSuccessCustomers, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); ButtonNew_Click(null, null); } catch (Exception Ex) { if (Ex.InnerException != null) { if (Ex.InnerException.InnerException != null && Ex.InnerException.InnerException is SqlException) { SqlException SEx = (SqlException)Ex.InnerException.InnerException; if (SEx.Message.Contains("IX_Unique_CustomersTbs_MeliCode")) { Msg = new MessageDialog(Messages.SaveMessageTitleCustomers, Messages.MeliCodeIsRepetitive, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBoxMeliCode.Focus(); TextBoxMeliCode.SelectAll(); } } } else { Msg = new MessageDialog(Messages.SaveMessageTitleCustomers, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeaderCustomers.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); } } } } } }