public static string SaveBasicData(string vals, string loc)
        {
            string[] d = vals.Split('½');
            string[] l = loc.Split('½');
            if (d[17] == "0")
            {
                DataSet ds = Fn.FillDSet(@"SELECT 
'FRDP-EMP-' +RIGHT('0000' + CAST(MAX(EmpNo) + 1 AS VARCHAR(50)) ,3) 
AS EmpNo 
,  CAST(MAX(EmpNo) + 1 AS VARCHAR(50))  EC
FROM (
SELECT CAST(EmpNo AS INT) EmpNo FROM [dbo].[TblHResources] WHERE EmpNo IS NOT NULL
) AS X");

                DataTable dttt   = ds.Tables[0];
                string    eno    = Convert.ToString(dttt.Rows[0][0]);
                string    en     = Convert.ToString(dttt.Rows[0][1]);
                string    UserID = Fn.ExenID("INSERT INTO TblHResources (EmpNo, CNIC, Full_Name, FatherName, DOB, Is_Male, CompanyID, DeptID, DesignationID, UserGroupID, ContactNos, U_Status, Qualification, Email, AppointmentDate, ResignationDate, Address, EnteryDate) VALUES ('" + en + "','" + d[1] + "','" + d[2] + "','" + d[3] + "','" + d[4] + "','" + d[5] + "','" + d[6] + "','" + d[7] + "','" + d[8] + "','" + d[9] + "','" + d[10] + "','" + d[11] + "','" + d[12] + "','" + d[13] + "','" + d[14] + "','" + d[15] + "','" + d[16] + "', Getdate());  Select Scope_Identity();");


                Fn.Exec("DELETE FROM TblHResourcesLocations WHERE UserID=" + UserID);

                foreach (var item in l)
                {
                    Fn.Exec(@"INSERT INTO TblHResourcesLocations
                         (User_ID, LocID)
                    VALUES (" + UserID + "," + item + ")");
                }

                Fn.Exec(@"UPDATE       TblHResources
                SET                U_Pass ='******' where User_ID=" + UserID);
                Fn.Exec(@"INSERT INTO Login
                         (UserName, Password, Created_Date, User_Group_Id, Emp_Id, Login_Status, IP_Check)
                VALUES        ('" + eno + "' ,'" + Encryptor.Encrypt(eno) + "', GETDATE(),'" + d[9] + "','" + UserID + "', 1, 0)");

                return(UserID);
            }
            else
            {
                Fn.Exec("UPDATE TblHResources SET CNIC = '" + d[1] + "', Full_Name = '" + d[2] + "', FatherName = '" + d[3] + "', DOB = '" + d[4] + "', Is_Male = '" + d[5] + "', CompanyID = '" + d[6] + "', DeptID = '" + d[7] + "', DesignationID = '" + d[8] + "', UserGroupID = '" + d[9] + "', ContactNos = '" + d[10] + "', U_Status = '" + d[11] + "', Qualification = '" + d[12] + "', Email = '" + d[13] + "', AppointmentDate = '" + d[14] + "', ResignationDate = '" + d[15] + "', Address = '" + d[16] + "' where User_ID = '" + d[17] + "';  Select Scope_Identity();");

                Fn.Exec(@"UPDATE Login
                         SET User_Group_Id='" + d[9] + "' WHERE Emp_Id =" + d[17]);



                Fn.Exec("DELETE FROM TblHResourcesLocations WHERE User_ID=" + d[17]);
                List <TblHResourcesLocation> el = new List <TblHResourcesLocation>();
                foreach (var item in l)
                {
                    //   Fn.Exec(@"INSERT INTO TblHResourcesLocations (User_ID, LocID) VALUES (" + d[17] + "," + item + ")");
                    if (item != "")
                    {
                        el.Add(new TblHResourcesLocation()
                        {
                            LocID = Convert.ToInt32(item), User_ID = Convert.ToInt32(d[17])
                        });
                    }
                }
                if (l.Length > 0)
                {
                    using (DBDataContext db = new DBDataContext())
                    {
                        db.TblHResourcesLocations.InsertAllOnSubmit(el);
                        db.SubmitChanges();
                    }
                }


                return(d[17]);
            }
        }
예제 #2
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (ValidateControls())
            {
                try
                {
                    string    ssssssssssss = Encryptor.Encrypt(txtPass.Text);
                    DataTable DT           = Fn.FillDSet("sp_Login '" + txtUser.Text + "','" + Encryptor.Encrypt(txtPass.Text) + "'").Tables[0];

                    if (txtPass.Text == Encryptor.Decrypt(DT.Rows[0]["Password"].ToString()))
                    {
                        //string EN = "";
                        //int? EID = 0, UGID = 0;
                        //bool? IsAllowed = false;
                        //using (DBDataContext db = new DBDataContext())
                        //{
                        //    db.User_Login(txtUser.Text, ssssssssssss, ref EN, ref EID, ref UGID, "", ref IsAllowed);
                        //}
                        //if (Convert.ToBoolean(IsAllowed) && Convert.ToInt32(EID) > 0)
                        //{

                        Session.Add("EmpName", Convert.ToString(DT.Rows[0]["EmpName"]));
                        Response.Cookies["EmpName"].Value   = Convert.ToString(DT.Rows[0]["EmpName"]);
                        Response.Cookies["EmpName"].Expires = DateTime.Now.AddDays(1);

                        Session.Add("bIsEmployee", Convert.ToString(DT.Rows[0]["bIsEmployee"]));
                        Response.Cookies["bIsEmployee"].Value   = Convert.ToString(DT.Rows[0]["bIsEmployee"]);
                        Response.Cookies["bIsEmployee"].Expires = DateTime.Now.AddDays(1);


                        Session.Add("Emp_Id", Convert.ToString(DT.Rows[0]["Emp_Id"]));
                        Response.Cookies["Emp_Id"].Value   = Convert.ToString(DT.Rows[0]["Emp_Id"]);
                        Response.Cookies["Emp_Id"].Expires = DateTime.Now.AddDays(1);
                        //READ Cookie in c#
                        //Convert.ToString(HttpContext.Current.Session["Emp_Id"]);

                        Session.Add("User_Group_ID", Convert.ToString(DT.Rows[0]["User_Group_ID"]));
                        Response.Cookies["User_Group_ID"].Value   = Convert.ToString(DT.Rows[0]["User_Group_ID"]);
                        Response.Cookies["User_Group_ID"].Expires = DateTime.Now.AddDays(1);


                        Session.Add("UserID", Convert.ToString(DT.Rows[0]["UserID"]));
                        Response.Cookies["UserID"].Value   = Convert.ToString(DT.Rows[0]["UserID"]);
                        Response.Cookies["UserID"].Expires = DateTime.Now.AddDays(1);


                        Session.Add("username", Convert.ToString(DT.Rows[0]["UserName"]));
                        Response.Cookies["username"].Value   = Convert.ToString(DT.Rows[0]["UserName"]);
                        Response.Cookies["username"].Expires = DateTime.Now.AddDays(1);


                        Session.Add("onlyname", Convert.ToString(DT.Rows[0]["onlyname"]));
                        Response.Cookies["onlyname"].Value   = Convert.ToString(DT.Rows[0]["onlyname"]);
                        Response.Cookies["onlyname"].Expires = DateTime.Now.AddDays(1);


                        Session.Add("GroupID", Convert.ToString(DT.Rows[0]["GroupID"]));
                        Response.Cookies["GroupID"].Value   = Convert.ToString(DT.Rows[0]["GroupID"]);
                        Response.Cookies["GroupID"].Expires = DateTime.Now.AddDays(1);


                        //Session.Add("PRD", DT.Rows[0][5]);
                        Session.Add("ContactNo", Convert.ToString(DT.Rows[0]["ContactNo"]));
                        Response.Cookies["ContactNo"].Value   = Convert.ToString(DT.Rows[0]["ContactNo"]);
                        Response.Cookies["ContactNo"].Expires = DateTime.Now.AddDays(1);

                        Session.Add("email", Convert.ToString(DT.Rows[0]["Email"]));
                        Response.Cookies["email"].Value   = Convert.ToString(DT.Rows[0]["Email"]);
                        Response.Cookies["email"].Expires = DateTime.Now.AddDays(1);

                        Session.Add("designation", Convert.ToString(DT.Rows[0]["designation"]));
                        Response.Cookies["designation"].Value   = Convert.ToString(DT.Rows[0]["designation"]);
                        Response.Cookies["designation"].Expires = DateTime.Now.AddDays(1);



                        Session.Add("picExt", Convert.ToString(DT.Rows[0]["picExt"]));
                        Response.Cookies["picExt"].Value   = Convert.ToString(DT.Rows[0]["picExt"]);
                        Response.Cookies["picExt"].Expires = DateTime.Now.AddDays(1);

                        Session.Add("CompanyID", Convert.ToString(DT.Rows[0]["CompanyID"]));
                        Response.Cookies["CompanyID"].Value   = Convert.ToString(DT.Rows[0]["CompanyID"]);
                        Response.Cookies["CompanyID"].Expires = DateTime.Now.AddDays(1);


                        //Response.Cookies["theme"].Value = DT.Rows[0][3].ToString();
                        //Response.Cookies["theme"].Expires = DateTime.Now.AddDays(1);



                        //Response.Cookies["PRD"].Value = HttpUtility.UrlEncode(DT.Rows[0][5].ToString());
                        //Response.Cookies["PRD"].Expires = DateTime.Now.AddDays(1);



                        Response.Cookies["FirstRun"].Value   = "1";
                        Response.Cookies["FirstRun"].Expires = DateTime.Now.AddDays(1);


                        string S = Fn.ExenID("select TOP(1) Format(AMonth, 'MM')+Format(AMonth, 'yyy') AMonth from tblMonthCloseing");
                        Session.Add("Amonth", S);


                        Session.Add("OfficeId", 16);
                        Response.Cookies["OfficeId"].Value   = "16";
                        Response.Cookies["OfficeId"].Expires = DateTime.Now.AddDays(1);
                        //
                        string[] info = Fn.GetRecords("SELECT AccYear, AccYear2, CodeSt, AMonth, AcYrID FROM tblSetup WHERE (CompID = 16)");
                        Session.Add("ActYr", Fn.FirstDayOfMonthFromDateTime(Convert.ToDateTime(info[0])));
                        Response.Cookies["ActYr"].Value   = Convert.ToString(Fn.FirstDayOfMonthFromDateTime(Convert.ToDateTime(info[0])));
                        Response.Cookies["ActYr"].Expires = DateTime.Now.AddDays(1);

                        Session.Add("ActYr2", Fn.LastDayOfMonthFromDateTime(Convert.ToDateTime(info[1])));
                        Response.Cookies["ActYr2"].Value   = Convert.ToString(Fn.LastDayOfMonthFromDateTime(Convert.ToDateTime(info[1])));
                        Response.Cookies["ActYr2"].Expires = DateTime.Now.AddDays(1);

                        Session.Add("ActMth", Convert.ToDateTime(info[3]).ToString("MMMM yyyy"));
                        Response.Cookies["ActMth"].Value   = Convert.ToString(Convert.ToDateTime(info[3]).ToString("MMMM yyyy"));
                        Response.Cookies["ActMth"].Expires = DateTime.Now.AddDays(1);

                        Session.Add("CodeSt", info[2]);
                        Response.Cookies["CodeSt"].Value   = Convert.ToString(info[2]);
                        Response.Cookies["CodeSt"].Expires = DateTime.Now.AddDays(1);

                        Session.Add("br", "16");
                        Response.Cookies["br"].Value   = "16";
                        Response.Cookies["br"].Expires = DateTime.Now.AddDays(1);

                        Session.Add("fy", Convert.ToString(info[4]));
                        Response.Cookies["fy"].Value   = Convert.ToString(info[4]);
                        Response.Cookies["fy"].Expires = DateTime.Now.AddDays(1);

                        //$.cookie('fy', $('#ddYear').val());
                        //$.cookie('ey', $('#ddey').val());

                        string S1 = Fn.ExenID("select TOP(1) Format(AMonth, 'MM')+Format(AMonth, 'yyy') AMonth from tblMonthCloseing");
                        //Session.Add("ActMth", S1);
                        Session.Add("OfficeId", 16);

                        Fn.Exec("INSERT INTO tblUserLog(UserID) VALUES (" + Convert.ToString(DT.Rows[0]["UserID"]) + ")");
                        Response.Cookies["xx"].Value   = S;
                        Response.Cookies["xx"].Expires = DateTime.Now.AddDays(1);
                        Response.Cookies["yy"].Value   = "16";
                        Response.Cookies["yy"].Expires = DateTime.Now.AddDays(1);
                        Response.Redirect(DT.Rows[0]["MP"].ToString());
                        //}
                    }
                    else
                    {
                        lblMsg.Text    = "The username or password you entered is incorrect.";
                        lblMsg.Visible = true;
                    }
                }
                catch (Exception ex)
                {
                    lblMsg.Text    = "The username or password you entered is incorrect...";
                    lblMsg.Visible = true;
                }
            }
        }