Example #1
0
    protected int SaveData()
    {
        int ShoppingListRno = Str.Num(hfShoppingListRno.Value);
        int Rno             = Str.Num(hfRno.Value);

        cDetails = Str.Num(hfNumDetails.Value);
        string Sql = string.Empty;

        try
        {
            int VendorRno = Parm.Int("hfVendorRno");
            if (Rno == 0)
            {
                Sql = string.Format(
                    "Insert Into Purchases (VendorRno, CreatedDtTm, CreatedUser) Values ({0}, GetDate(), {1}); " +
                    "Select Scope_Identity()",
                    VendorRno,
                    DB.PutStr(g.User));
                Rno = db.SqlNum(Sql);
            }

            Sql = string.Format(
                "Update Purchases Set " +
                "VendorRno = {1}, " +
                "PurchaseDt = {2}, " +
                "PurchaseOrdNum = {3}, " +
                "VendorInvNum = {4}, " +
                "UpdatedDtTm = GetDate(), " +
                "UpdatedUser = {5} " +
                "Where PurchaseRno = {0}",
                Rno,
                VendorRno,
                DB.PutDtTm(Parm.DtTm("txtPurchaseDate")),
                DB.PutStr(txtOrderNum.Text, 20),
                DB.PutStr(txtVendorInvoice.Text, 20),
                DB.PutStr(g.User));
            db.Exec(Sql);

            StartHere = Rno;

            RemoveDetails();
            SaveDetails(Rno);

            // cleanup shopping list
            if (ShoppingListRno != 0)
            {
                Sql = string.Format(
                    "Delete From ShoppingListDetails Where ShoppingListRno = {0};\n" +
                    "Delete From ShoppingLists Where ShoppingListRno = {0};",
                    ShoppingListRno);
                db.Exec(Sql);
                LoadShoppingList();
            }
        }
        catch (Exception Ex)
        {
            Err Err = new Err(Ex);
            Response.Write(Err.Html());
        }

        return(Rno);
    }