Exemple #1
0
        private static void OnCurrentLicenceTypePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            LicenceTypePopup     popup       = source as LicenceTypePopup;
            LicenceTypeViewModel LicenceType = (LicenceTypeViewModel)e.NewValue;

            popup.txtLicenceType.Text = LicenceType != null ? LicenceType.Category + " (" + LicenceType.Description + ")" : "";
        }
        public LicenceTypeResponse Create(LicenceTypeViewModel licenceType)
        {
            LicenceTypeResponse response = new LicenceTypeResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();

                SqliteCommand insertCommand = new SqliteCommand();
                insertCommand.CommandText = SqlCommandInsertPart;
                insertCommand.Connection  = db;

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, licenceType);
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
Exemple #3
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            LicenceTypeViewModel licenceType = new LicenceTypeViewModel();

            licenceType.Identifier = Guid.NewGuid();

            LicenceType_List_AddEdit addEditForm = new LicenceType_List_AddEdit(licenceType, true);

            addEditForm.LicenceTypeCreatedUpdated += new LicenceTypeHandler(SyncData);
            FlyoutHelper.OpenFlyout(this, ((string)Application.Current.FindResource("Podaci_o_dozvolu")), 95, addEditForm);
        }
Exemple #4
0
        public LicenceType_List_AddEdit(LicenceTypeViewModel licenceTypeViewModel, bool isCreateProcess, bool isPopup = false)
        {
            // Initialize service
            this.licenceTypeService = DependencyResolver.Kernel.Get <ILicenceTypeService>();

            InitializeComponent();

            this.DataContext = this;

            CurrentLicenceType = licenceTypeViewModel;
            IsCreateProcess    = isCreateProcess;
            IsPopup            = isPopup;
        }
        public LicenceTypeListResponse GetLicenceTypesForPopup(int companyId, string filterString)
        {
            LicenceTypeListResponse     response     = new LicenceTypeListResponse();
            List <LicenceTypeViewModel> LicenceTypes = new List <LicenceTypeViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM LicenceTypes " +
                        "WHERE ((@Code IS NULL OR @Code = '' OR Code LIKE @Code) " +
                        "OR (@Category IS NULL OR @Category = '' OR Category LIKE @Category)) " +
                        "AND CompanyId = @CompanyId " +
                        "ORDER BY IsSynced, Id DESC " +
                        "LIMIT @ItemsPerPage;", db);

                    selectCommand.Parameters.AddWithValue("@Code", ((object)filterString) != null ? "%" + filterString + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Category", ((object)filterString) != null ? "%" + filterString + "%" : "");
                    selectCommand.Parameters.AddWithValue("@CompanyId", ((object)filterString) != null ? companyId : 0);
                    selectCommand.Parameters.AddWithValue("@ItemsPerPage", 100);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        LicenceTypeViewModel dbEntry = Read(query);
                        LicenceTypes.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.LicenceTypes   = new List <LicenceTypeViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success      = true;
            response.LicenceTypes = LicenceTypes;
            return(response);
        }
