コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var      frmdata  = context.Request.Form["vls"];
                var      Province = context.Request.Form["Province"];
                string[] d        = frmdata.Split('½');

                int benID = 0;

                using (DBDataContext db = new DBDataContext())
                {
                    if (db.TblHResources.Where(v => v.ContactNos == d[2]).Count() == 0)
                    {
                        TblHResource obj = new TblHResource();
                        obj.Full_Name   = d[1];
                        obj.ContactNos  = d[2];
                        obj.UserGroupID = Convert.ToInt32(d[4]);
                        obj.Email       = d[5];
                        obj.U_Pass      = Encryptor.Encrypt(d[6].Replace("'", ""));
                        obj.EnteryDate  = DateTime.Now;
                        obj.U_Status    = true;
                        obj.U_ThemeID   = 1;
                        obj.Designation = d[3];


                        db.TblHResources.InsertOnSubmit(obj);
                        db.SubmitChanges();
                        benID = obj.User_ID;


                        //new Thread(() =>
                        //{
                        QR objQR = new QR();
                        objQR.QrGenerate(Convert.ToString(benID), "TblHResources", Convert.ToString(benID));
                        //string result = LongRunningMethod("World");
                        //Dispatcher.BeginInvoke((Action)();
                        //}).Start();



                        string[] l = Province.Split('½');
                        Fn.ExenID(@"INSERT INTO Login
                         (UserName, Password, Created_Date, User_Group_Id, Emp_Id, Login_Status, IP_Check)
                            VALUES        ('" + d[2] + "' ,'" + Encryptor.Encrypt(d[6]) + "', GETDATE(),'" + d[4] + "','" + benID + "', 1, 0)");

                        foreach (var item in l)
                        {
                            Fn.Exec(@"INSERT INTO TblHResourcesLocations
                         (User_ID, LocID)
                    VALUES (" + benID + "," + item + ")");
                        }
                    }
                    else
                    {
                        context.Response.ContentType = "text/plain";
                        context.Response.Write("Record Already Exists");
                    }
                }


                if (context.Request.Files.Count > 0 && benID > 0)
                {
                    HttpFileCollection SelectedFiles = context.Request.Files;

                    for (int i = 0; i < SelectedFiles.Count; i++)
                    {
                        HttpPostedFile PostedFile = SelectedFiles[i];
                        string         FileName   = context.Server.MapPath("~/Uploads/EmployeePhoto/" + PostedFile.FileName);
                        string         Path       = context.Server.MapPath("~/Uploads/EmployeePhoto/");
                        FileInfo       fi         = new FileInfo(FileName);
                        int            fileID     = benID;

                        using (DBDataContext db = new DBDataContext())
                        {
                            var o = db.TblHResources.Where(v => v.User_ID == fileID).FirstOrDefault();
                            if (o != null)
                            {
                                o.PhotoExtension = fi.Extension;
                                o.DisplayName    = fi.Extension;
                                db.SubmitChanges();
                            }
                        }
                        PostedFile.SaveAs(Path + Convert.ToString(fileID) + fi.Extension);
                        if (fi.Extension.ToUpper() == ".JPEG" || fi.Extension.ToUpper() == ".JPG" || fi.Extension.ToUpper() == ".BMP" || fi.Extension.ToUpper() == ".PNG" || fi.Extension.ToUpper() == ".GIF")
                        {
                            Bitmap Thumbnail       = CreateThumbnail(Path + Convert.ToString(fileID) + fi.Extension, 32, 32);
                            string SaveAsThumbnail = System.IO.Path.Combine(context.Server.MapPath("~") + "/Uploads/EmployeePhoto/", Convert.ToString(fileID) + "A" + fi.Extension);
                            Thumbnail.Save(SaveAsThumbnail);
                        }

                        if (fi.Extension.ToUpper() == ".JPEG" || fi.Extension.ToUpper() == ".JPG" || fi.Extension.ToUpper() == ".BMP" || fi.Extension.ToUpper() == ".PNG" || fi.Extension.ToUpper() == ".GIF")
                        {
                            Bitmap Thumbnail       = CreateThumbnail(Path + Convert.ToString(fileID) + fi.Extension, 75, 75);
                            string SaveAsThumbnail = System.IO.Path.Combine(context.Server.MapPath("~") + "/Uploads/EmployeePhoto/", Convert.ToString(fileID) + "B" + fi.Extension);
                            Thumbnail.Save(SaveAsThumbnail);
                        }



                        //using (DBDataContext db =  new DBDataContext())
                        //{
                        //    db.sp_RegisterEmpWithLogin(d[0], d[1], "", "", "", d[2], d[5], "", d[3], 1, 1, DateTime.Now, Encryptor.Encrypt(d[6].Replace("'", "")), Convert.ToInt32(d[4]), Convert.ToString(benID)+"."+ fi.Extension);
                        //}



                        context.Response.ContentType = "text/plain";
                        context.Response.Write("Record Saved");
                    }
                }

                else if (benID > 0)
                {
                    //using (DBDataContext db = new DBDataContext())
                    //{
                    //    db.sp_RegisterEmpWithLogin(d[0], d[1], "", "", "", d[2], d[5], "", d[3], 1, 1, DateTime.Now, Encryptor.Encrypt(d[6].Replace("'", "")), Convert.ToInt32(d[4]), null);
                    //}
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Record Saved");
                }

                //context.Response.ContentType = "text/plain";
                //context.Response.Write("Files Uploaded Successfully!!");
            }
            catch (Exception ex)
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write(ex.Message);
            }
        }