Exemple #1
0
        //New BT Click , toggle form
        private void NewBranchBT_Click(object sender, RoutedEventArgs e)
        {
            //From grid animation
            if (FormGrid.Opacity == 0)
            {
                FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("PopUpGrid"));
                BranchNameTX.Focus();
                SaveBT.IsEnabled = true;
            }
            else if (BranchNameTX.Text.Length == 0)
            {
                FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
                SaveBT.IsEnabled = false;
            }

            //Clear branch values
            if (BranchNameTX.Text.Length > 0)
            {
                ResetForm();
            }
        }
Exemple #2
0
        private void EditBranch_Click(object sender, RoutedEventArgs e)
        {
            //Get button control
            Button Control = (Button)sender;

            if (FormGrid.Opacity == 0)
            {
                FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("PopUpGrid"));
            }

            //Set branch information to controls
            BranchNameTX.Text  = NovaAPI.APIBranch.branch.Find(x => x.id == Control.Tag.ToString()).name;
            BranchAddTX.Text   = NovaAPI.APIBranch.branch.Find(x => x.id == Control.Tag.ToString()).address;
            BranchPhoneTX.Text = NovaAPI.APIBranch.branch.Find(x => x.id == Control.Tag.ToString()).phone;

            //Set selected rol id index for edition save
            SelectedIndex = Control.Tag.ToString();

            //Focus editable rol
            BranchNameTX.Focus();
            SaveBT.IsEnabled = true;
        }
Exemple #3
0
        private async void SaveBT_Click(object sender, RoutedEventArgs e)
        {
            NewBranchBT.Focus();

            if (BranchNameTX.Text.Length == 0 || BranchNameTX.Text.Length < 5)
            {
                MessageBox.Show("El nombre de la sucursal no puede estar en blanco o ser inferior a 5 caracteres");
                BranchNameTX.Focus();
                return;
            }

            //Get rol parameters
            var Data = new NovaAPI.APIBranch.BranchClass();

            Data.id      = SelectedIndex;
            Data.name    = BranchNameTX.Text;
            Data.address = BranchAddTX.Text;
            Data.phone   = BranchPhoneTX.Text;

            //rol json data
            string requestData = JsonConvert.SerializeObject(Data);

            bool response;

            //Modify / Create request
            if (Data.id.Length > 0)
            {
                response = await NovaAPI.APIBranch.GetValues("2", DataConfig.LocalAPI, requestData);
            }
            else
            {
                response = await NovaAPI.APIBranch.GetValues("1", DataConfig.LocalAPI, requestData);
            }

            //Request response
            if (response)
            {
                if (Data.id.Length > 0)
                {
                    //On branch modified
                    NovaAPI.APIBranch.branch.Find(x => x.id == Data.id).name    = Data.name;
                    NovaAPI.APIBranch.branch.Find(x => x.id == Data.id).address = Data.address;
                    NovaAPI.APIBranch.branch.Find(x => x.id == Data.id).phone   = Data.phone;

                    BranchGrid.Items.Refresh();
                    FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
                    ResetForm();
                    SaveBT.IsEnabled = false;
                }
                else
                {
                    //On new branch created response
                    var branch = new NovaAPI.APIBranch.BranchClass();
                    branch.name    = Data.name;
                    branch.address = Data.address;
                    branch.phone   = Data.phone;
                    branch.id      = NovaAPI.APIRoles.LastID;
                    branch.count   = "0";

                    FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
                    ResetForm();

                    NovaAPI.APIBranch.branch.Add(branch);
                    SaveBT.IsEnabled = false;
                    //Reload rol data
                    LoadData();
                }
            }
            else
            {
                MessageBox.Show($"Error al crear la sucursal, INFO: {Environment.NewLine}{NovaAPI.APIRoles.Message}");
            }
        }