Beispiel #1
0
        private void btDelete_Click(object sender, EventArgs e)
        {
            if (listViewLotes.SelectedItems.Count == 0)
            {
                MessageBox.Show("Por favor, selecione um lote.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (!Firebird.UserHasPermission(1))
            {
                return;
            }

            if (MessageBox.Show("Tem certeza que deseja excluir o lote selecionado?", "Tem Certeza?", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Lote lote = new Lote();
                lote = Firebird.ReturnLote(listViewLotes.SelectedItems[0].SubItems[0].Text, Convert.ToInt32(listViewLotes.SelectedItems[0].SubItems[1].Text),
                                           listViewLotes.SelectedItems[0].SubItems[3].Text);
                Firebird.DeleteAll(lote);

                for (int i = listaLotes.Count - 1; i >= 0; i--)
                {
                    if (listaLotes[i].Maquina == lote.Maquina && listaLotes[i].NumLote == lote.NumLote && listaLotes[i].Calendario == lote.Calendario)
                    {
                        listaLotes.RemoveAt(i);
                    }
                }
            }
            else
            {
                return;
            }
            WriteFilterLotes(listaLotes);
        }
        // Retirado pois agora salva de modo automático
        //private void btSalvarLote_Click(object sender, EventArgs e)
        //{
        //    if (lote == null || listaLeituras.Count == 0) return;
        //    if (!Firebird.UserHasPermission(0)) return;

        //    var lista = Firebird.ReturnListMaquina();
        //    bool Exists = false;
        //    foreach (var item in lista)
        //    {
        //        if (item == CurrentMachine)
        //        {
        //            Exists = true;
        //            break;
        //        }
        //    }

        //    if (!Exists)
        //    {
        //        DialogResult result = MessageBox.Show("Máquina não registrada, deseja salvá-la?", "Aviso", MessageBoxButtons.YesNo);
        //        if (result == DialogResult.Yes)
        //        {
        //            NovaMaquina form = new NovaMaquina(this);
        //            form.ShowDialog();

        //            if (!form.MachineSaved) return;
        //        }
        //        else return;
        //    }

        //    lote.Usuario = CurrentUser.UserName;
        //    Firebird.SaveNewLote(lote);
        //    Firebird.SaveLeituras(listaLeituras);

        //    MessageBox.Show("Lote salvo com sucesso!", "Sucesso!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        //    lbExistente.Text = "Lote Salvo!";

        //    btSalvarLote.Enabled = false;
        //}
        public void SalvarLote()
        {
            if (lote == null || listaLeituras.Count == 0)
            {
                return;
            }
            if (!Firebird.UserHasPermission(0))
            {
                return;
            }

            if (!Firebird.LoteExists(lote))
            {
                var  lista  = Firebird.ReturnListMaquina();
                bool Exists = false;
                foreach (var item in lista)
                {
                    if (item == CurrentMachine)
                    {
                        Exists = true;
                        break;
                    }
                }

                if (!Exists)
                {
                    DialogResult result = MessageBox.Show("Máquina não registrada, deseja salvá-la?", "Aviso", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        NovaMaquina form = new NovaMaquina(this);
                        form.ShowDialog();

                        if (!form.MachineSaved)
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }

                lote.Usuario = CurrentUser.UserName;
                Firebird.SaveNewLote(lote);
                Firebird.SaveLeituras(listaLeituras);

                MessageBox.Show("Lote salvo com sucesso!", "Sucesso!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                lbExistente.Text = "Lote Salvo!";
            }
            else if (Firebird.LoteExists(lote))
            {
                if (Firebird.ReturnLeituras(lote).LastOrDefault() != Firebird.ReturnLeituras(lote).FirstOrDefault())
                {
                    Firebird.DeleteAll(lote);
                    lote.Usuario = CurrentUser.UserName;
                    Firebird.SaveNewLote(lote);
                    Firebird.SaveLeituras(listaLeituras);
                    //MessageBox.Show("Lote atualizado com sucesso!", "Sucesso!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                return;
            }
        }