Exemple #6
0
        public static LicenceTypeViewModel ConvertToLicenceTypeViewModelLite(this LicenceType licenceType)
        {
            LicenceTypeViewModel licenceTypeViewModel = new LicenceTypeViewModel()
            {
                Id         = licenceType.Id,
                Identifier = licenceType.Identifier,

                Code        = licenceType.Code,
                Category    = licenceType.Category,
                Description = licenceType.Description,

                CreatedAt = licenceType.CreatedAt,
                UpdatedAt = licenceType.UpdatedAt
            };

            return(licenceTypeViewModel);
        }
        public LicenceTypeResponse Create(LicenceTypeViewModel licenceType)
        {
            LicenceTypeResponse response = new LicenceTypeResponse();

            try
            {
                response = WpfApiHandler.SendToApi <LicenceTypeViewModel, LicenceTypeResponse>(licenceType, "Create");
            }
            catch (Exception ex)
            {
                response.LicenceType = new LicenceTypeViewModel();
                response.Success     = false;
                response.Message     = ex.Message;
            }

            return(response);
        }
        private LicenceTypeViewModel Read(SqliteDataReader query)
        {
            int counter = 0;
            LicenceTypeViewModel dbEntry = new LicenceTypeViewModel();

            dbEntry.Id          = SQLiteHelper.GetInt(query, ref counter);
            dbEntry.Identifier  = SQLiteHelper.GetGuid(query, ref counter);
            dbEntry.Code        = SQLiteHelper.GetString(query, ref counter);
            dbEntry.Category    = SQLiteHelper.GetString(query, ref counter);
            dbEntry.Description = SQLiteHelper.GetString(query, ref counter);
            dbEntry.Country     = SQLiteHelper.GetCountry(query, ref counter);
            dbEntry.IsSynced    = SQLiteHelper.GetBoolean(query, ref counter);
            dbEntry.UpdatedAt   = SQLiteHelper.GetDateTime(query, ref counter);
            dbEntry.CreatedBy   = SQLiteHelper.GetCreatedBy(query, ref counter);
            dbEntry.Company     = SQLiteHelper.GetCompany(query, ref counter);

            return(dbEntry);
        }
        public LicenceTypeResponse Delete(Guid identifier)
        {
            LicenceTypeResponse response = new LicenceTypeResponse();

            try
            {
                LicenceTypeViewModel re = new LicenceTypeViewModel();
                re.Identifier = identifier;
                response      = WpfApiHandler.SendToApi <LicenceTypeViewModel, LicenceTypeResponse>(re, "Delete");
            }
            catch (Exception ex)
            {
                response.LicenceType = new LicenceTypeViewModel();
                response.Success     = false;
                response.Message     = ex.Message;
            }

            return(response);
        }
        private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, LicenceTypeViewModel licenceType)
        {
            insertCommand.Parameters.AddWithValue("@ServerId", licenceType.Id);
            insertCommand.Parameters.AddWithValue("@Identifier", licenceType.Identifier);
            insertCommand.Parameters.AddWithValue("@Code", ((object)licenceType.Code) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Category", ((object)licenceType.Category) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Description", ((object)licenceType.Description) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@CountryId", ((object)licenceType.Country?.Id) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@CountryIdentifier", ((object)licenceType.Country?.Identifier) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@CountryCode", ((object)licenceType.Country?.Mark) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@CountryName", ((object)licenceType.Country?.Name) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@IsSynced", licenceType.IsSynced);
            insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)licenceType.UpdatedAt) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@CreatedById", MainWindow.CurrentUser.Id);
            insertCommand.Parameters.AddWithValue("@CreatedByName", MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName);
            insertCommand.Parameters.AddWithValue("@CompanyId", MainWindow.CurrentCompany.Id);
            insertCommand.Parameters.AddWithValue("@CompanyName", MainWindow.CurrentCompany.CompanyName);

            return(insertCommand);
        }
Exemple #11
0
        public JsonResult Delete([FromBody] LicenceTypeViewModel licenceType)
        {
            LicenceTypeResponse response = new LicenceTypeResponse();

            try
            {
                response = this.licenceTypeService.Delete(licenceType.Identifier);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                Console.WriteLine(ex.Message);
            }

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
        public LicenceTypeResponse Create(LicenceTypeViewModel licenceType)
        {
            LicenceTypeResponse response = new LicenceTypeResponse();

            try
            {
                LicenceType addedLicenceType = unitOfWork.GetLicenceTypeRepository().Create(licenceType.ConvertToLicenceType());
                unitOfWork.Save();

                response.LicenceType = addedLicenceType.ConvertToLicenceTypeViewModel();
                response.Success     = true;
            }
            catch (Exception ex)
            {
                response.LicenceType = new LicenceTypeViewModel();
                response.Success     = false;
                response.Message     = ex.Message;
            }

            return(response);
        }
Exemple #13
0
        public static LicenceType ConvertToLicenceType(this LicenceTypeViewModel licenceTypeViewModel)
        {
            LicenceType licenceType = new LicenceType()
            {
                Id         = licenceTypeViewModel.Id,
                Identifier = licenceTypeViewModel.Identifier,

                Code        = licenceTypeViewModel.Code,
                Category    = licenceTypeViewModel.Category,
                Description = licenceTypeViewModel.Description,


                CountryId   = licenceTypeViewModel.Country?.Id ?? null,
                CreatedById = licenceTypeViewModel.CreatedBy?.Id ?? null,
                CompanyId   = licenceTypeViewModel.Company?.Id ?? null,

                CreatedAt = licenceTypeViewModel.CreatedAt,
                UpdatedAt = licenceTypeViewModel.UpdatedAt
            };

            return(licenceType);
        }
        public LicenceTypeResponse GetLicenceType(Guid identifier)
        {
            LicenceTypeResponse  response    = new LicenceTypeResponse();
            LicenceTypeViewModel licenceType = new LicenceTypeViewModel();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM LicenceTypes " +
                        "WHERE Identifier = @Identifier;", db);
                    selectCommand.Parameters.AddWithValue("@Identifier", identifier);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        LicenceTypeViewModel dbEntry = Read(query);
                        licenceType = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.LicenceType    = new LicenceTypeViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success     = true;
            response.LicenceType = licenceType;
            return(response);
        }
