Esempio n. 1
0
 //Reset form data
 private void ResetForm()
 {
     FilterTX.Clear();
     SuppSocialNameTX.Clear();
     SuppComercialNameTX.Clear();
     SuppIDTX.Clear();
     SuppidTypeCB.SelectedIndex = 0;
     SuppAddressTX.Clear();
     SuppPhoneTX.Clear();
     StatusCB.IsChecked = true;
     SuppCelphoneTX.Clear();
     SuppEmailTX.Clear();
     SuppContactTX.Clear();
     SuppObvsTX.Clear();
     SaveBT.IsEnabled = false;
 }
Esempio n. 2
0
        //Supplier create / modify functions
        private async void SaveBT_Click(object sender, RoutedEventArgs e)
        {
            NewSupplierBT.Focus();

            if (SuppSocialNameTX.Text.Length == 0 || SuppSocialNameTX.Text.Length < 5)
            {
                MessageBox.Show("La razón social no puede estar en blanco o ser inferior a 5 caracteres");
                SuppSocialNameTX.Focus();
                return;
            }
            else if (SuppIDTX.Text.Length == 0 || SuppIDTX.Text.Length < 5)
            {
                MessageBox.Show("El numero de identificacion no puede estar en blanco o ser inferior a 5 caracteres");
                SuppIDTX.Focus();
                return;
            }

            //Get/Set Supplier parameters
            var Data = new NovaAPI.APISupplier.SupplierClass();

            Data.id            = SelectedIndex;
            Data.socialname    = SuppSocialNameTX.Text;
            Data.comercialname = SuppComercialNameTX.Text.Length == 0 ? SuppSocialNameTX.Text : SuppComercialNameTX.Text;
            Data.idtype        = SuppidTypeCB.SelectedIndex.ToString();
            Data.documentid    = SuppIDTX.Text;
            Data.address       = SuppAddressTX.Text;
            Data.mail          = SuppEmailTX.Text;
            Data.phone         = SuppPhoneTX.Text;
            Data.celphone      = SuppCelphoneTX.Text;
            Data.contact       = SuppContactTX.Text;
            Data.observation   = SuppObvsTX.Text;
            Data.status        = StatusCB.IsChecked == true ? "1" : "0";


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

            bool response;

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

            //Request response
            if (response)
            {
                if (Data.id.Length > 0)
                {
                    //On supplier modified
                    var SuppData = NovaAPI.APISupplier.suppliers.Find(x => x.id == Data.id);
                    SuppData.socialname    = Data.socialname;
                    SuppData.comercialname = Data.comercialname;
                    SuppData.idtype        = Data.idtype;
                    SuppData.documentid    = Data.documentid;
                    SuppData.address       = Data.address;
                    SuppData.mail          = Data.mail;
                    SuppData.phone         = Data.phone;
                    SuppData.celphone      = Data.celphone;
                    SuppData.contact       = Data.contact;
                    SuppData.observation   = Data.observation;
                    SuppData.status        = Data.status;
                    SuppliersGrid.Items.Refresh();
                    FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
                    ResetForm();
                }
                else
                {
                    //On new supplier created response
                    var SuppData = new NovaAPI.APISupplier.SupplierClass();
                    SuppData.socialname    = Data.socialname;
                    SuppData.comercialname = Data.comercialname;
                    SuppData.idtype        = Data.idtype;
                    SuppData.documentid    = Data.documentid;
                    SuppData.address       = Data.address;
                    SuppData.mail          = Data.mail;
                    SuppData.phone         = Data.phone;
                    SuppData.celphone      = Data.celphone;
                    SuppData.contact       = Data.contact;
                    SuppData.status        = Data.status;
                    SuppData.observation   = Data.observation;
                    SuppData.id            = NovaAPI.APISupplier.LastID;

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

                    NovaAPI.APISupplier.suppliers.Add(SuppData);

                    //Reload rol data
                    LoadData();
                }
            }
            else
            {
                MessageBox.Show($"Error al crear el proveedor, INFO: {Environment.NewLine}{NovaAPI.APISupplier.Message}");
            }
        }