Пример #1
0
 private void BindAccount()
 {
     try
     {
         SPARInsightManagement.Web.Code.Account account = SPARInsightManagement.Web.Code.Account.GetAccountByAccountId(this.accountId);
         TextBoxName.Text    = account.Name;
         TextBoxVAT.Text     = account.VAT;
         TextBoxAddress.Text = account.Address;
         DropDownListAccountType.Items.FindByValue(account.AccountTypeId.ToString()).Selected     = true;
         DropDownListAccountStatus.Items.FindByValue(account.AccountStatusId.ToString()).Selected = true;
     }
     catch (System.Data.SqlClient.SqlException sqlEx)
     {
         for (int i = 0; i < sqlEx.Errors.Count; i++)
         {
             LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
         }
         PanelError.Visible = true;
     }
     catch (Exception exception)
     {
         LabelError.Text   += (exception.Message + "<br />");
         PanelError.Visible = true;
     }
 }
Пример #2
0
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                SPARInsightManagement.Web.Code.Account account = new SPARInsightManagement.Web.Code.Account();
                account.AccountId       = this.accountId;
                account.Name            = TextBoxName.Text;
                account.VAT             = TextBoxVAT.Text;
                account.Address         = TextBoxAddress.Text;
                account.AccountTypeId   = Convert.ToInt32(DropDownListAccountType.SelectedValue);
                account.AccountStatusId = Convert.ToInt32(DropDownListAccountStatus.SelectedValue);
                account.ModifiedUser    = Context.User.Identity.GetUserName();

                try
                {
                    account.Save();
                    int accountId = account.AccountId;

                    Button clickedButton = (Button)sender;
                    switch (clickedButton.ID)
                    {
                    case "ButtonSave":
                        Response.Redirect(String.Format("AccountList.aspx?Name={0}", account.Name));
                        break;

                    case "ButtonSaveEdit":
                        Response.Redirect(String.Format("AccountEdit.aspx?AccountId={0}", account.AccountId));
                        break;

                    case "ButtonSaveNew":
                        Response.Redirect("AccountEdit.aspx");
                        break;
                    }
                }
                catch (System.Data.SqlClient.SqlException sqlEx)
                {
                    LabelError.Text = "";
                    for (int i = 0; i < sqlEx.Errors.Count; i++)
                    {
                        ErrorMessage.Text += (sqlEx.Errors[i].Message + "<br />");
                    }
                }
            }
        }