Ejemplo n.º 1
0
    //private void FillMemberCode(int MemberCode)
    //{
    //    try
    //    {
    //        tbl_MemberMasterProp Objtbl_MemberMasterProp = new tbl_MemberMasterProp();
    //        Objtbl_MemberMasterProp.MemberCode = MemberCode;

    //        int PageCount = 0;
    //        tbl_MemberMasterBAL Objtbl_MemberMasterBAL = new tbl_MemberMasterBAL();
    //        DataSet dsData = Objtbl_MemberMasterBAL.Select_Data(Objtbl_MemberMasterProp, ref PageCount);

    //        txtMemberName.Text = Convert.ToString(dsData.Tables[0].Rows[0]["MemberName"]);
    //        txtCurrentAddress.Text = Convert.ToString(dsData.Tables[0].Rows[0]["CurrentAddress"]);
    //        ddlCountryCode.SelectedValue = Convert.ToString(dsData.Tables[0].Rows[0]["CountryCode"]);
    //        ddlStateCode.SelectedValue = Convert.ToString(dsData.Tables[0].Rows[0]["StateCode"]);
    //        ddlCityCode.SelectedValue = Convert.ToString(dsData.Tables[0].Rows[0]["CityCode"]);
    //        txtPermanentAddress.Text = Convert.ToString(dsData.Tables[0].Rows[0]["PermanentAddress"]);
    //        txtContactNo.Text = Convert.ToString(dsData.Tables[0].Rows[0]["ContactNo"]);
    //        txtEmailID.Text = Convert.ToString(dsData.Tables[0].Rows[0]["EmailID"]);
    //        txtDOB.Text = Convert.ToString(dsData.Tables[0].Rows[0]["DOB"]);
    //        ddlQualificationCode.SelectedValue = Convert.ToString(dsData.Tables[0].Rows[0]["QualificationCode"]);
    //        ddlOccupationCode.SelectedIndex = Convert.ToInt32(dsData.Tables[0].Rows[0]["OccupationCode"]);
    //        ddlMaritalStatus.SelectedIndex = Convert.ToInt32(dsData.Tables[0].Rows[0]["MaritalStatusCode"]);
    //        ddlGender.SelectedIndex = Convert.ToInt32(dsData.Tables[0].Rows[0]["Gender"]);
    //        ddlNativePlace.SelectedIndex = Convert.ToInt32(dsData.Tables[0].Rows[0]["NativePlaceCode"]);
    //        ddlNationality.SelectedIndex = Convert.ToInt32(dsData.Tables[0].Rows[0]["NationalityCode"]);
    //        ddlPhysicallyChallanged.SelectedIndex = Convert.ToInt32(dsData.Tables[0].Rows[0]["PhysicallyChallangedCode"]);
    //        ddlRelationshipCode.SelectedIndex = Convert.ToInt32(dsData.Tables[0].Rows[0]["RelationshipCode"]);
    //        ddlParentCode.SelectedValue = Convert.ToString(dsData.Tables[0].Rows[0]["ParentCode"]);

    //        Objtbl_MemberMasterProp.PhotoPath = sFilename;

    //        ViewState["EditCode"] = MemberCode;
    //    }
    //    catch (Exception ex)
    //    {
    //        throw ex;
    //    }
    //}

    #endregion

    #region "--------------- Buttons Events ---------------"

    protected void imgbtnSave_Click(object sender, ImageClickEventArgs e)
    {
        string sSavePath = "";
        string sFilename = "";

        try
        {
            if (chkDeleteFilePath.Checked == false)
            {
                // Set constant values
                sSavePath = "../MembersPhotos/";

                // If file field isn’t empty
                if (flFilePath.PostedFile != null && flFilePath.PostedFile.ContentLength > 0)
                {
                    // Check file size (mustn’t be 0)
                    HttpPostedFile myFile   = flFilePath.PostedFile;
                    int            nFileLen = myFile.ContentLength;
                    if (nFileLen == 0)
                    {
                        ShowGuidMessage(0, new Exception("No file was uploaded."));
                        return;
                    }

                    // Check file extension (must be JPG or pdf)
                    if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")
                    {
                        ShowGuidMessage(0, new Exception("The file must have an extension of JPG or pdf"));
                        return;
                    }

                    // Read file into a data stream
                    byte[] myData = new Byte[nFileLen];
                    myFile.InputStream.Read(myData, 0, nFileLen);

                    // Make sure a duplicate file doesn’t exist.  If it does, keep on appending an
                    // incremental numeric until it is unique
                    sFilename = System.IO.Path.GetFileName(myFile.FileName);
                    int file_append = 0;
                    while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))
                    {
                        file_append++;
                        sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)
                                    + file_append.ToString() + System.IO.Path.GetExtension(myFile.FileName).ToLower();
                    }

                    // Save the stream to disk
                    System.IO.FileStream newFile = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename),
                                                                            System.IO.FileMode.Create);
                    newFile.Write(myData, 0, myData.Length);
                    newFile.Close();

                    // Check whether the file is really a JPEG by opening it
                    System.Drawing.Image.GetThumbnailImageAbort myCallBack =
                        new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                    Bitmap myBitmap;
                    try
                    {
                        myBitmap = new Bitmap(Server.MapPath(sSavePath + sFilename));

                        tdUploadedFile.Visible   = true;
                        tdUploadedFile.InnerHtml = "<a href=\"..\\" + sSavePath + sFilename + ">Download Attachment</a>";

                        // Displaying success information
                        //tdError.InnerText = "File uploaded successfully!";

                        // Destroy objects
                        myBitmap.Dispose();
                    }
                    catch
                    {
                        // The file wasn't a valid jpg file
                        System.IO.File.Delete(Server.MapPath(sSavePath + sFilename));
                        ShowGuidMessage(0, new Exception("The file wasn't a valid jpg file"));
                        return;
                    }
                }
            }

            if (sFilename == "" && Convert.ToInt32(ViewState["EditCode"]) > 0)
            {
                sFilename = Convert.ToString(ViewState["PhotoPath"]);
            }
            else if (sFilename == "" && Convert.ToInt32(ViewState["EditCode"]) <= 0)
            {
                sFilename = "noimage.jpg";
            }
            else if (chkDeleteFilePath.Checked == true)
            {
                if (Convert.ToInt32(ViewState["EditCode"]) > 0)
                {
                    System.IO.File.Delete(Server.MapPath(sSavePath + Convert.ToString(ViewState["PhotoPath"])));
                }
                sFilename = "noimage.jpg";
            }
            tbl_MemberMasterProp Objtbl_MemberMasterProp = new tbl_MemberMasterProp();
            Objtbl_MemberMasterProp.MemberCode       = Convert.ToInt32(ViewState["EditCode"]);
            Objtbl_MemberMasterProp.MemberName       = txtMemberName.Text;
            Objtbl_MemberMasterProp.CurrentAddress   = txtCurrentAddress.Text;
            Objtbl_MemberMasterProp.CountryCode      = Convert.ToInt32(ddlCountryCode.SelectedValue);
            Objtbl_MemberMasterProp.StateCode        = Convert.ToInt32(ddlStateCode.SelectedValue);
            Objtbl_MemberMasterProp.CityCode         = Convert.ToInt32(ddlCityCode.SelectedValue);
            Objtbl_MemberMasterProp.PermanentAddress = txtPermanentAddress.Text;
            Objtbl_MemberMasterProp.ContactNo        = txtContactNo.Text;
            Objtbl_MemberMasterProp.EmailID          = txtEmailID.Text;
            Objtbl_MemberMasterProp.Password         = "******";
            Objtbl_MemberMasterProp.DOB = new DateTime(Convert.ToInt32(txtDOB.Text.Split('/')[2]), Convert.ToInt32(txtDOB.Text.Split('/')[1]), Convert.ToInt32(txtDOB.Text.Split('/')[0]));
            Objtbl_MemberMasterProp.QualificationCode      = Convert.ToInt32(ddlQualificationCode.SelectedValue);
            Objtbl_MemberMasterProp.OccupationCode         = Convert.ToInt32(ddlOccupationCode.Text);
            Objtbl_MemberMasterProp.MaritalStatusCode      = Convert.ToInt32(ddlMaritalStatus.SelectedIndex);
            Objtbl_MemberMasterProp.Gender                 = Convert.ToBoolean(ddlGender.SelectedIndex);
            Objtbl_MemberMasterProp.NativePlaceCode        = Convert.ToInt32(ddlNativePlace.SelectedValue);
            Objtbl_MemberMasterProp.NationalityCode        = Convert.ToInt32(ddlNationality.SelectedValue);
            Objtbl_MemberMasterProp.PhysicalChallangedCode = Convert.ToInt32(ddlPhysicallyChallanged.SelectedIndex);
            Objtbl_MemberMasterProp.RelationshipCode       = Convert.ToInt32(ddlRelationshipCode.SelectedIndex);
            Objtbl_MemberMasterProp.ParentCode             = Convert.ToInt32(ddlParentCode.SelectedValue);
            Objtbl_MemberMasterProp.PhotoPath              = sFilename;

            tbl_MemberMasterBAL Objtbl_MemberMasterBAL = new tbl_MemberMasterBAL();
            Objtbl_MemberMasterBAL.InsertUpdate_Data(Objtbl_MemberMasterProp);
            ShowGuidMessage(1, null);
            mdlPopupNewEntry.Hide();
            FillData();
        }
        catch (Exception ex)
        {
            ShowGuidMessage(0, ex); //MessageBox.Show(ex.Message);
        }
    }