public void ButtonSave_Click(object sender, EventArgs e)
        {
            if (!BaseConnection.openConnection())
            {
                return;
            }

            string command = "select * from (select Name from Contractors inner join Users on Contractors.Id_User = Users.id where Users.id ="
                             + Session["User"] + ") as tabelka where tabelka.Name = '" + TextBoxName.Text + "'; ";

            // check if already added
            if (BaseConnection.execScalar(command) != null)
            {
                BaseConnection.closeConnection();
                string title = "Błąd";
                string body  = "Kontrahent o takiej nazwie już isnieje!";
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "showModalError('" + title + "', '" + body + "');", true);
                return;
            }

            Dictionary <string, string> pair = new Dictionary <string, string>();

            pair.Add("@userId", Session["User"].ToString());
            pair.Add("@name", TextBoxName.Text);
            pair.Add("@postTown", TextBoxPostTown.Text);
            pair.Add("@postCode", TextBoxPostCode.Text);
            pair.Add("@city", TextBoxCity.Text);
            pair.Add("@street", TextBoxStreet.Text);
            if (!String.IsNullOrEmpty(TextBoxNIP.Text))
            {
                pair.Add("@nip", TextBoxNIP.Text);
            }
            else
            {
                pair.Add("@nip", "null");
            }
            pair.Add("@regon", "null");
            if (!String.IsNullOrEmpty(TextBoxPESEL.Text))
            {
                pair.Add("@pesel", TextBoxPESEL.Text);
            }
            else
            {
                pair.Add("@pesel", "null");
            }

            BaseConnection.execProcedure("AddContractor", pair);

            BaseConnection.closeConnection();

            Response.Redirect("Contractors.aspx");
        }
Пример #2
0
        public GenerateInvoice(int idUser, int invoiceId, string nr)
        {
            _stringWriter = new StringWriter();
            _writer       = new HtmlTextWriter(_stringWriter);


            _idInvoice = invoiceId;
            _nr        = nr;
            _idUser    = idUser;
            if (!BaseConnection.openConnection())
            {
                return;
            }

            string query = "select Id_contractor from Invoices where Id =" + invoiceId;

            _idContractor = (int)BaseConnection.execScalar(query);

            BaseConnection.closeConnection();
        }
Пример #3
0
        protected void ButtonAddProduct_Click(object sender, EventArgs e)
        {
            if (!BaseConnection.openConnection())
            {
                return;
            }

            string command = "select * from Products where Name='" + TextBoxName.Text + "' and Id_user="******"User"];

            if (BaseConnection.execScalar(command) != null)
            {
                BaseConnection.closeConnection();
                string title = "Błąd";
                string body  = "Taki produkt już istnieje!";
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "showModalError('" + title + "', '" + body + "');", true);

                return;
            }

            command = "insert into Products values (" + Session["User"] + ",'" + TextBoxName.Text + "'," + DropDownListUnit.SelectedValue + " )";

            if ((int)BaseConnection.execCommand(command) == 1)
            {
                LabelError.Text     = "Produkt dodany";
                LabelError.CssClass = "text-success";
                LabelError.Visible  = true;
            }
            else
            {
                LabelError.Text     = "Nie udało się dodać do bazy";
                LabelError.CssClass = "text-danger";
                LabelError.Visible  = true;
            }


            BaseConnection.closeConnection();

            Response.Redirect("Product.aspx");
        }