Exemple #15
0
        public static LicenceTypeViewModel ConvertToLicenceTypeViewModel(this LicenceType licenceType)
        {
            LicenceTypeViewModel licenceTypeViewModel = new LicenceTypeViewModel()
            {
                Id         = licenceType.Id,
                Identifier = licenceType.Identifier,

                Code        = licenceType.Code,
                Category    = licenceType.Category,
                Description = licenceType.Description,

                Country = licenceType.Country?.ConvertToCountryViewModelLite(),

                IsActive = licenceType.Active,

                CreatedBy = licenceType.CreatedBy?.ConvertToUserViewModelLite(),
                Company   = licenceType.Company?.ConvertToCompanyViewModelLite(),

                UpdatedAt = licenceType.UpdatedAt,
                CreatedAt = licenceType.CreatedAt
            };

            return(licenceTypeViewModel);
        }
        public LicenceTypeListResponse GetLicenceTypesByPage(int companyId, LicenceTypeViewModel licenceTypeSearchObject, int currentPage = 1, int itemsPerPage = 50)
        {
            LicenceTypeListResponse     response     = new LicenceTypeListResponse();
            List <LicenceTypeViewModel> LicenceTypes = new List <LicenceTypeViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM LicenceTypes " +
                        "WHERE (@Category IS NULL OR @Category = '' OR Category LIKE @Category) " +
                        "AND (@Description IS NULL OR @Description = '' OR Description LIKE @Description) " +
                        "AND CompanyId = @CompanyId " +
                        "ORDER BY IsSynced, Id DESC " +
                        "LIMIT @ItemsPerPage OFFSET @Offset;", db);

                    selectCommand.Parameters.AddWithValue("@Category", ((object)licenceTypeSearchObject.Search_Category) != null ? "%" + licenceTypeSearchObject.Search_Category + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Description", ((object)licenceTypeSearchObject.Search_Description) != null ? "%" + licenceTypeSearchObject.Search_Description + "%" : "");
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);
                    selectCommand.Parameters.AddWithValue("@ItemsPerPage", itemsPerPage);
                    selectCommand.Parameters.AddWithValue("@Offset", (currentPage - 1) * itemsPerPage);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        LicenceTypeViewModel dbEntry = Read(query);
                        LicenceTypes.Add(dbEntry);
                    }

                    selectCommand = new SqliteCommand(
                        "SELECT Count(*) " +
                        "FROM LicenceTypes " +
                        "WHERE (@Category IS NULL OR @Category = '' OR Category LIKE @Category) " +
                        "AND (@Description IS NULL OR @Description = '' OR Description LIKE @Description) " +
                        "AND CompanyId = @CompanyId ;", db);

                    selectCommand.Parameters.AddWithValue("@Category", ((object)licenceTypeSearchObject.Search_Category) != null ? "%" + licenceTypeSearchObject.Search_Category + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Description", ((object)licenceTypeSearchObject.Search_Description) != null ? "%" + licenceTypeSearchObject.Search_Description + "%" : "");
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);


                    query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        response.TotalItems = query.GetInt32(0);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.LicenceTypes   = new List <LicenceTypeViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success      = true;
            response.LicenceTypes = LicenceTypes;
            return(response);
        }
