Exemple #1
0
        public static async System.Threading.Tasks.Task<List<Anfrage>> GetAnfragenAsync( string lieferantenId, string deviceLanguage ,  BusinessLayer.User User, bool offline)
        {
            if (offline == false)
                return await GetAnfragenAsync (lieferantenId, deviceLanguage,  User);

            DataAccessLayer.DAL_Anfrage dal_Anfrage = new DataAccessLayer.DAL_Anfrage ();
            var anfragen = await System.Threading.Tasks.Task.Run(() =>dal_Anfrage.GetAnfragenAsync (lieferantenId, deviceLanguage,  User, true));
            return anfragen;

        }
Exemple #2
0
        public static async System.Threading.Tasks.Task<List<Anfrage>> GetAnfragenAsync ( string lieferantenId, string deviceLanguage , BusinessLayer.User user)
        {

            // Alle Kunden, die in dem Namen den Begriff <name> enthalten
            DataAccessLayer.DAL_Anfrage dal_Anfrage = new DataAccessLayer.DAL_Anfrage ();
            var anfragen  = await dal_Anfrage.GetAnfragenAsync (lieferantenId, deviceLanguage , user);
            Console.WriteLine ("CommitPost GetAnfrageAsync 3");

            return anfragen;

        }
        public override async System.Threading.Tasks.Task<IEnumerable<Transaction>> GetPreTransactionsAsync (  string deviceLanguage , BusinessLayer.User user)
        {
            try
            {
               // Alle Lieferanten, die in dem Namen den Begriff <name> enthalten
                DataAccessLayer.DAL_Anfrage dal_Anfrage = new DataAccessLayer.DAL_Anfrage ();
                var anfragen  = await dal_Anfrage.GetAnfragenAsync (ID, deviceLanguage , user);
                Console.WriteLine ("CommitPost GetAnfrageAsync 3");

                return anfragen.Cast<BusinessLayer.Transaction>();
            }
            catch (Exception ex)
            {
                DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
                return null;
            }
        }
        public override async System.Threading.Tasks.Task<DataAccessLayer.SOAResult> DownloadLocalAsync(User user, string deviceLanguage)
        {
            Console.WriteLine("__________________________________ START ___________________________________________________");
            DataAccessLayer.SOAResult result = DataAccessLayer.SOAResult.FALSE;
            try
            {
                // In this progress we increase the progress status, too
                // Main step: Lieranten Data
                ResetProgressStatus();

                ProgressStatusWish = 1;
                DataAccessLayer.DAL_Lieferant dal_Lieferant = new DataAccessLayer.DAL_Lieferant();

                // first check permission
                if (!user.HasPermission(DAC_Object.Lieferant,BusinessLayer.DAC_Permission.DOWN_UPLOAD))
                    return DataAccessLayer.SOAResult.TRUE;

                using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result = await dal_Lieferant.InsertLieferantAsync(this, user, true);
                }
                ProgressStatus = 1;

                // Then the related data
                // 1. Ansprechpartner
                // We don't check permission for Ansprechpartner, cause Tasks and other modules will use it 
                if (result == DataAccessLayer.SOAResult.TRUE )
                {

                    ProgressStatusWish += 2;
                    List<Ansprechpartner> ansprechpartnern = await Ansprechpartner.GetAnsprechpartnernAsync(this.ID, deviceLanguage,user);
                    ProgressStatus += 2;
                    ProgressStatusWish += 1;
                    DataAccessLayer.DAL_Ansprechpartner dal_ansprechpartner = new DataAccessLayer.DAL_Ansprechpartner();
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                        result = await System.Threading.Tasks.Task.Run(() => dal_ansprechpartner.InsertAnsprechpartnernAsync(ansprechpartnern, user, true));
                    }
                    ProgressStatus += 1;
                }

                // 2. PersonUmsatz for Charts
                if (result == DataAccessLayer.SOAResult.TRUE && user.HasPermission(DAC_Object.Lieferant_Chart,DAC_Permission.DOWN_UPLOAD))
                {

                    ProgressStatusWish += 3;
                    List<BusinessLayer.PersonUmsatz> PersonUmsatzList = await GetPersonTimeUmsatzAsync("36", user);
                    ProgressStatus += 3;
                    ProgressStatusWish += 2;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                        result = await System.Threading.Tasks.Task.Run(() => dal_Lieferant.InsertPersonUmsatzAsync(PersonUmsatzList, this, user, true));
                    }
                    ProgressStatus += 2;
                }

                // 3. Tasks and related data
                // I. Tasks
                DataAccessLayer.DAL_Task dal_task = new DataAccessLayer.DAL_Task();
                if (result == DataAccessLayer.SOAResult.TRUE && user.HasPermission(DAC_Object.Lieferant_Task,DAC_Permission.DOWN_UPLOAD))
                {

                    ProgressStatusWish += 11;
                    List<Task> tasks = await dal_task.GetTasksAsync(ID, user);
                    ProgressStatus += 11;
                    ProgressStatusWish += 32;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                          result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertTasksAsync(tasks, user, true));
                    }

                    //result = await dal_task.InsertTasksAsync(tasks, user, true);
                    ProgressStatus += 32;

                }

                // II. TaskArt
                // These are help data, so permission checking is not needed
                if (result == DataAccessLayer.SOAResult.TRUE )
                {

                    ProgressStatusWish += 2;
                    List<TaskArt> taskArts = await DataAccessLayer.DAL_Task.GetTaskArtsAsync(user);
                    ProgressStatus += 2;
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                           result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertTaskArtsAsync(taskArts, user, true));
                    }
                    ProgressStatus += 1;
                }

                // III. TaskTyp
                // These are help data, so permission checking is not needed
                if (result == DataAccessLayer.SOAResult.TRUE )
                {
                    ProgressStatusWish += 3;
                    List<TaskTyp> taskTyps = await DataAccessLayer.DAL_Task.GetTaskTypsAsync(user);
                    ProgressStatus += 3;
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                        result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertTaskTypsAsync(taskTyps, user, true));
                    }
                    ProgressStatus += 1;
                }

                // IV. Mitarbeiter
                // These are help data, so permission checking is not needed
                if (result == DataAccessLayer.SOAResult.TRUE )
                {

                    ProgressStatusWish += 2;
                    List<Mitarbeiter> mitarbeitern = await DataAccessLayer.DAL_Task.GetTaskMitarbeiternAsync(user);
                    ProgressStatus += 2;
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                        result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertMitarbeiternAsync(mitarbeitern, user, true));
                    }
                    ProgressStatus += 1;
                }

                // V. Abteilung
                // These are help data, so permission checking is not needed
                if (result == DataAccessLayer.SOAResult.TRUE )
                {
                    ProgressStatusWish += 2;
                    List<Abteilung> abteilungen = await DataAccessLayer.DAL_Task.GetTaskAbteilungenAsync(user);
                    ProgressStatus += 2;
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                           result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertAbteilungenAsync(abteilungen, user, true));
                    }
                    ProgressStatus += 1;
                }

                // VI. Anfragen
                DataAccessLayer.DAL_Anfrage dal_anfrage = new DataAccessLayer.DAL_Anfrage();
                DataAccessLayer.DAL_Position dal_position = new DataAccessLayer.DAL_Position();
                if (result == DataAccessLayer.SOAResult.TRUE && user.HasPermission(DAC_Object.Lieferant_Anfrage,DAC_Permission.DOWN_UPLOAD))
                {
                    ProgressStatusWish += 7;
                    List<Anfrage> anfragen = await dal_anfrage.GetAnfragenAsync(ID, deviceLanguage, user);
                    ProgressStatus += 7;
                    foreach (var anfrage in anfragen)
                    {
                        List<Position> positionen = await dal_position.GetPositionenAsync(anfrage.ID, anfrage.Waehrung, deviceLanguage, user);
                        result = await System.Threading.Tasks.Task.Run(() => dal_position.InsertPositionenAsync(positionen, user, true));
                    }
                    ProgressStatusWish += 11;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result =  await System.Threading.Tasks.Task.Run(() => dal_anfrage.InsertAnfragenAsync(anfragen, user, true));
                    }
                    ProgressStatus += 11;

                }

                // VI. Bestellungen
                DataAccessLayer.DAL_Bestellung dal_bestellung = new DataAccessLayer.DAL_Bestellung();

                if (result == DataAccessLayer.SOAResult.TRUE && user.HasPermission(DAC_Object.Lieferant_Bestellung,DAC_Permission.DOWN_UPLOAD))
                {
                    ProgressStatusWish += 7;
                    List<Bestellung> bestellungen = await dal_bestellung.GetBestellungenAsync(ID, deviceLanguage, user);
                    ProgressStatus += 7;
                    foreach (var bestellung in bestellungen)
                    {
                        List<Position> positionen = await dal_position.GetPositionenAsync(bestellung.ID, bestellung.Waehrung, deviceLanguage, user);
                        result = await System.Threading.Tasks.Task.Run(() => dal_position.InsertPositionenAsync(positionen, user, true));
                    }
                    ProgressStatusWish += 6;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                           result =  await System.Threading.Tasks.Task.Run(() => dal_bestellung.InsertBestellungenAsync(bestellungen, user, true));
                    }
                    ProgressStatus += 6;

                }
            }
            catch (Exception ex)
            {
                DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
            }

            return result;
        }
        public override async System.Threading.Tasks.Task<DataAccessLayer.SOAResult> DownloadLocalAsync(User user, string deviceLanguage)
        {

            Console.WriteLine("__________________________________ START ___________________________________________________");
            DataAccessLayer.SOAResult result = DataAccessLayer.SOAResult.FALSE;
            try
            {

                // In this progress we increase the progress status, too
                // Main step: Lieranten Data
                DataAccessLayer.PerformanceWatch stopWatch = new DataAccessLayer.PerformanceWatch();
                stopWatch.Start();
                ResetProgressStatus();

                ProgressStatusWish = 1;
                DataAccessLayer.DAL_Lieferant dal_Lieferant = new DataAccessLayer.DAL_Lieferant();


                using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result = await dal_Lieferant.InsertLieferantAsync(this, user, true);
                }
                ProgressStatus = 1;
                stopWatch.Stop();
                stopWatch.PrintConsole("InsertLieferantAsync");

                // Then the related data
                // 1. Ansprechpartner

                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    List<Ansprechpartner> ansprechpartnern = await Ansprechpartner.GetAnsprechpartnernAsync(this.ID, deviceLanguage,user);
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("GetAnsprechpartnernAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    DataAccessLayer.DAL_Ansprechpartner dal_ansprechpartner = new DataAccessLayer.DAL_Ansprechpartner();
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                        result = await System.Threading.Tasks.Task.Run(() => dal_ansprechpartner.InsertAnsprechpartnernAsync(ansprechpartnern, user, true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("InsertAnsprechpartnernAsync");
                }

                // 2. PersonUmsatz for Charts
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 3;
                    List<BusinessLayer.PersonUmsatz> PersonUmsatzList = await GetPersonTimeUmsatzAsync("36", user);
                    ProgressStatus += 3;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("GetPersonTimeUmsatzAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                        result = await System.Threading.Tasks.Task.Run(() => dal_Lieferant.InsertPersonUmsatzAsync(PersonUmsatzList, this, user, true));
                    }
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("InsertPersonUmsatzAsync");
                }

                // 3. Tasks and related data
                // I. Tasks
                DataAccessLayer.DAL_Task dal_task = new DataAccessLayer.DAL_Task();
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 11;
                    List<Task> tasks = await dal_task.GetTasksAsync(ID, user);
                    ProgressStatus += 11;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("GetTasksAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 32;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                          result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertTasksAsync(tasks, user, true));
                    }

                    //result = await dal_task.InsertTasksAsync(tasks, user, true);
                    ProgressStatus += 32;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("InsertTasksAsync");

                }

                // II. TaskArt
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    List<TaskArt> taskArts = await DataAccessLayer.DAL_Task.GetTaskArtsAsync(user);
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("GetTaskArtsAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                           result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertTaskArtsAsync(taskArts, user, true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("InsertTaskArtsAsync");
                }

                // III. TaskTyp
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 3;
                    List<TaskTyp> taskTyps = await DataAccessLayer.DAL_Task.GetTaskTypsAsync(user);
                    ProgressStatus += 3;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("GetTaskTypsAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                        result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertTaskTypsAsync(taskTyps, user, true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("InsertTaskTypsAsync");
                }

                // IV. Mitarbeiter
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    List<Mitarbeiter> mitarbeitern = await DataAccessLayer.DAL_Task.GetTaskMitarbeiternAsync(user);
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("GetTaskMitarbeiternAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                        result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertMitarbeiternAsync(mitarbeitern, user, true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("InsertMitarbeiternAsync");
                }

                // V. Abteilung
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    List<Abteilung> abteilungen = await DataAccessLayer.DAL_Task.GetTaskAbteilungenAsync(user);
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("GetTaskAbteilungenAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                           result = await System.Threading.Tasks.Task.Run(() => dal_task.InsertAbteilungenAsync(abteilungen, user, true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole("InsertAbteilungenAsync");
                }

                // VI. Anfragen
                DataAccessLayer.DAL_Anfrage dal_anfrage = new DataAccessLayer.DAL_Anfrage();
                DataAccessLayer.DAL_Position dal_position = new DataAccessLayer.DAL_Position();
                if(result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 7;
                    List<Anfrage> anfragen = await dal_anfrage.GetAnfragenAsync(ID, deviceLanguage, user);
                    ProgressStatus += 7;
                    stopWatch.PrintConsole ("GetAnfragAsync: "  + anfragen.Count);
                    foreach (var anfrage in anfragen)
                    {
                        List<Position> positionen = await dal_position.GetPositionenAsync(anfrage.ID, anfrage.Waehrung, deviceLanguage, user);
                        result = await System.Threading.Tasks.Task.Run(() => dal_position.InsertPositionenAsync(positionen, user, true));
                    }
                    ProgressStatusWish += 11;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result =  await System.Threading.Tasks.Task.Run(() => dal_anfrage.InsertAnfragenAsync(anfragen, user, true));
                    }
                    ProgressStatus += 11;

                }

                // VI. Bestellungen
                DataAccessLayer.DAL_Bestellung dal_bestellung = new DataAccessLayer.DAL_Bestellung();

                if(result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 7;
                    List<Bestellung> bestellungen = await dal_bestellung.GetBestellungenAsync(ID, deviceLanguage, user);
                    ProgressStatus += 7;
                    stopWatch.PrintConsole ("GetbestellungenAsync: " + bestellungen.Count);
                    foreach (var bestellung in bestellungen)
                    {
                        List<Position> positionen = await dal_position.GetPositionenAsync(bestellung.ID, bestellung.Waehrung, deviceLanguage, user);
                        result = await System.Threading.Tasks.Task.Run(() => dal_position.InsertPositionenAsync(positionen, user, true));
                    }
                    ProgressStatusWish += 6;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                           result =  await System.Threading.Tasks.Task.Run(() => dal_bestellung.InsertBestellungenAsync(bestellungen, user, true));
                    }
                    ProgressStatus += 6;

                }
            }
            catch (Exception ex)
            {
                DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
            }

            return result;
        }