public static string SubmitDonor(string firstName, string lastName, string donorType, string donationType, string email, string organization, string templeAffiliation, string tuID, string donationDetail, string savedDonor, string existingDonor) { try { if (existingDonor == "-1") { DBConnect objDB = new DBConnect(ConfigurationManager.ConnectionStrings["appString"].ConnectionString); DateTime lastUpdateDate = DateTime.Now; string LastUpdateUser = HttpContext.Current.Session["Access_Net"].ToString(); string status = "Active"; string personID = HttpContext.Current.Session["PersonID"].ToString(); if (savedDonor != "" && savedDonor != null) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "_donation-CheckSavedName"; cmd.Parameters.AddWithValue("@name", savedDonor); DataSet ds2 = objDB.GetDataSetUsingCmdObj(cmd); if (ds2.Tables[0].Rows.Count > 0) { //ClientScript.RegisterStartupScript(this.GetType(), "confirmation", "alertconfirmationError('Saved Donor Name already exists.')", true); return("Donor Name Exists"); } } else { savedDonor = ""; } SqlCommand objCommand = new SqlCommand(); objCommand.CommandType = CommandType.StoredProcedure; objCommand.CommandText = "AddDonor"; objCommand.Parameters.AddWithValue("@DonorID", SqlDbType.Int).Direction = ParameterDirection.Output; objCommand.Parameters.AddWithValue("@DonorType", donorType); objCommand.Parameters.AddWithValue("@FirstName", firstName); objCommand.Parameters.AddWithValue("@LastName", lastName); objCommand.Parameters.AddWithValue("@TempleAffiliation", templeAffiliation); objCommand.Parameters.AddWithValue("@Organization", organization); objCommand.Parameters.AddWithValue("@TUID", tuID); objCommand.Parameters.AddWithValue("@Email", email); objCommand.Parameters.AddWithValue("@LastUpdateDate", lastUpdateDate); objCommand.Parameters.AddWithValue("@LastUpdateUser", LastUpdateUser); objCommand.Parameters.AddWithValue("@Status", status); objCommand.Parameters.AddWithValue("@SavedDonor", savedDonor); objDB.DoUpdateUsingCmdObj(objCommand); string donorID = objCommand.Parameters["@DonorID"].Value.ToString(); objCommand.Parameters.Clear(); objCommand.CommandType = CommandType.StoredProcedure; objCommand.CommandText = "AddDonation"; objCommand.Parameters.AddWithValue("@DonationID", SqlDbType.Int).Direction = ParameterDirection.Output; objCommand.Parameters.AddWithValue("@PersonID", personID); objCommand.Parameters.AddWithValue("@DonorID", donorID); objCommand.Parameters.AddWithValue("@DonationType", donationType); objCommand.Parameters.AddWithValue("@DonationDate", lastUpdateDate); objCommand.Parameters.AddWithValue("@DonationDetail", donationDetail); objCommand.Parameters.AddWithValue("@LastUpdateDate", lastUpdateDate); objCommand.Parameters.AddWithValue("@LastUpdateUser", LastUpdateUser); objCommand.Parameters.AddWithValue("@Status", status); int ret = objDB.DoUpdateUsingCmdObj(objCommand); //ClientScript.RegisterStartupScript(this.GetType(), "confirmation", "alertconfirmation()", true); return("true"); } else { string theDonorID = existingDonor; DateTime lastUpdateDate = DateTime.Now; string LastUpdateUser = HttpContext.Current.Session["Access_Net"].ToString(); string personID = HttpContext.Current.Session["PersonID"].ToString(); string status = "Active"; DBConnect objDB = new DBConnect(ConfigurationManager.ConnectionStrings["appString"].ConnectionString); SqlCommand objCommand = new SqlCommand(); objCommand.Parameters.Clear(); objCommand.CommandType = CommandType.StoredProcedure; objCommand.CommandText = "AddDonation"; objCommand.Parameters.AddWithValue("@DonationID", SqlDbType.Int).Direction = ParameterDirection.Output; objCommand.Parameters.AddWithValue("@PersonID", personID); objCommand.Parameters.AddWithValue("@DonorID", theDonorID); objCommand.Parameters.AddWithValue("@DonationType", donationType); objCommand.Parameters.AddWithValue("@DonationDate", lastUpdateDate); objCommand.Parameters.AddWithValue("@DonationDetail", donationDetail); objCommand.Parameters.AddWithValue("@LastUpdateDate", lastUpdateDate); objCommand.Parameters.AddWithValue("@LastUpdateUser", LastUpdateUser); objCommand.Parameters.AddWithValue("@Status", status); DataSet ds = objDB.GetDataSetUsingCmdObj(objCommand); return("true"); //ClientScript.RegisterStartupScript(this.GetType(), "confirmation", "alertconfirmation()", true); } } catch (Exception ex) { return("error"); //ClientScript.RegisterStartupScript(this.GetType(), "confirmation", "alertconfirmationError()", true); } }
public static string AddToInventory(string Upc, string Category, string Packaging, string Weight, int Point, int Quantity) { try { DBConnect objDB = new DBConnect(connectionStr); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "_scan-AddCategory"; cmd.Parameters.AddWithValue("@type", Category); cmd.Parameters.AddWithValue("@packaging", Packaging); cmd.Parameters.AddWithValue("@last_update_user", HttpContext.Current.Session["Access_Net"].ToString()); cmd.Parameters.AddWithValue("@last_update_date", DateTime.Today); cmd.Parameters.Add("@CatID", SqlDbType.Int).Direction = ParameterDirection.Output; SqlConnection sqlConnection = new SqlConnection(connectionStr); int returnInt; try { cmd.Connection = sqlConnection; cmd.Connection.Open(); returnInt = cmd.ExecuteNonQuery(); cmd.Connection.Close(); } catch (Exception ex) { returnInt = -1; } int catID = Convert.ToInt32(cmd.Parameters["@CatID"].Value.ToString()); cmd = new SqlCommand(); string weightSub = Weight.Substring(0, 1); int weightInt; bool isWeight = int.TryParse(weightSub, out weightInt); if (!isWeight) { Weight = "n/a"; } cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "_scan-AddToInventory"; cmd.Parameters.AddWithValue("@upc", Upc); cmd.Parameters.AddWithValue("@categoryID", catID); cmd.Parameters.AddWithValue("@weight", Weight); cmd.Parameters.AddWithValue("@point", Point); cmd.Parameters.AddWithValue("@quantity", Quantity); cmd.Parameters.AddWithValue("@user", HttpContext.Current.Session["Access_Net"].ToString()); cmd.Parameters.AddWithValue("@date", DateTime.Today); int ret = objDB.DoUpdateUsingCmdObj(cmd); return(CheckInventory(Upc)); } catch (Exception ex) { return("false"); } }
public static string CheckoutCart(string ItemCount, string PointCount, List <CheckoutItem> itemList) { Cart cart; int cartID; DBConnect objDB = new DBConnect(connectionStr); try { JavaScriptSerializer js = new JavaScriptSerializer(); var items = itemList; cart = (Cart)HttpContext.Current.Session["cart"]; if (items.Count == 0 || cart == null) { return("No Items"); } SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "CreateReceipt"; cmd.Parameters.AddWithValue("@personID", HttpContext.Current.Session["PersonID"].ToString()); cmd.Parameters.AddWithValue("@points", Convert.ToInt32(PointCount)); cmd.Parameters.AddWithValue("@quantity", Convert.ToInt32(ItemCount)); cmd.Parameters.AddWithValue("@lastUpdateUser", HttpContext.Current.Session["Access_Net"].ToString()); cmd.Parameters.AddWithValue("@lastUpdateDate", DateTime.Now); cmd.Parameters.AddWithValue("@checkoutDate", DateTime.Now); cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output; objDB.DoUpdateUsingCmdObj(cmd); cart.CartID = Convert.ToInt32(cmd.Parameters["@id"].Value.ToString()); cartID = cart.CartID; foreach (CheckoutItem item in items) { cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "UpdateItemCheckedOut"; cmd.Parameters.AddWithValue("@CategoryID", item.CategoryID); cmd.Parameters.AddWithValue("@Quantity", item.Quantity); cmd.Parameters.AddWithValue("@ReceiptID", cart.CartID); cmd.Parameters.AddWithValue("@lastUpdateUser", HttpContext.Current.Session["Access_Net"].ToString()); cmd.Parameters.AddWithValue("@lastUpdateDate", DateTime.Now); objDB.DoUpdateUsingCmdObj(cmd); } cart = new Cart(); HttpContext.Current.Session["cart"] = cart; return(cartID.ToString()); } catch (Exception ex) { cart = new Cart(); HttpContext.Current.Session["cart"] = cart; return("error"); } }
public static string CheckInventory(string upc) { Boolean local = true; ////*****For testing without Database connection***// //if (upc == "43100071129") //{ // item.Upc = upc; // item.Category = "Notebook"; // item.Weight = 12.0; // item.Point = 3; // item.QOH = 100; // item.Image = ""; //} //else if (upc == "086216118456") //{ // item.Upc = upc; // item.Category = "Pencil"; // item.Weight = 2.0; // item.Point = 1; // item.QOH = 100; // item.Image = ""; //} //else if (upc == "819913012471") //{ // item.Upc = upc; // item.Category = "Box"; // item.Weight = 3.0; // item.Point = 5; // item.QOH = 100; // item.Image = ""; //} //else //{ // item.Upc = upc; // item.Category = "Item Not Found"; // item.Weight = 0; // item.Point = 0; // item.QOH = 0; // item.Image = ""; //} //cartPoints = addToCart(item); //if (cartPoints > MAX_POINTS) //{ // item.Flag = "true"; //} //return javaScriptSerializer.Serialize(item); //************************************************// Item item = new Item(); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); DataSet ds; int MAX_POINTS = getMaxPoint(); int cartPoints; try { if (local) { DBConnect objDB = new DBConnect(@"Server=localhost\SQLEXPRESS;Database=CherryPantry;Trusted_Connection=True;"); string query = "SELECT * FROM Items WHERE[UPC] LIKE '" + upc + "';"; ds = objDB.GetDataSet(query); } else { DBConnect objDB = new DBConnect(ConfigurationManager.ConnectionStrings["appString"].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "_scan-GetItemByUPC"; cmd.Parameters.AddWithValue("@UPC", upc); ds = objDB.GetDataSetUsingCmdObj(cmd); } //Item Found if (ds.Tables[0].Rows.Count != 0) { item.Upc = ds.Tables[0].Rows[0]["UPC"].ToString(); item.Category = ds.Tables[0].Rows[0]["Type"].ToString(); item.Weight = ds.Tables[0].Rows[0]["Weight"].ToString(); item.Point = Convert.ToInt32(ds.Tables[0].Rows[0]["Point"]); item.QOH = Convert.ToInt32(ds.Tables[0].Rows[0]["Quantity"]); item.Image = ds.Tables[0].Rows[0]["Image"].ToString(); } //Item Not Found else { item = new Item(upc, "Item Not Found", 0); } cartPoints = addToCart(item); if (cartPoints > MAX_POINTS) { item.Flag = "true"; } return(javaScriptSerializer.Serialize(item)); } catch (Exception ex) { item = new Item(upc, "Item Not Found", 0); return(javaScriptSerializer.Serialize(item)); } }