Ejemplo n.º 1
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Attendance.Entities.UserInfo objInfo = new UserInfo();
            string timezone = "";

            try
            {
                if (Convert.ToInt32(Session["TimeZoneID"]) == 2)
                {
                    timezone = "Eastern Standard Time";
                }
                else
                {
                    timezone = "India Standard Time";

                }
                DateTime ISTTime = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(timezone));

                var CurentDatetime = ISTTime;
                hdnToday.Value = ISTTime.ToString("MM/dd/yyyy");


                btnUpdate.Attributes.Add("Enabled", "False");

                int UserID = Convert.ToInt32(Session["UserID"]);
                int EmployeeID = Convert.ToInt32(hdnUserID.Value);

                objInfo.Firstname = txtEditFirstname.Text == "" ? "" : GeneralFunction.ToProper(txtEditFirstname.Text.Trim());
                objInfo.Lastname = txtEditLastname.Text == "" ? "" : GeneralFunction.ToProper(txtEditLastname.Text.Trim());

                objInfo.BLastname = txtEditBLname.Text == "" ? txtEditFirstname.Text.Trim() : GeneralFunction.ToProper(txtEditBLname.Text.Trim());
                objInfo.BFirstname = txtEditBFname.Text == "" ? txtEditLastname.Text.Trim() : GeneralFunction.ToProper(txtEditBFname.Text.Trim());
                
                
                
                string PhotoLink = imgPhoto.ImageUrl.Replace("~/Photos/", "").Trim();
                try
                {
                    if (photoUpload1.HasFile)
                    {
                        string filePhotoName = photoUpload1.FileName;
                        string Photoextension = System.IO.Path.GetExtension(filePhotoName);
                        if (Photoextension == ".jpg" || Photoextension == ".png" || Photoextension == ".jpeg" || Photoextension == ".JPG" || Photoextension == ".PNG" || Photoextension == ".JPEG")
                        {
                            string SaveFileLoc = Server.MapPath("~/Photos/");
                            if (System.IO.Directory.Exists(SaveFileLoc) == false)
                            {
                                System.IO.Directory.CreateDirectory(SaveFileLoc);
                            }

                            string FileNameSaveData = SaveFileLoc + (objInfo.Firstname.Trim() + objInfo.Lastname.Trim()).Trim() + ".jpeg";
                            PhotoLink = (objInfo.Firstname.Trim() + objInfo.Lastname.Trim()).Trim() + ".jpeg";


                            photoUpload1.SaveAs(FileNameSaveData);
                            Bitmap oBitmap = default(Bitmap);
                            oBitmap = new Bitmap(FileNameSaveData);
                            Graphics oGraphic = default(Graphics);

                            int newwidthimg = 140;
                            // Here create a new bitmap object of the same height and width of the image.
                            // float AspectRatio = (float)oBitmap.Size.Width / (float)oBitmap.Size.Height;

                            int newHeight = 140;

                            Bitmap bmpNew = new Bitmap(newwidthimg, newHeight);
                            oGraphic = Graphics.FromImage(bmpNew);

                            oGraphic.CompositingQuality = CompositingQuality.HighQuality;
                            oGraphic.SmoothingMode = SmoothingMode.HighQuality;
                            oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;


                            oGraphic.DrawImage(oBitmap, new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), 0, 0, oBitmap.Width, oBitmap.Height, GraphicsUnit.Pixel);
                            // Release the lock on the image file. Of course,
                            // image from the image file is existing in Graphics object
                            oBitmap.Dispose();
                            oBitmap = bmpNew;

                            //SolidBrush oBrush = new SolidBrush(Color.Black);
                            //Font ofont = new Font("Arial", 8);
                            //oGraphic.DrawString("Some text to write", ofont, oBrush, 10, 10);
                            //oGraphic.Dispose();
                            //ofont.Dispose();
                            //oBrush.Dispose();
                            oBitmap.Save(FileNameSaveData, ImageFormat.Jpeg);

                            oBitmap.Dispose();


                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "alert('File access denied');", true);
                }

                //objInfo.Lastname = GeneralFunction.ToProper(txtEditLastname.Text.Trim());
                objInfo.ScheduleID = Convert.ToInt32(ddlSchedule.SelectedItem.Value);
                objInfo.EmpTypeID = Convert.ToInt32(ddlEmpType.SelectedItem.Value);
                objInfo.Deptname = ddlEditDepart.SelectedItem.Text.ToString();
                objInfo.Designation = GeneralFunction.ToProper(txtEditDesg.Text.Trim());
                objInfo.StartDt = txtEditStartDate.Text == "" ? Convert.ToDateTime("01/01/1900") : Convert.ToDateTime(txtEditStartDate.Text);
                objInfo.TermDt = txtEditTermDate.Text == "" ? Convert.ToDateTime("01/01/1900") : Convert.ToDateTime(txtEditTermDate.Text);
                objInfo.TermReason = txtEdit1TermReason.Text.Trim();
                if (rdEditActiveFalse.Checked == true)
                {
                    objInfo.IsActive = false;
                }
                else
                {
                    objInfo.IsActive = true;
                    objInfo.TermDt = Convert.ToDateTime("01/01/1900");
                    objInfo.TermReason = "";
                }

                Attendance.BAL.Report obj = new Report();
                String strHostName = Request.UserHostAddress.ToString();
                string strIp = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
                bool bnew = obj.UpdateUser(objInfo, EmployeeID, UserID, PhotoLink, strIp);
                if (bnew)
                {
                    btnUpdate.Enabled = true;
                    btnEditCancel.Enabled = true;
                    mdlEditPopup.Hide();
                    txtEdit1TermReason.Text = "";
                    txtEditTermDate.Text = "";
                    txtEditDesg.Text = "";
                    txtEditEmpID.Text = "";
                    txtEditFirstname.Text = "";
                    txtEditLastname.Text = "";
                    txtEditStartDate.Text = "";
                    ddlEditDepart.SelectedIndex = 0;
                    ddlEmpType.SelectedIndex = 0;
                    ddlSchedule.SelectedIndex = 0;
                    GetEmpDet(EmployeeID);

                }
            }


            catch (Exception ex)
            {

            }
        }