Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndices == null)
            {
                MessageBox.Show("Nu ati selectat niciun element!", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            using (FacturiContext context = new FacturiContext()) {
                DialogResult result = MessageBox.Show("Sunteti sigur ca doriti salvarea template-ului in baza de date?", "Template", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                if (result == DialogResult.OK)
                {
                    TemplateExportBanci temp = new TemplateExportBanci();
                    List <string>       elementeSelectate = new List <string>();
                    foreach (int x in listBox1.SelectedIndices)
                    {
                        elementeSelectate.Add(listBox1.Items[x].ToString());
                    }

                    temp.Template = string.Join(",", elementeSelectate);

                    if (templateBanci == null)
                    {
                        templateBanci = new TemplateExportBanci();
                    }

                    templateBanci.Template  = temp.Template;
                    templateBanci.NumeBanca = comboBox1.Text;

                    if (context.TemplateExportBanci.Any(x => x.NumeBanca == comboBox1.Text))
                    {
                        context.Entry <TemplateExportBanci>(templateBanci).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        context.Entry <TemplateExportBanci>(templateBanci).State = System.Data.Entity.EntityState.Added;
                    }

                    context.SaveChanges();
                }
            }
        }
Beispiel #2
0
        public static void salveazaScenariuInBd(List <Tranzactie> scenariu)
        {
            using (FacturiContext context = new FacturiContext()) {
                // Exporta in fisier (TUDOR)

                /*CommonOpenFileDialog dialog = new CommonOpenFileDialog();
                 * dialog.InitialDirectory = "C:";
                 * dialog.IsFolderPicker = true;
                 * dialog.ShowDialog();*/
                /* if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                 * {
                 *   MessageBox.Show("You selected: " + dialog.FileName);
                 * }*/


                //Dictionary<int, List<Tranzactie>> TranzactiiBanci = new Dictionary<int, List<Tranzactie>>();

                foreach (var tranz in scenariu)
                {
                    if (tranz.ContClient == null || tranz.ValoareTotala == 0)
                    {
                        continue;
                    }

                    // Actualizez cont
                    Cont cont = context.Conturi
                                .First(c => c.Id == tranz.ContClient.Id);
                    cont.Sold     = tranz.ContClient.Sold;
                    cont.DataSold = DateTime.Now;

                    // leg tranzactia de celelalte obiecte din baza de date
                    tranz.Factura          = context.Facturi.First(f => f.Id == tranz.Factura.Id);
                    tranz.ContClient       = context.Conturi.First(c => c.Id == tranz.ContClient.Id);
                    tranz.ContFurnizor     = context.Conturi.First(c => c.Id == tranz.ContFurnizor.Id);
                    tranz.ContClient.Banca = context.Banci.First(b => b.Id == tranz.ContClient.BancaId);

                    // Atasez tranzactia la baza de date
                    context.Entry <Tranzactie>(tranz).State = System.Data.Entity.EntityState.Added;

                    //export

                    /*if (!TranzactiiBanci.ContainsKey(tranz.ContClient.BancaId)) {
                     *  TranzactiiBanci.Add(tranz.ContClient.BancaId, new List<Tranzactie>());
                     * }
                     * TranzactiiBanci[tranz.ContClient.BancaId].Add(tranz);*/
                }

                /*foreach (var i in TranzactiiBanci.Keys) {
                 *  try { exportaTranzCsv(dialog.FileName + $@"\{NumeBanca(i, TranzactiiBanci[i].Select(x => x.ContClient.Banca).ToList())}" + ".csv", TranzactiiBanci[i]); }
                 *  catch { }
                 * }*/

                /* SAU: -------------------------------------------------------------------------------------------------
                 * context.Conturi.AddOrUpdate(x=>x.Id,scenarii[index].Select(t => t.ContClient).ToArray());
                 *
                 * // tranzactiile(si atrib. din ele) din scenarii[index] sunt detached fata de baza de date
                 * foreach(var tranz in scenarii[index]){
                 *  tranz.Factura = context.Facturi.First(f => f.Id == tranz.Factura.Id);
                 *  tranz.ContClient = context.Conturi.First(c => c.Id == tranz.ContClient.Id);
                 *  tranz.ContFurnizor = context.Conturi.First(c => c.Id == tranz.ContFurnizor.Id);
                 * }
                 * context.Tranzactii.AddOrUpdate(t => t.Id, scenarii[index].ToArray());
                 */

                context.SaveChanges();
            }
        }