// IMAGE URL UPLOAD TO DB protected void btnSubmit_Click(object sender, EventArgs e) { //itemcat = CategoryList.SelectedValue.ToString(); itemcat = CategoryList.SelectedItem.Text; itemname = iNameBox.Text; itemqty = qtyList.SelectedValue.ToString(); itempprice = pPriceBox.Text; itemrprice = rPriceBox.Text; itemnote = notebox.Text; itemimg = imgurl.Text; CsItem nitem = new CsItem(itemnum, itemcat, itemname, itempprice, itemrprice, itemnote, itemimg, itemqty,itemdate); try { ConnectionClass.RegisterItem(nitem); ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('New Item Registered!');</script>"); ClearTextBoxes(Page); CategoryList.ClearSelection(); testimg.ImageUrl = ""; } catch { ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('Error!');</script>"); } }
// 010 POS.ASPX // GET ITEM DETAIL WITHOUT FORMATTNG TO CURRENCY (NEED TO CONVERT TO DOUBLE) public static void GetItemDetails(CsItem itemdetail) { string iQuery = string.Format(@"SELECT itemID,itemCategory, itemName, itemPPrice,itemRPrice, itemNote,itemImage,itemQty,itemRegisterDate FROM tblItem WHERE itemID = ('{0}');", itemdetail.itemNumber); cmdString = new SqlCommand(iQuery, cntString); try { cntString.Open(); SqlDataAdapter da = new SqlDataAdapter(cmdString); DataTable dt = new DataTable(); DataSet ds = new DataSet(); da.Fill(dt); ds.Tables.Add(dt); itemdetail.itemCategory = dt.Rows[0]["itemCategory"].ToString(); itemdetail.itemName = dt.Rows[0]["itemName"].ToString(); itemdetail.itemQuantity = dt.Rows[0]["itemQty"].ToString(); itemdetail.itemNote = dt.Rows[0]["itemNote"].ToString(); itemdetail.itemPPrice = dt.Rows[0]["itemPPrice"].ToString(); itemdetail.itemRPrice = dt.Rows[0]["itemRPrice"].ToString(); itemdetail.itemImage = dt.Rows[0]["itemImage"].ToString(); } finally { cntString.Close(); } }
protected void btnSave_Click(object sender, EventArgs e) { iID = inumlbl.Text; iCategory = CategoryList.SelectedValue.ToString(); iName = iNameBox.Text; iPPrice = pPriceBox.Text; iRPrice = rPriceBox.Text; iNote = notebox.Text; iImage = imgURL.Text; iQuantity = qtyList.SelectedValue.ToString(); CsItem oldItemInfo = new CsItem(iID, iCategory, iName, iPPrice, iRPrice, iNote, iImage, iQuantity, iRday); try { ConnectionClass.UpdateItemDetail(oldItemInfo); ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('Updated!');</script>"); } catch { ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('Update failed');</script>"); } finally { DisableTextBoxes(Page); btnUpload.Visible = false; } }
// 021 item_add new page public static void RegisterItem(CsItem newItem) { string iQuery = string.Format(@"INSERT INTO tblItem (itemID,itemCategory,itemName,itemPPrice,itemRPrice,itemNote,itemImage,itemQty,itemRegisterDate) VALUES (NEXT VALUE FOR SQitem,(N'{0}'),(N'{1}'),('{2}'),('{3}'),(N'{4}'),(N'{5}'),('{6}'),GETDATE());", newItem.itemCategory, newItem.itemName, newItem.itemPPrice, newItem.itemRPrice, newItem.itemNote, newItem.itemImage, newItem.itemQuantity); cmdString = new SqlCommand(iQuery, cntString); try { cntString.Open(); cmdString.ExecuteNonQuery(); cntString.Close(); } finally { cntString.Close(); } }
public static void UpdateItemDetail(CsItem olditem) { string iQuery = string.Format(@"UPDATE tblItem SET itemCategory=(N'{0}'),itemName=(N'{1}'), itemPPrice=('{2}'),itemRPrice=('{3}'),itemNote=(N'{4}'),itemImage=(N'{5}'),itemQty=('{6}') WHERE itemID=('{7}');" , olditem.itemCategory, olditem.itemName, olditem.itemPPrice, olditem.itemRPrice, olditem.itemNote, olditem.itemImage, olditem.itemQuantity, olditem.itemNumber); cmdString = new SqlCommand(iQuery, cntString); try { cntString.Open(); cmdString.ExecuteNonQuery(); } finally { cntString.Close(); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["itemNum"] != null && !IsPostBack) { inumlbl.Text = Session["itemNum"].ToString(); // update 이전: 텍스트박스+ 드롭다운리스트 disabled, 업로드버튼 invisible btnUpload.Visible = false; DisableTextBoxes(Page); iID = inumlbl.Text; try { CsItem theitem = new CsItem(iID, iCategory, iName, iPPrice, iRPrice, iNote, iImage, iQuantity, iRday); ConnectionClass.GetItemDetails(theitem); // NO CURRENCY DISPLAY (FOR EASILY UPDATING) CategoryList.SelectedItem.Text = theitem.itemCategory; iNameBox.Text = theitem.itemName; qtyList.SelectedItem.Text = theitem.itemQuantity; notebox.Text = theitem.itemNote; pPriceBox.Text = theitem.itemPPrice; rPriceBox.Text = theitem.itemRPrice; testimg.ImageUrl = theitem.itemImage; imgURL.Text = theitem.itemImage; } catch { ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('error');</script>"); } finally { } } }
// SELECT ITEM (BY CLICK ITEM IMAGE) protected void SelectItem(object sender, EventArgs e) { if (Session["ii"] == null) { ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('Please select quantity ');</script>"); } else { ImageButton ibtn = (ImageButton)(sender); string itemNo = Convert.ToString(ibtn.CommandArgument); CsItem theitem = new CsItem(itemNo, iCategory, iName, iPPrice, iRPrice, iNote, iImage, iQuantity, iRday); ConnectionClass.GetItemDetails(theitem); bool found = false; if (iTable.Rows.Count > 0) // IF CART IS NOT EMPTY, { foreach (DataRow iRow in iTable.Rows) { if (Convert.ToString(iRow["No"]) == itemNo) // IF THE ITEM IS ALREADY IN THE CART LIST, UPDATE QTY { //double temp = Convert.ToDouble(iRow["qty"]); double temp = Convert.ToDouble(iRow["qty"]); // double uptemp = Convert.ToDouble(Session["ii"]) + temp; double uptemp = Convert.ToDouble(Session["ii"]) + temp; if (uptemp > Convert.ToDouble(theitem.itemQuantity)) // IF USER TRY TO ADD ITEM MORE THAN AVAILABLE NUMBER (=QUANTITY) { ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('You cannot add more than available stock ');</script>"); // ALERT MESSSAGE } else { iRow["qty"] = Convert.ToDouble(Session["ii"]) + temp; // UPDATE QUANTITY // iRow["amount"] = Math.Round(Convert.ToDouble(iRow["qty"]) * Convert.ToDouble(iRow["unitprice"]),2); iRow["amount"] = Math.Round(Convert.ToDouble(iRow["qty"]) * Convert.ToDouble(iRow["unitprice"]), 2); //iRow["tax"] = Convert.ToDouble(iRow["amount"]) * 0.13; iRow["tax"] = Math.Round(Convert.ToDouble(iRow["amount"]) * 0.13, 2); } found = true; } } if (!found) // IF ITEM IS NOT IN THE CART LIST, ADD ROW { iTable.Rows.Add("", itemNo, theitem.itemName, Math.Round(Convert.ToDouble(theitem.itemRPrice), 2), Convert.ToDouble(Session["ii"]), Math.Round(Convert.ToDouble(theitem.itemRPrice) * Convert.ToDouble(Session["ii"]), 2), Math.Round(Convert.ToDouble(theitem.itemRPrice) * Convert.ToDouble(Session["ii"]) * 0.13, 2)); } } else // IF CART IS EMPTY, { iTable.Rows.Add("", itemNo, theitem.itemName, Math.Round(Convert.ToDouble(theitem.itemRPrice), 2), Convert.ToDouble(Session["ii"]), Math.Round(Convert.ToDouble(theitem.itemRPrice) * Convert.ToDouble(Session["ii"]), 2), Math.Round(Convert.ToDouble(theitem.itemRPrice) * Convert.ToDouble(Session["ii"]) * 0.13, 2)); } GridView1.DataSource = iTable; // GridView1.DataBind(); object Sum = iTable.Compute(" SUM(amount) ", ""); double NetTotal = Math.Round(Double.Parse(Sum.ToString()), 2); double GrandTotal = Math.Round(NetTotal * 1.13, 2); subTotal.Text = NetTotal.ToString(); grandTotal.Text = GrandTotal.ToString(); Session["ii"] = null; } }