Ejemplo n.º 1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int b = 0;

        if (ddlDocumentName.SelectedIndex == 0)
        {
            DisplayMessage("Select Document Name");
            ddlDocumentName.Focus();
            return;
        }


        if (txtFileName.Text == "")
        {
            DisplayMessage("Enter File Name");
            txtFileName.Focus();
            return;
        }


        if (UploadFile.HasFile == false)
        {
            DisplayMessage("Upload The File");
            UploadFile.Focus();
            return;
        }


        string filepath = "~/" + "HR" + "/" + HidEmpId.Value + "/" + UploadFile.FileName;

        UploadFile.SaveAs(Server.MapPath(filepath));
        string filename = UploadFile.FileName;
        string ext      = Path.GetExtension(filepath);

        string NewfileName = txtFileName.Text + "" + ext;

        Stream       fs = UploadFile.PostedFile.InputStream;
        BinaryReader br = new BinaryReader(fs);

        Byte[] bytes = br.ReadBytes((Int32)fs.Length);

        string FileTypeId = "0";

        DataTable dt = ObjFile.Get_FileTransaction(strCompId, FileTypeId);


        dt = new DataView(dt, "File_Name='" + txtFileName.Text + "'", "", DataViewRowState.CurrentRows).ToTable();
        if (dt.Rows.Count > 0)
        {
            DisplayMessage("File Name Already Exists");
            txtFileName.Focus();
            txtFileName.Text = "";
            return;
        }

        b = ObjFile.Insert_In_FileTransaction(strCompId, ddlDirectory.SelectedValue, ddlDocumentName.SelectedValue, "0", NewfileName, DateTime.Now.ToString(), bytes, filepath, txtExpiryDate.Text, "", "0", "", "", "", false.ToString(), DateTime.Now.ToString(), true.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString());

        if (b != 0)
        {
            DisplayMessage("Record Saved");
            FillGrid();
            DataTable DtFile = (DataTable)Session["File"];
            DtFile = new DataView(DtFile, "Directory_Id =" + ddlDirectory.SelectedValue + "", "", DataViewRowState.CurrentRows).ToTable();

            gvFileMaster.DataSource = DtFile;
            gvFileMaster.DataBind();
            Reset();
            Paneladddocument.Visible = false;
        }
        else
        {
            DisplayMessage("Record Not Saved");
        }
    }
Ejemplo n.º 2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int b = 0;

        if (ddlDirectory.SelectedIndex == 0)
        {
            DisplayMessage("Select Directory Name");
            ddlDirectory.Focus();
            return;
        }
        if (ddlDocumentName.SelectedIndex == 0)
        {
            DisplayMessage("Select Document Name");
            ddlDocumentName.Focus();
            return;
        }


        if (txtFileName.Text == "")
        {
            DisplayMessage("Enter File Name");
            txtFileName.Focus();
            return;
        }


        if (UploadFile.HasFile == false)
        {
            DisplayMessage("Upload The File");
            UploadFile.Focus();
            return;
        }


        string filepath = "~/" + "ArcaWing" + "/" + ddlDirectory.SelectedItem + "/" + UploadFile.FileName;

        UploadFile.SaveAs(Server.MapPath(filepath));
        string filename = UploadFile.FileName;
        string ext      = Path.GetExtension(filepath);

        string NewfileName = txtFileName.Text + "" + ext;

        Stream       fs = UploadFile.PostedFile.InputStream;
        BinaryReader br = new BinaryReader(fs);

        Byte[] bytes = br.ReadBytes((Int32)fs.Length);

        if (editid.Value == "")
        {
            string FileTypeId = "0";

            DataTable dt = ObjFile.Get_FileTransaction(strCompId, FileTypeId);


            dt = new DataView(dt, "File_Name='" + txtFileName.Text + "'", "", DataViewRowState.CurrentRows).ToTable();
            if (dt.Rows.Count > 0)
            {
                DisplayMessage("File Name Already Exists");
                txtFileName.Focus();
                txtFileName.Text = "";
                return;
            }
            //dt = new DataView(dt, "Directory_Id="+ddlDirectory.SelectedValue+" ", "", DataViewRowState.CurrentRows).ToTable();
            //if (dt.Rows.Count > 0)
            //{
            //    DisplayMessage("Directory Exists");
            //    txtContentName.Focus();
            //    return;

            //}



            b = ObjFile.Insert_In_FileTransaction(strCompId, ddlDirectory.SelectedValue, ddlDocumentName.SelectedValue, "0", NewfileName, DateTime.Now.ToString(), bytes, filepath, txtExpiryDate.Text, "", "0", "", "", "", false.ToString(), DateTime.Now.ToString(), true.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString());

            if (b != 0)
            {
                DisplayMessage("Record Saved");
                FillGrid();
                Reset();
            }
            else
            {
                DisplayMessage("Record Not Saved");
            }
        }
        else
        {
            string    FileTransactionid = "0";
            DataTable dt = ObjFile.Get_FileTransaction(strCompId, FileTransactionid);


            string FileTransaction = string.Empty;


            try
            {
                FileTransaction = (new DataView(dt, "Trans_Id='" + editid.Value + "'", "", DataViewRowState.CurrentRows).ToTable()).Rows[0]["File_Name"].ToString();
            }
            catch
            {
                FileTransaction = "";
            }
            dt = new DataView(dt, "File_Name='" + txtFileName.Text + "' and File_Name<>'" + FileTransaction + "'  ", "", DataViewRowState.CurrentRows).ToTable();
            if (dt.Rows.Count > 0)
            {
                DisplayMessage("File Name Already Exists");
                txtFileName.Focus();
                txtFileName.Text = "";
                return;
            }
            //dt = new DataView(dt, "Content_Type='" + txtContentName.Text + "'  ", "", DataViewRowState.CurrentRows).ToTable();
            //if (dt.Rows.Count > 0)
            //{
            //    DisplayMessage("Content Name Already Exists");
            //    txtContentName.Focus();
            //    return;

            //}



            b = ObjFile.Update_In_FileTransaction(strCompId, editid.Value, ddlDirectory.SelectedValue, ddlDocumentName.SelectedValue, ddlFiletype.SelectedValue, NewfileName, DateTime.Now.ToString(), bytes, filepath, DateTime.Now.ToString(), "", "0", "", "", "", false.ToString(), DateTime.Now.ToString(), true.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString());

            if (b != 0)
            {
                btnList_Click(null, null);
                DisplayMessage("Record Updated");
                Reset();
                FillGrid();
            }
            else
            {
                DisplayMessage("Record Not Updated");
            }
        }
    }