Пример #1
0
        public List <CatalogImageEntity> GetCalatogImages(long id)
        {
            string                    CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            SqlDataAdapter            adapter;
            DataSet                   ds     = new DataSet();
            List <CatalogImageEntity> retlst = new List <CatalogImageEntity>();

            try
            {
                using (SqlConnection con = new SqlConnection(CS))
                {
                    SqlCommand cmd = new SqlCommand("USP_GetCatalogImagesbyID", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@ID", id);
                    con.Open();
                    adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(ds);

                    for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                    {
                        CatalogImageEntity obj = new CatalogImageEntity();
                        obj.CATALOG_ID    = ds.Tables[0].Rows[i]["CATALOG_ID"] == DBNull.Value ? 0 : Convert.ToInt64(ds.Tables[0].Rows[i]["CATALOG_ID"].ToString());
                        obj.PHY_FILE_NAME = ds.Tables[0].Rows[i]["PHY_FILE_NAME"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["PHY_FILE_NAME"].ToString();
                        retlst.Add(obj);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(retlst);
        }
Пример #2
0
        public DbStatusEntity InsertCatalogImages(CatalogImageEntity obj)
        {
            DbStatusEntity objreturn = new DbStatusEntity();
            string         CS        = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            try
            {
                using (SqlConnection con = new SqlConnection(CS))
                {
                    SqlCommand cmd = new SqlCommand("USP_InsertCatalogImages", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@CATALOG_ID", obj.CATALOG_ID);
                    cmd.Parameters.AddWithValue("@ORG_FILE_NAME", obj.ORG_FILE_NAME);
                    cmd.Parameters.AddWithValue("@PHY_FILE_NAME", obj.PHY_FILE_NAME);

                    cmd.Parameters.Add("@RESULT", SqlDbType.Int);
                    cmd.Parameters["@RESULT"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@CNT", SqlDbType.Int);
                    cmd.Parameters["@CNT"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@MSG", SqlDbType.NVarChar, 500);
                    cmd.Parameters["@MSG"].Direction = ParameterDirection.Output;
                    con.Open();
                    cmd.ExecuteNonQuery();
                    objreturn.RESULT = Convert.ToInt32(cmd.Parameters["@RESULT"].Value);
                    objreturn.CNT    = Convert.ToInt32(cmd.Parameters["@CNT"].Value);
                    objreturn.MSG    = Convert.ToString(cmd.Parameters["@MSG"].Value);
                    con.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(objreturn);
        }
Пример #3
0
        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            if (context.Request.QueryString["action"] != null)
            {
                actiontype = context.Request.QueryString["action"].ToString();
                if (actiontype.Trim().ToUpper() == "UPLOAD")
                {
                    //for uploading new File
                    folderpath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
                    var    postedFile = context.Request.Files[0];
                    string filesize   = System.Configuration.ConfigurationManager.AppSettings["FileSize"];
                    mFileSize = postedFile.ContentLength / 1048576;
                    string Savepath = context.Server.MapPath("~//" + folderpath);
                    if (mFileSize <= Convert.ToInt32(filesize))
                    {
                        // Get Server Folder to upload file
                        catelogid     = context.Request.QueryString["catalogid"].ToString();
                        phy_file_name = context.Request.QueryString["phy_file_name"].ToString();
                        org_file_name = context.Request.QueryString["org_file_name"].ToString();

                        if (!Directory.Exists(Savepath))
                        {
                            Directory.CreateDirectory(Savepath);
                        }

                        postedFile.SaveAs(Savepath + "\\" + phy_file_name);

                        CatalogImageEntity objimg = new CatalogImageEntity();
                        objimg.CATALOG_ID    = Convert.ToInt64(catelogid);
                        objimg.IS_THUMBNAIL  = true;
                        objimg.ORG_FILE_NAME = org_file_name;
                        objimg.PHY_FILE_NAME = phy_file_name;
                        List <DbStatusEntity> details = new List <DbStatusEntity>();

                        details.Add(new CatalogMasterDAO().InsertCatalogImages(objimg));

                        //Set response message
                        string msg = "{";
                        msg += string.Format("error:'{0}',\n", string.Empty);
                        msg += string.Format("upfile:'{0}'\n", phy_file_name);
                        msg += "}";
                        context.Response.Write(msg);
                    }
                }
                else if (actiontype.Trim().ToUpper() == "DELETE")
                {
                    folderpath    = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
                    catelogid     = context.Request.QueryString["catalogid"].ToString();
                    phy_file_name = context.Request.QueryString["phy_file_name"].ToString();

                    string Savepath = context.Server.MapPath("~//" + folderpath);

                    if (File.Exists(Savepath + "\\" + phy_file_name))
                    {
                        File.Delete(Savepath + "\\" + phy_file_name);
                    }

                    List <DbStatusEntity> details = new List <DbStatusEntity>();

                    details.Add(new CatalogMasterDAO().DeleteCatalogImages(Convert.ToInt64(catelogid), phy_file_name));
                }
                else if (actiontype.Trim().ToUpper() == "DOWNLOAD")
                {
                    folderpath    = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
                    catelogid     = context.Request.QueryString["catalogid"].ToString();
                    phy_file_name = context.Request.QueryString["phy_file_name"].ToString();
                    org_file_name = context.Request.QueryString["org_file_name"].ToString();
                    string Savepath = context.Server.MapPath("~//" + folderpath);
                    if (File.Exists(Savepath + "\\" + phy_file_name))
                    {
                        context.Response.Clear();
                        context.Response.ContentType = "application/octet-stream";
                        context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", org_file_name));
                        context.Response.WriteFile(Savepath + "\\" + phy_file_name);
                        context.Response.Flush();
                    }
                }
            }
        }