示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!validator.Validate())
                return;
            if (lbFileLogo.Text.Equals("Nenhum arquivo selecionado") && Convert.ToInt64(tfId.EditValue) == 0)
            {
                XtraMessageBox.Show("Selecione a Logo do Credenciado");
                OpenLogo_DoubleClick(sender, e);
                return;
            }

            using (var scope = credentialed.repo.GetTransaction())
            {
                try
                {
                    credentialed c = (credentialed)bdgCredentialed.Current;
                    FTPUtil ftp = new FTPUtil();
                    address ad = ((address)bdgAddress.Current);
                    ad.Save();
                    if(IsNew)
                        c.registered_at = credentialed.Now();
                    c.address_id = ad.id;
                    c.business_id = Singleton.getCurrentBusiness().id;
                    string localFile = ftp.dirCredentialeds + Util.RemoveSpecialCharacters(c.cnpj) + ".jpg";
                    if(peLogo.Image.Tag != null && !String.Equals(peLogo.Image.Tag, "ERROR"))
                        ftp.uploadImage(localFile, peLogo.Image);
                    c.directory_logo = localFile;
                    if (String.IsNullOrEmpty(tfPassword.EditValue.ToString()))
                        c.password = Util.RemoveSpecialCharacters(c.cnpj);
                    c.Save();
                    scope.Complete();
                    tfId.EditValue = c.id;
                    tfRegisteredAt.EditValue = c.registered_at;
                    if (this.MessageToSave("Credenciado"))
                        desk.AddTabAndCloseCurrent(new CredentialedForm(null), "Novo credenciado", false);

                }
                catch (Exception ex)
                {
                    credentialed.repo.AbortTransaction();
                    XtraMessageBox.Show(String.Format("Ocorreu um erro:\n\n{0}\n{1}", ex.Message, ex.InnerException));
                }
            }
        }
示例#2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if(!validatorCustomer.Validate())
                return;
            if (listPhones.ItemCount == 0)
            {
                XtraMessageBox.Show("Informe no mínimo 1 numero de contato para o cliente");
                return;
            }
            if (pePicture.Image == null)
            {
                XtraMessageBox.Show("Selecione a Imagem do Cliente");
                OpenImage_DoubleClick(sender, e);
                return;
            }
            using (var scope = customer.repo.GetTransaction())
            {
                try
                {
                    Console.WriteLine(0);
                    SplashScreenManager.ShowForm(null, typeof(PleaseWaitForm), false, false, false);
                    FTPUtil ftp = new FTPUtil();
                    customer c = (customer)bdgCustomer.Current;
                    address ad = (address)bdgAddress.Current;
                    Console.WriteLine(1);
                    ad.Save();
                    Console.WriteLine(2);
                    if (IsNew)
                        c.registered_at = credentialed.Now();
                    Console.WriteLine(3);
                    c.address_id = ad.id;
                    string localFile = ftp.dirCustomers + Util.RemoveSpecialCharacters(c.cpf) + ".jpg";
                    Console.WriteLine(4);
                    if (pePicture.Image.Tag != null && !String.Equals(pePicture.Image.Tag, "ERROR"))
                        ftp.uploadImage(localFile, pePicture.Image);
                    c.directory_picture = localFile;
                    Console.WriteLine(5);
                    c.organ_emitter_rg = String.Format("{0}/{1}", cbOrganEmitter.Text, cbStateRG.Text);
                    Console.WriteLine(6);
                    c.business_id = Singleton.getCurrentBusiness().id;
                    c.registred_by = Singleton.getCurrentUser().id;
                    c.Save();
                    Console.WriteLine(7);
                    foreach (string s in listPhones.Items)
                    {
                        phones_customer pc = new phones_customer()
                        {
                            customer_id = c.id,
                            phone = s
                        };
                        if (pc.IsNew())
                            pc.Save();
                    }
                    Console.WriteLine(8);
                    scope.Complete();
                    Console.WriteLine(9);
                    tfId.EditValue = c.id;
                    tfRegistredAt.EditValue = c.registered_at;
                    if (this.MessageToSave("Cliente"))
                        desk.AddTabAndCloseCurrent(new CustomerForm(null), "Novo cliente", false);

                }
                catch (Exception ex)
                {
                    customer.repo.AbortTransaction();
                    XtraMessageBox.Show(String.Format("Ocorreu um erro:\n\n{0}\n{1}", ex.Message, ex.InnerException));
                }
                finally
                {
                    SplashScreenManager.CloseForm(false);
                }
            }
        }