Exemple #17
0
        private void btnLicenceTypes_Insert_Click(object sender, RoutedEventArgs e)
        {
            Thread th = new Thread(() =>
            {
                LicenceTypeButtonContent = " Učitavanje EXCEL fajla... ";
                LicenceTypeButtonEnabled = false;

                List <LicenceTypeViewModel> licenceTypes = new List <LicenceTypeViewModel>();

                #region Excel
                OpenFileDialog oDlg   = new OpenFileDialog();
                oDlg.InitialDirectory = "C:\\";
                oDlg.Filter           = "xlsx Files (*.xlsx)|*.xlsx";
                if (true == oDlg.ShowDialog())
                {
                    Microsoft.Office.Interop.Excel.Application xlApp      = new Microsoft.Office.Interop.Excel.Application();
                    Microsoft.Office.Interop.Excel.Workbook xlWorkbook    = xlApp.Workbooks.Open(oDlg.FileName);
                    Microsoft.Office.Interop.Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
                    Microsoft.Office.Interop.Excel.Range xlRange          = xlWorksheet.UsedRange;

                    int rowCount = xlRange.Rows.Count;
                    int colCount = xlRange.Columns.Count;

                    for (int i = 2; i <= rowCount; i++)
                    {
                        LicenceTypeButtonContent = i + " od " + rowCount;

                        LicenceTypeViewModel licenceType = new LicenceTypeViewModel();
                        licenceType.Category             = xlRange.Cells[i, 1].Text;
                        licenceType.Description          = xlRange.Cells[i, 2].Text;
                        licenceType.Country = new CountryViewModel()
                        {
                            Mark = xlRange.Cells[i, 3].Text
                        };

                        licenceType.Identifier = Guid.NewGuid();
                        licenceType.IsSynced   = false;
                        licenceType.CreatedBy  = new UserViewModel()
                        {
                            Id = MainWindow.CurrentUserId
                        };
                        licenceType.Company = new CompanyViewModel()
                        {
                            Id = MainWindow.CurrentCompanyId
                        };
                        licenceType.CreatedAt = DateTime.Now;
                        licenceType.UpdatedAt = DateTime.Now;

                        licenceTypes.Add(licenceType);

                        if (i % 100 == 0)
                        {
                            BankButtonContent = " Unos podataka u toku... ";
                            BankButtonEnabled = false;

                            string apiUrlTmp = BaseApiUrl + "/SeedData/SeedLicenceTypes";
                            string valuesTmp = JsonConvert.SerializeObject(
                                licenceTypes,
                                Formatting.Indented,
                                new JsonSerializerSettings
                            {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            });

                            SendData(apiUrlTmp, valuesTmp);

                            licenceTypes.Clear();
                        }
                    }
                }
                #endregion

                LicenceTypeButtonContent = " Unos podataka u toku... ";
                LicenceTypeButtonEnabled = false;

                string apiUrl = BaseApiUrl + "/SeedData/SeedLicenceTypes";
                string values = JsonConvert.SerializeObject(
                    licenceTypes,
                    Formatting.Indented,
                    new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });

                SendData(apiUrl, values);

                LicenceTypeButtonContent = " Tip dozvole ";
                LicenceTypeButtonEnabled = true;
            });

            th.IsBackground = true;
            th.Start();
        }
Exemple #18
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (String.IsNullOrEmpty(CurrentLicenceType.Category))
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Ime_dozvole"));
                return;
            }

            #endregion

            Thread th = new Thread(() =>
            {
                SaveButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke"));
                SaveButtonEnabled = false;

                CurrentLicenceType.IsSynced = false;

                CurrentLicenceType.Company = new CompanyViewModel()
                {
                    Id = MainWindow.CurrentCompanyId
                };
                CurrentLicenceType.CreatedBy = new UserViewModel()
                {
                    Id = MainWindow.CurrentUserId
                };

                LicenceTypeResponse response = licenceTypeService.Create(CurrentLicenceType);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_čuvanja_na_serveruUzvičnik"));
                    SaveButtonContent       = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled       = true;
                }

                if (response.Success)
                {
                    MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik"));
                    SaveButtonContent         = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled         = true;

                    LicenceTypeCreatedUpdated();

                    if (IsCreateProcess)
                    {
                        CurrentLicenceType            = new LicenceTypeViewModel();
                        CurrentLicenceType.Identifier = Guid.NewGuid();

                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            txtName.Focus();
                        })
                            );
                    }
                    else
                    {
                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            if (IsPopup)
                            {
                                FlyoutHelper.CloseFlyoutPopup(this);
                            }
                            else
                            {
                                FlyoutHelper.CloseFlyout(this);
                            }
                        })
                            );
                    }
                }
            });
            th.IsBackground = true;
            th.Start();

            txtName.Focus();
        }