Exemple #1
0
        private void Update_Click(object sender, RoutedEventArgs e)
        {
            bool   error = false;
            double price = 0;
            int    cant  = 0;

            if (PN.Text.Contains(".") || PN.Text.Contains("-") || PN.Text.Contains(",") || PN.Text.Contains("/"))
            {
                MessageBox.Show("Error.\nEstos simbolos no son admisibles: . - , /", "Añadir elemento", MessageBoxButton.OK, MessageBoxImage.Error);
                error = true;
            }
            if (PI.Text.Contains(".") || PI.Text.Contains("-") || PI.Text.Contains(",") || PI.Text.Contains("/"))
            {
                MessageBox.Show("Error.\nEstos simbolos no son admisibles: . - , /", "Añadir elemento", MessageBoxButton.OK, MessageBoxImage.Error);
                error = true;
            }
            try
            {
                price = double.Parse(Price.Text);
                cant  = int.Parse(Cant.Text);
            }
            catch (FormatException err)
            {
                MessageBox.Show("Error.\n" + err.Message, "Añadir elemento", MessageBoxButton.OK, MessageBoxImage.Error);
                error = true;
            }
            if (WindowMode == 0 && !error)
            {
                int index = InventoryIO.items.IndexOf(InventoryWindow.info);
                InventoryIO.items.RemoveAt(index);
                InventoryInfo info = new InventoryInfo()
                {
                    SKU = int.Parse(SKU.Text), ProductName = PI.Text, ProductInfo = PN.Text, Price = double.Parse(Price.Text), Cant = int.Parse(Cant.Text)
                };
                InventoryIO.items.Insert(index, info);
                InventoryIO.InventorySet();
                MessageBox.Show("Refresque la lista de items al salir", "Modificar Item", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                this.Close();
            }
            if (WindowMode == 1 && !error)
            {
                ToAdd.SKU         = int.Parse(SKU.Text);
                ToAdd.ProductName = PI.Text;
                ToAdd.ProductInfo = PN.Text;
                ToAdd.Price       = price;
                ToAdd.Cant        = cant;
                InventoryIO.items.Add(ToAdd);
                InventoryIO.InventorySet();
                MessageBox.Show("Refresque la lista de items al salir", "Modificar Item", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                this.Close();
            }
        }
Exemple #2
0
 public ModifyAssistant()
 {
     InitializeComponent();
     if (WindowMode == 0)
     {
         InventoryInfo info = InventoryWindow.info;
         Element_Label.Content = "SKU de elemento a modificar: " + info.SKU.ToString();
         SKU.Text   = info.SKU.ToString();
         PI.Text    = info.ProductName;
         PN.Text    = info.ProductInfo;
         Price.Text = info.Price.ToString();
         Cant.Text  = info.Cant.ToString();
     }
     if (WindowMode == 1)
     {
         int           legth        = InventoryIO.items.Count();
         InventoryInfo lastSKU_info = InventoryIO.items.ElementAt(legth - 1);
         Element_Label.Content = "Añadir un nuevo item: ";
         SKU.Text       = (lastSKU_info.SKU + 1).ToString();
         Update.Content = "➕Añadir";
     }
 }
        private void LookAddItem_Click(object sender, RoutedEventArgs e)
        {
            bool          error     = false;
            bool          found     = false;
            string        cant_temp = "";
            int           LookSKU   = -1;
            InventoryInfo itemGet   = new InventoryInfo();
            Items         itemToAdd = new Items();

            try
            {
                LookSKU = int.Parse(AddItem.Text);
                error   = false;
            }
            catch (FormatException err)
            {
                MessageBox.Show("Ocurrio un error. " + err.Message, "Añadir Item", MessageBoxButton.OK, MessageBoxImage.Error);
                error = true;
            }
            if (!error)
            {
                foreach (InventoryInfo element in InventoryIO.items)
                {
                    if (element.SKU == LookSKU)
                    {
                        itemGet = element;
                        found   = true;
                    }
                }
                if (found)
                {
                    bool error1 = true;
                    int  cant   = 0;
                    while (error1)
                    {
                        cant_temp = (Interaction.InputBox("Ingrese la cantidad de productos: (Deje en blanco para cancelar o presione Cancelar)", "Añadir productos", "0"));
                        if (cant_temp != "")
                        {
                            try
                            {
                                cant   = int.Parse(cant_temp);
                                error1 = false;
                            }
                            catch (FormatException err)
                            {
                                error1 = true;
                                MessageBox.Show("Ocurrio un error. " + err.Message, "Añadir Item", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                            if (!error1)
                            {
                                if (cant > 0)
                                {
                                    itemToAdd.Cant        = cant;
                                    itemToAdd.SKU         = itemGet.SKU;
                                    itemToAdd.PI          = itemGet.ProductInfo;
                                    itemToAdd.PN          = itemGet.ProductName;
                                    itemToAdd.Unit        = itemGet.Price;
                                    itemToAdd.UnitStr     = String.Format("{0:$#.00}", itemToAdd.Unit);
                                    itemToAdd.PriceAll    = cant * itemGet.Price;
                                    itemToAdd.PriceAllStr = String.Format("{0:$#.00}", itemToAdd.PriceAll);
                                    items.Add(itemToAdd);
                                    ItemList.Items.Refresh();
                                    AddItem.Text = null;
                                    RefreshTotal();
                                    SoundPlayer beep = new SoundPlayer(Directory.GetCurrentDirectory() + @"\\sounds\\beep.wav");
                                    beep.Play();
                                }
                                else if (cant <= 0)
                                {
                                    MessageBox.Show("Ocurrio un error.\nLa cantidad de productos no puede ser inferior o igual a 0", "Añadir productos", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }
                        }
                        else if (cant_temp == "")
                        {
                            return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Ocurrio un error.\nNo se encontro el elemento.", "Añadir Item", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }