public List <ClientDocsEntity> GetClientDocs(long id) { string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; SqlDataAdapter adapter; DataSet ds = new DataSet(); List <ClientDocsEntity> retlst = new List <ClientDocsEntity>(); try { using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand("USP_GetClientDocsbyID", 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++) { ClientDocsEntity obj = new ClientDocsEntity(); obj.CLIENT_ID = ds.Tables[0].Rows[i]["CLIENT_ID"] == DBNull.Value ? 0 : Convert.ToInt64(ds.Tables[0].Rows[i]["CLIENT_ID"].ToString()); obj.ORG_FILE_NAME = ds.Tables[0].Rows[i]["ORG_FILE_NAME"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["ORG_FILE_NAME"].ToString(); obj.PHY_FILE_NAME = ds.Tables[0].Rows[i]["PHY_FILE_NAME"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["PHY_FILE_NAME"].ToString(); obj.REMARKS = ds.Tables[0].Rows[i]["REMARKS"] == DBNull.Value ? "" : Convert.ToString(ds.Tables[0].Rows[i]["REMARKS"]); retlst.Add(obj); } } } catch (Exception ex) { throw ex; } return(retlst); }
public DbStatusEntity InsertClientDocs(ClientDocsEntity obj) { DbStatusEntity objreturn = new DbStatusEntity(); string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; try { using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand("USP_InsertClientDocs", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CLIENT_ID", obj.CLIENT_ID); cmd.Parameters.AddWithValue("@ORG_FILE_NAME", obj.ORG_FILE_NAME); cmd.Parameters.AddWithValue("@PHY_FILE_NAME", obj.PHY_FILE_NAME); cmd.Parameters.AddWithValue("@REMARKS", obj.REMARKS); 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); }
public void ProcessRequest(HttpContext context) { if (context.Request.QueryString["action"] != null) { actiontype = context.Request.QueryString["action"].ToString(); folderpath = System.Configuration.ConfigurationManager.AppSettings["ClientFolderPath"]; clientid = context.Request.QueryString["clientid"].ToString(); phy_file_name = context.Request.QueryString["phy_file_name"].ToString(); if (actiontype.Trim().ToUpper() == "UPLOAD") { //for uploading new File 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)) { org_file_name = context.Request.QueryString["org_file_name"].ToString(); remarks = context.Request.QueryString["remarks"].ToString(); if (!Directory.Exists(Savepath)) { Directory.CreateDirectory(Savepath); } postedFile.SaveAs(Savepath + "\\" + phy_file_name); ClientDocsEntity objdocs = new ClientDocsEntity(); objdocs.CLIENT_ID = Convert.ToInt64(clientid); objdocs.REMARKS = remarks; objdocs.ORG_FILE_NAME = org_file_name; objdocs.PHY_FILE_NAME = phy_file_name; List <DbStatusEntity> details = new List <DbStatusEntity>(); details.Add(new ClientMasterDAO().InsertClientDocs(objdocs)); //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") { 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 ClientMasterDAO().DeleteClientDocs(Convert.ToInt64(clientid), phy_file_name)); } else if (actiontype.Trim().ToUpper() == "DOWNLOAD") { 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(); } } } }