예제 #1
0
    //// ///// //Update Item
    //Update item
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            string fileName  = Path.GetFileName(FUpimg.PostedFile.FileName);
            string extension = Path.GetExtension(FUpimg.PostedFile.FileName);

            SqlConnection cn  = new SqlConnection(ConnectionString);
            SqlCommand    cmd = new SqlCommand("SP_POS_Update_Item", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cn.Open();

            cmd.Parameters.AddWithValue("@ItemCode", txtProductCode.Text);
            cmd.Parameters.AddWithValue("@ItemName", txtItemName.Text);
            cmd.Parameters.AddWithValue("@ItemQty", Convert.ToDecimal(txtItemQty.Text));
            cmd.Parameters.AddWithValue("@PurchasePrice", Convert.ToDecimal(txtPurchasePrice.Text));
            cmd.Parameters.AddWithValue("@RetailPrice", Convert.ToDecimal(txtRetailPrice.Text));
            cmd.Parameters.AddWithValue("@Discount", Convert.ToDecimal(txtItemDiscRate.Text));
            cmd.Parameters.AddWithValue("@ItemCategory", DDLCategory.Text);
            cmd.Parameters.AddWithValue("@Lastupdateby", Request.Cookies["POSCookies"]["UserID"].ToString());

            if (FUpimg.HasFile)
            {
                if (extension == ".png" || extension == ".jpg" || extension == ".PNG" || extension == ".JPG")
                {
                    cmd.Parameters.AddWithValue("@Itemphoto", "~/ItemsPhoto/" + txtProductCode.Text + extension);

                    string strPath = MapPath("ItemsPhoto/") + txtProductCode.Text + extension;
                    FUpimg.SaveAs(strPath);
                    LoadDetailsData(lblItemID.Text);
                    // imgItemPhoto.ImageUrl = "/ItemsPhoto/" + txtProductCode.Text + extension;
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Only .jpg and .Png Format can be support')", true);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@Itemphoto", imgItemPhoto.ImageUrl);
            }

            cmd.ExecuteNonQuery();
            cn.Close();


            lblmsg.Visible = true;
            lblmsg.Text    = "Successfully Updated";
            //ItemsListDataBind();
            this.MpeEditItemShow.Show();
        }
        catch (Exception ex)
        {
            lblmsg.Visible = true;
            lblmsg.Text    = ex.Message;
            this.MpeEditItemShow.Show();
        }
    }
예제 #2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string fileName  = Path.GetFileName(FUpimg.PostedFile.FileName);
            string extension = Path.GetExtension(FUpimg.PostedFile.FileName);

            SqlConnection cn  = new SqlConnection(ConnectionString);
            SqlCommand    cmd = new SqlCommand("SP_POS_Insert_Items", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cn.Open();

            cmd.Parameters.AddWithValue("@ItemCode", txtProductCode.Text);
            cmd.Parameters.AddWithValue("@ItemName", txtproductName.Text);
            cmd.Parameters.AddWithValue("@PurchasePrice", txtpurchasePrice.Text);
            cmd.Parameters.AddWithValue("@RetailPrice", txtRetailPrice.Text);
            cmd.Parameters.AddWithValue("@ItemQty", txtItemQty.Text);
            cmd.Parameters.AddWithValue("@ItemCategory", DDLCategory.Text);
            cmd.Parameters.AddWithValue("@Discount", txtItemDiscRate.Text);
            cmd.Parameters.AddWithValue("@LogBy", Request.Cookies["POSCookies"]["UserID"].ToString());
            //  cmd.Parameters.AddWithValue("@Itemphoto", "ItemsPhoto/" + txtProductCode.Text + extension);

            if (FUpimg.HasFile)
            {
                if (extension == ".png" || extension == ".jpg" || extension == ".PNG" || extension == ".JPG")
                {
                    cmd.Parameters.AddWithValue("@Itemphoto", "~/ItemsPhoto/" + txtProductCode.Text + extension);

                    string strPath = MapPath("ItemsPhoto/") + txtProductCode.Text + extension;
                    FUpimg.SaveAs(strPath);

                    //string uploadFolder = Request.PhysicalApplicationPath + "ItemsPhoto\\";
                    // FUpimg.SaveAs(uploadFolder + txtProductCode.Text + extension);
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('.jpg and .Png Format can be support')", true);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@Itemphoto", "~/ItemsPhoto/item.png"); //DBNull.Value for Database NULL value
            }

            cmd.ExecuteNonQuery();
            cn.Close();
            lblmessage.Text = "Successfully Saved";
        }
        catch (Exception ex)
        {
            lblmessage.Text = ex.Message;
        }
    }