protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            //if (requestContext.HttpContext.Session.IsNewSession)
            //{
            if (this.SessionContext == null)
            {
                this.SessionContext = new WebSessionContext(MvcApplication.MySystem, requestContext.HttpContext.Session, MvcApplication.SessionFactory, requestContext.HttpContext.Request.UserHostAddress);
                BudgetConfiguration.CurrentConfiguration = BudgetConfiguration.GetConfiguration(SessionContext);
            }
            //this.SessionContext.CurrentLanguage = this.SessionContext.Configuration.DefaultLanguage;
            //}

            ViewBag.AppName = ApplicationName;
            if (this.SessionContext.User != null)
            {
                GetMenu();
                GetAnnouncesByRole();

                ViewBag.UserName       = this.SessionContext.User.Person.CurrentName.FirstName.GetValue("th-TH");
                ViewBag.DepartmentName = this.SessionContext.User.OrgUnit.CurrentName.Name.GetValue("th-TH");
                ViewBag.AppName        = CommonConstant.ApplicationName(Request);
            }
            else
            {
                GetAnonymousMenu();
            }
        }
Exemple #2
0
        public string Create(AGSUserEntity user)
        {
            // creat the Identity User with the provided password
            EFApplicationUser appUser = new EFApplicationUser();

            MapAGSUserEntityToEFApplicationUser(user, appUser);
            appUser.Id = CommonConstant.GenerateId();


            // set the default password for the newly created user
            _ = _userManager.CreateAsync(appUser).Result;

            _ = _userManager.AddClaimsAsync(appUser, new Claim[] {
                new Claim(JwtClaimTypes.Name, user.Username),
                new Claim(JwtClaimTypes.Email, user.Email)
            }).Result;

            // update the associated groups
            if (user.GroupIds != null)
            {
                foreach (var groupId in user.GroupIds)
                {
                    Console.WriteLine($"Adding group:{groupId}");
                    this.AddUserToGroup(appUser, groupId);
                }
            }

            return(appUser.Id);
        }
Exemple #3
0
 public ActionResult Register(User model)
 {
     if (ModelState.IsValid)
     {
         using (BSDBContext db = new BSDBContext())
         {
             var user = db.Users.FirstOrDefault(p => p.Username == model.Username);
             if (user == null)
             {
                 model.UserRoleID  = 1;
                 model.isActivated = true;
                 model.Password    = CommonConstant.HashPassword(model.Password);
                 db.Users.Add(model);
                 db.SaveChanges();
             }
             else
             {
                 ViewBag.Message = "Tài khoản " + model.Username + " đã tồn tại";
                 return(View());
             }
         }
         ModelState.Clear();
         ViewBag.Message = "Đăng ký thành công cho tài khoản " + model.Username;
     }
     return(RedirectToAction("Login"));
 }
Exemple #4
0
 public void MapAGSGroupEntityToEFApplicationRole(AGSGroupEntity groupEntity, EFApplicationRole efApplicationRole)
 {
     efApplicationRole.Id               = groupEntity.Id;
     efApplicationRole.Name             = groupEntity.Name;
     efApplicationRole.NormalizedName   = groupEntity.Name;
     efApplicationRole.ConcurrencyStamp = CommonConstant.GenerateId();
 }
Exemple #5
0
        public void InitializeApplicationData()
        {
            // add all function claims into Database
            var ags_identity_constant_type = typeof(CommonConstant);
            var constant_fields            = ags_identity_constant_type.GetFields();

            foreach (var constant_field in constant_fields)
            {
                if (constant_field.Name.EndsWith("ClaimConstant"))
                {
                    var claimValue = (string)(constant_field.GetValue(null));
                    _applicationDbContext.FunctionClaims.Add(new EFFunctionClaim()
                    {
                        Id = CommonConstant.GenerateId(), Name = claimValue
                    });
                }
            }

            // create admin user
            var userName     = AGSAdminName;
            var email        = _configuration["default_user_email"];
            var userPassword = _configuration["default_user_password"];

            var user = new EFApplicationUser
            {
                Id                 = CommonConstant.GenerateId(),
                UserName           = userName,
                NormalizedEmail    = email,
                NormalizedUserName = userName,
                Email              = email,
                First_Name         = "Tim",
                Last_Name          = "Ng",
                Title              = "Developer",
                SecurityStamp      = CommonConstant.GenerateId(), // need to add this !!!
            };

            _ = _userManager.CreateAsync(user, userPassword).Result;


            var group1 = new EFApplicationRole
            {
                Id               = CommonConstant.GenerateId(),
                Name             = "Group_1_Test",
                NormalizedName   = "Group_1_Test",
                ConcurrencyStamp = CommonConstant.GenerateId()
            };
            var group2 = new EFApplicationRole
            {
                Id               = CommonConstant.GenerateId(),
                Name             = "Group_2_Test",
                NormalizedName   = "Group_2_Test",
                ConcurrencyStamp = CommonConstant.GenerateId()
            };

            _ = _roleManager.CreateAsync(group1).Result;
            _ = _roleManager.CreateAsync(group2).Result;
            _applicationDbContext.SaveChanges();
        }
Exemple #6
0
        public string Create(AGSFunctionClaimEntity functionClaim)
        {
            var result = new EFFunctionClaim();

            UpdateFunctionClaim(functionClaim, result);
            result.Id = CommonConstant.GenerateId();
            _applicationDbContext.FunctionClaims.Add(result);
            return(result.Id);
        }
        private void Save()
        {
            if (string.IsNullOrEmpty(txtTenNCC.Text.Trim()))
            {
                MessageBox.Show("Tên nhà cung cấp không được để trống.", CommonConstant.MESSAGE_WARNING, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!CommonConstant.CheckPhoneNumber(txtSDT.Text))
            {
                MessageBox.Show("Số điện thoại không hợp lệ.", CommonConstant.MESSAGE_WARNING, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string info = "";

            if (flag)//sua ban ghi
            {
                var model = db.NhaCungCaps.Find(txtMaNCC.Text);
                model.TenNCC = txtTenNCC.Text;
                model.TenNCC = txtTenNCC.Text;
                model.SDT    = txtSDT.Text;
                model.MoTa   = txtMoTa.Text;
                model.MST    = txtMST.Text;
                model.DiaChi = txtDiaChi.Text;
                model.Email  = txtEmail.Text;
                info         = "Sửa thông tin nhà cung cấp";
            }
            else
            {
                NhaCungCap obj = new NhaCungCap();
                obj.MaNCC  = GenerateID();
                obj.TenNCC = txtTenNCC.Text;
                obj.SDT    = txtSDT.Text;
                obj.MoTa   = txtMoTa.Text;
                obj.MST    = txtMST.Text;
                obj.DiaChi = txtDiaChi.Text;
                obj.Email  = txtEmail.Text;
                info       = "Thêm mới thông tin nhà cung cấp";
                db.NhaCungCaps.Add(obj);
            }

            int record = db.SaveChanges();

            if (record > 0)
            {
                MessageBox.Show(info + " thành công.", CommonConstant.MESSAGE_INFO, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                MessageBox.Show(string.Format("Xảy ra lỗi, vui lòng kiểm tra lại!"), CommonConstant.MESSAGE_WARNING, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        public static void SetFilter(ref XmlDocument xDom, string id)
        {
            string[] vtl_id  = CommonConstant.splitGlobalID(id);
            XmlNode  xNodeID = xDom.SelectSingleNode("//query:ID", GetNamespaceManager(xDom));

            xNodeID.ChildNodes.Item(0).InnerText = vtl_id[0];
            xNodeID = xDom.SelectSingleNode("//query:AgencyID", GetNamespaceManager(xDom));
            xNodeID.ChildNodes.Item(0).InnerText = vtl_id[1];
            xNodeID = xDom.SelectSingleNode("//query:Version", GetNamespaceManager(xDom));
            xNodeID.ChildNodes.Item(0).InnerText = vtl_id[2];
        }
Exemple #9
0
        public void CreateUser_IdNotEmpty_ThrowException()
        {
            var repository = new Mock <IRepository>();
            var newUser    = new AGSUserEntity()
            {
                Id = CommonConstant.GenerateId()
            };

            var usersHelper = new UsersHelper(repository.Object, _configuration);

            Assert.Throws <ArgumentException>(() => usersHelper.CreateUser(newUser));
        }
        /// <summary>
        /// แสดงหน้าโครงการจากระบบ E-Budget เพื่อให้เลือกนำเข้ามาระบบ Risk และสามารถ Link ที่นำเข้ามาแล้วไปยังหน้า Project Risk ได้เลย
        /// </summary>
        /// <returns>View</returns>
        public ActionResult ProjectEBudget()
        {
            ViewBag.TabMenu = "2";
            int riskLimit = 5;

            //ViewBag.AppName = CommonConstant.ApplicationName(Request);
            ViewBag.Menus = MenuSession = new List <Models.Menu>
            {
                new Models.Menu {
                    Name = "หน้าแรก", Url = CommonConstant.GetApplicationUrl(Request, "/UserPage/Home"), IdTab = "tab0",
                },
                new Models.Menu {
                    Name = "โครงการที่ยังไม่สมบูรณ์", Url = CommonConstant.GetApplicationUrl(Request, "/UserPage/ProjectRisk_Incomplete"), IdTab = "ta1b0",
                },
                new Models.Menu {
                    Name = "โครงการทั้งหมด", Url = "", IdTab = "tab10",
                },
                new Models.Menu {
                    Name = "ติดต่อเรา", Url = CommonConstant.GetApplicationUrl(Request, "/Contacts"), IdTab = "tab10"
                },
            };

            Dictionary <string, List <string> > projectEBudget = new Dictionary <string, List <string> >();

            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("1")), new List <string>()
            {
                "12003-001", "โครงการทดลองนะจ๊ะ 1", "10,000,000.00", "1"
            });
            riskLimit--;
            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("2")), new List <string>()
            {
                "12003-002", "โครงการทดลองนะจ๊ะ 2", "500,000,000.00", "0"
            });
            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("3")), new List <string>()
            {
                "12003-003", "โครงการทดลองนะจ๊ะ 3", "400,000,000.00", "0"
            });
            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("4")), new List <string>()
            {
                "12003-004", "โครงการทดลองนะจ๊ะ 4", "200,000,000.00", "1"
            });
            riskLimit--;
            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("5")), new List <string>()
            {
                "12003-005", "โครงการทดลองนะจ๊ะ 5", "300,000,000.00", "0"
            });
            ViewBag.ProjectEBudget = projectEBudget;
            ViewBag.RiskLimit      = riskLimit;

            return(View());
        }
        private void LoadCodelistCodes(string webserviceId, string dsd_id, TreeNode treeNodeSecLevel)
        {
            try
            {
                List <BaseArtefactInfo> dsList;
                bool raiseError = false;
                CommonItem.WaitOn();


                MetadataLoader mtl = new MetadataLoader(CommonItem.CurrentSettings.QueriesPath, new WebServiceLayer.classes.service.Net.WebServiceLayer(CommonItem.CurrentSettings, int.Parse(webserviceId)));

                string[] ident = CommonConstant.splitGlobalID(dsd_id);
                dsList = mtl.LoadCodelistCodes21(ident[0], ident[1], ident[2]);

                //Visit components

                foreach (BaseComponentInfo compInfo in dsList[0].DataStructureDetails.Components)
                {
                    string text;
                    if (switchTreeView.isCode())
                    {
                        text = compInfo.vtlId;
                    }
                    else
                    if (compInfo.name.Count == 0)
                    {
                        raiseError = true;
                        text       = compInfo.vtlId;
                    }
                    else
                    {
                        text = compInfo.name[0].value.ToString();
                    }

                    TreeNode tmp = treeNodeSecLevel.Nodes.Add(compInfo.vtlId, text);
                    tmp.ForeColor = Color.Gray;
                    tmp.Tag       = new ArtefactNodeInfo(webserviceId, compInfo, ArtefactNodeInfo.ArtefactType.DataStructureComponents);
                }

                CommonItem.WaitOff();
                if (raiseError)
                {
                    MessageBox.Show("The description is not available for one or more items.The ID will be shown", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                CommonItem.ErrManger.ErrorManagement(ex, false, this);
            }
        }
Exemple #12
0
        private object GetDataComments(int bookID)
        {
            List <Comment> commentList = CommentsDAO.GetComments(bookID);
            object         jsonData    = (from d in commentList
                                          select new {
                comment_id = d.CommentID,
                username = CommentsDAO.getUsername(d.UserID),
                picture = CommentsDAO.getPicture(d.UserID),
                content = d.Content,
                date = string.Format("{0} {1}", CommonConstant.GetWeekOfDate(d.CreatedDate, "dd/MM/yyyy"), d.CreatedDate.ToString("HH:mm")),
            }).ToList();

            return(jsonData);
        }
Exemple #13
0
        public JsonResult LoginAjax(string user_name, string pass)
        {
            pass = CommonConstant.Encrypt(pass);
            using (BSDBContext db = new BSDBContext())
            {
                var result = db.Users.Where(p => p.Username == user_name && p.Password == pass).Count();
                if (result == 0)
                {
                    object jsondata = new LoginClass
                    {
                        SessionRole     = null,
                        SessionUsername = null
                    };
                    return(Json(jsondata, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var roleID = db.Users.Where(a => a.Username == user_name).FirstOrDefault().UserRoleID;
                    if (roleID == 1)
                    {
                        object jsondata = new LoginClass
                        {
                            SessionRole     = null,
                            SessionUsername = null
                        };
                        return(Json(jsondata, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        var userID  = db.Users.Where(a => a.Username == user_name).FirstOrDefault().UserID;
                        var name    = db.Users.Where(a => a.Username == user_name && a.Password == pass).FirstOrDefault().Username;
                        var blockID = db.Users.Where(a => a.Username == user_name).FirstOrDefault().isActivated;
                        Session["userHello"] = name;
                        Session["userName"]  = user_name;
                        Session["UserID"]    = userID;
                        Session["blockID"]   = blockID;
                        Session["roleID"]    = roleID;

                        object jsondata = new LoginClass
                        {
                            SessionRole     = Session["roleID"].ToString(),
                            SessionBlockID  = Convert.ToBoolean(Session["blockID"]),
                            SessionUsername = Session["userName"].ToString()
                        };
                        return(Json(jsondata, JsonRequestBehavior.AllowGet));
                    }
                }
            }
        }
 public ActionResult Create(decimal?id)
 {
     ViewData["Employee"] = Employee.ListEmployee(1);
     ViewData["DocType"]  = CommonConstant.BindDocumentType();
     ViewData["Status"]   = CommonConstant.BindStatus();
     if (id != null)
     {
         ViewData["CurrEmployee"] = id;
     }
     else
     {
         ViewData["CurrEmployee"] = string.Empty;
     }
     return(View());
 }
        public ActionResult Edit(decimal id)
        {
            ViewData["Department"] = CommonConstant.BindDepartment();
            ViewData["Status"]     = CommonConstant.BindStatus();
            Employee obj = Employee.Find(id);

            if (obj != null)
            {
                return(View(obj));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Regex r = new Regex(@"[a-zA-Z0-9]", RegexOptions.IgnoreCase);
                if (!r.IsMatch(trasfTextBox.Text.Trim()))
                {
                    MessageBox.Show("Wrong ID format. Please use a SDMX ID format [A-Z, a-z, 0-9, _, -, $, @])", "Wrong format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string tmpString = CommonConstant.ToGlobalID(trasfTextBox.Text.Trim(), AgencyTextBox.Text.Trim(), VersionTextBox.Text.Trim());
                foreach (BaseArtefactInfo artInfo in _transfInfo)
                {
                    if (artInfo.vtlId == tmpString)
                    {
                        MessageBox.Show("The Trasformation scheme :\n" +
                                        trasfTextBox.Text.Trim() + " " + AgencyTextBox.Text.Trim() + " " + VersionTextBox.Text.Trim() + "\n" +
                                        " is already present. Please insert a different ID, Agency or change the version.", "Already present", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return;
                    }
                }

                r = new Regex(@"^(\d{1}\.?){1,2}\d{1}$");
                if (!r.IsMatch(VersionTextBox.Text.Trim()))
                {
                    MessageBox.Show("Wrong version format. Please use a correct version format tre numbers separated by a dot", "Wrong format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (string.IsNullOrEmpty(AgencyTextBox.Text.Trim()))
                {
                    MessageBox.Show("The Angency value is empty. Please insert and agency ID", "Agency", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                TrasformationName = trasfTextBox.Text.Trim();
                AgencyID          = AgencyTextBox.Text.Trim();
                Version           = VersionTextBox.Text.Trim();

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public ActionResult Edit(decimal id)
        {
            ViewData["Employee"] = Employee.ListEmployee(1);
            ViewData["DocType"]  = CommonConstant.BindDocumentType();
            ViewData["Status"]   = CommonConstant.BindStatus();
            EmployeeDocument obj = EmployeeDocument.Find(id);

            if (obj != null)
            {
                return(View(obj));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        /// <summary>
        /// แสดงหน้าเริ่มต้น Project Risk
        /// </summary>
        /// <returns>View</returns>
        public ActionResult ProjectRisk_New(string id)
        {
            try
            {
                string projectID = CommonConstant.Decrypt(CommonConstant.ResotrePlusAndSpaceSymolFromBase64(id));

                ViewBag.DepartmentCode = "12000";
                ViewBag.DepartmentName = "กระทรวงพลังงาน";
                ViewBag.DivisionCode   = "12003";
                ViewBag.DivisionName   = "กรมเชื้อเพลิงธรรมชาติ";
                ViewBag.ProjectCode    = ViewBag.DivisionCode + "-" + "016";
                ViewBag.Yudtasad       = new Dictionary <string, string>()
                {
                    { "1", "1 ยุทธศาสตร์เร่งรัดวางรากฐานการพัฒนาที่ยั่งยืนของประเทศ" },
                    { "2", "2 ยุทธศาสตร์ความมั่นคงแห่งรัฐ" },
                    { "20", "3 ยุทธศาสตร์การสร้างความเจริญเติบโตทางเศรษฐกิจอย่างยั่งยืนและเป็นธรรม" },
                    { "21", "4 ยุทธศาสตร์การศึกษา สาธารณสุข คุณธรรม จริยธรรม และคุณภาพชีวิต" },
                    { "15", "5 ยุทธศาสตร์การจัดการทรัพยากรธรรมชาติและสิ่งแวดล้อม" },
                    { "16", "6 ยุทธศาสตร์การพัฒนาวิทยาศาสตร์ เทคโนโลยี การวิจัยและนวัตกรรม" },
                    { "17", "7 ยุทธศาสตร์การต่างประเทศและเศรษฐกิจระหว่างประเทศ" },
                    { "18", "8 ยุทธศาสตร์การบริหารกิจการบ้านเมืองที่ดี" },
                    { "19", "9 รายการค่าดำเนินการภาครัฐ" }
                };
                ViewBag.Menus = MenuSession = new List <Models.Menu>
                {
                    new Models.Menu {
                        Name = "หน้าแรก", Url = CommonConstant.GetApplicationUrl(Request, "/UserPage/Home"), IdTab = "tab0",
                    },
                    new Models.Menu {
                        Name = "โครงการที่ยังไม่สมบูรณ์", Url = CommonConstant.GetApplicationUrl(Request, "/UserPage/ProjectRisk_Incomplete"), IdTab = "ta1b0",
                    },
                    new Models.Menu {
                        Name = "โครงการทั้งหมด", Url = "", IdTab = "tab10",
                    },
                    new Models.Menu {
                        Name = "ติดต่อเรา", Url = CommonConstant.GetApplicationUrl(Request, "/Contacts"), IdTab = "tab10"
                    },
                };
            }
            catch //(Exception exc)
            {
                return(RedirectToAction("Home"));
                //throw exc;
            }

            return(View());
        }
Exemple #19
0
        public void CreateFunctionClaim_IdProvided_ThrowException()
        {
            // mock the IRepository object start
            var functionClaimsRepository = new Mock <IRepository>();

            functionClaimsRepository.Setup(_ => _.FunctionClaimsRepository.Create(It.Is <AGSFunctionClaimEntity>(g => string.IsNullOrEmpty(g.Id)))).Returns(CommonConstant.GenerateId());
            // end


            var functionClaimsHelper = new FunctionClaimsHelper(functionClaimsRepository.Object);
            var newFunctionClaim     = new AGSFunctionClaimEntity()
            {
                Id = CommonConstant.GenerateId()
            };

            Assert.Throws <ArgumentException>(() => functionClaimsHelper.CreateFunctionClaim(newFunctionClaim));
        }
Exemple #20
0
        public JsonResult GetPassOld()
        {
            var model = db.Users.Find(Convert.ToInt32(Session["UserID"].ToString()));

            if (model != null)
            {
                if (model.Password != "")
                {
                    return(Json(CommonConstant.Decrypt(model.Password), JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(null, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #21
0
        public ActionResult ChangePassword(string newPass)
        {
            int userID = Convert.ToInt32(Session["UserID"].ToString());
            var model  = db.Users.Find(userID);

            //newPass = CommonConstant.HashPassword(newPass);
            newPass = CommonConstant.Encrypt(newPass);
            int check = 1;

            try
            {
                model.Password = newPass;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                check = -1;
            }
            return(Json(check, JsonRequestBehavior.AllowGet));
        }
Exemple #22
0
        public string Create(AGSGroupEntity group)
        {
            // create a new role in ASP.NET identity core
            var role = new EFApplicationRole();

            MapAGSGroupEntityToEFApplicationRole(group, role);
            role.Id = CommonConstant.GenerateId(); // assign id here
            _       = _roleManager.CreateAsync(role).Result;

            // update the associated Function Claims
            if (group.FunctionClaimIds != null)
            {
                foreach (var functionClaimId in group.FunctionClaimIds)
                {
                    this.AddFunctionClaimToGroup(role, functionClaimId);
                }
            }

            return(role.Id);
        }
        /// <summary>
        /// แสดงหน้า Intro ก่อนเข้าทำความเสี่ยง
        /// </summary>
        /// <returns>View</returns>
        public ActionResult ProjectRisk_Intro()
        {
            ViewBag.Menus = MenuSession = new List <Models.Menu>
            {
                new Models.Menu {
                    Name = "หน้าแรก", Url = CommonConstant.GetApplicationUrl(Request, "/UserPage/Home"), IdTab = "tab0",
                },
                new Models.Menu {
                    Name = "โครงการที่ยังไม่สมบูรณ์", Url = CommonConstant.GetApplicationUrl(Request, "/UserPage/ProjectRisk_Incomplete"), IdTab = "ta1b0",
                },
                new Models.Menu {
                    Name = "โครงการทั้งหมด", Url = "", IdTab = "tab10",
                },
                new Models.Menu {
                    Name = "ติดต่อเรา", Url = CommonConstant.GetApplicationUrl(Request, "/Contacts"), IdTab = "tab10"
                },
            };

            return(View());
        }
Exemple #24
0
        public JsonResult ExecuteLogin(User model)
        {
            model.Password = CommonConstant.HashPassword(model.Password);
            bool check = new AccountDAO().checkAccount(model.Username, model.Password);

            if (check)
            {
                var roleID = db.Users.Where(a => a.Username == model.Username).FirstOrDefault().UserRoleID;
                Session["roleID"] = roleID;
                if (check && ((int)Session["roleID"] == 1))
                {
                    Session["UserName"] = model.Username;
                    return(Json(new { status = true }));
                }
                else
                {
                    return(Json(new { status = false }));
                }
            }
            return(Json(new { status = false }));
        }
Exemple #25
0
        public static List <string> getDataStructureSQLStatement(string dsd_ID, string dsd_Agency, string dsd_Version, List <LocalizedValue> names, string sequentialVariable)
        {
            try
            {
                List <string> statements = new List <string>();
                string        GlobalID   = CommonConstant.ToGlobalID(dsd_ID, dsd_Agency, dsd_Version);
                statements.Add("select nvl(max(ARTEFACT_SEQ_ID),0)+1 into " + sequentialVariable + " from ARTEFACT;");
                statements.Add("insert into ARTEFACT values(" + sequentialVariable + ", '" + GlobalID + "', '" + dsd_ID + "', '" + dsd_Agency + "', '" + dsd_Version + "');");
                statements.Add("insert into DATA_STRUCTURE values (" + sequentialVariable + " );");


                if (names.Count > 0)
                {
                    string[] lang  = { names[0].lang.ToString(), names[1].lang.ToString() };
                    string[] descr = { names[0].value.ToString().Replace("'", "''"), names[1].value.ToString().Replace("'", "''") };
                    bool     first = true;
                    int      l     = 0;
                    statements.Add("select nvl(max(LS_SEQ_ID),0)+1 into appo_variable from LOCALISED_STRING;");

                    foreach (string str in lang)
                    {
                        if (first)
                        {
                            statements.Add("insert into LOCALISED_STRING values(appo_variable, '" + str + "', '" + descr[l] + "', 'Description', " + sequentialVariable + ", null);");
                            first = false;
                        }
                        else
                        {
                            statements.Add("insert into LOCALISED_STRING values(appo_variable, '" + str + "', '" + descr[l] + "', 'Description', " + sequentialVariable + ", null);");
                        }
                        l++;
                    }
                }
                return(statements);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public string GetProjectRisk_IncompleteYear(string year)
        {
            for (int i = 0; i < 5000000; i++)
            {
                Console.WriteLine(i);
            }

            try
            {
                Dictionary <string, object> jsonResult = new Dictionary <string, object>();
                jsonResult.Add("result", 1);

                IList <Dictionary <string, object> > projectData = new List <Dictionary <string, object> >();
                if (year == "2559")
                {
                    projectData.Add(new Dictionary <string, object>()
                    {
                        { "ProjectID", CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("1")) },
                        { "ProjectName", "โครงการนำร่องผลิตน้ำมันเพื่อใช้ภายในประเทศจากแหล่งทรัพยากรธรรมชาติของชาติ" },
                        { "ProjectCategory", "" },
                        { "ProjectFund", "1,000,000,000" },
                        { "ProjectLastUpdate", "29/05/2558" },
                    });
                }

                jsonResult.Add("data", projectData);
                jsonResult.Add("recordCount", 1);

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
            catch (Exception exc)
            {
                Dictionary <string, object> jsonResult = new Dictionary <string, object>();
                jsonResult.Add("result", 0);
                jsonResult.Add("message", exc.ToString());

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
        }
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            BudgetConfiguration.CurrentConfiguration
                = BudgetConfiguration.GetConfiguration(SessionContext);

            ViewBag.AppName = ApplicationName;
            if (this.SessionContext.User != null)
            {
                GetMenu();
                GetAnnouncesByRole();

                ViewBag.UserName       = this.SessionContext.User.Person.CurrentName.FirstName.GetValue(Formetter.LanguageTh);
                ViewBag.DepartmentName = this.SessionContext.User.OrgUnit.CurrentName.Name.GetValue(Formetter.LanguageTh);
                ViewBag.AppName        = CommonConstant.ApplicationName(Request);
            }
            else
            {
                GetAnonymousMenu();
            }
        }
Exemple #28
0
 private void frmOpenTrasformation_Load(object sender, EventArgs e)
 {
     try
     {
         TrasDataGridView.Rows.Clear();
         BaseArtefactInfo[] transList = getTrasformationList();
         if (transList.Length > 0)
         {
             foreach (BaseArtefactInfo bsArtefact in getTrasformationList())
             {
                 string[] sdmxGlobal = CommonConstant.splitGlobalID(bsArtefact.vtlId);
                 TrasDataGridView.Rows.Add(bsArtefact.vtlId, sdmxGlobal[0], sdmxGlobal[1], sdmxGlobal[2]);
             }
         }
         ToolTip tp = new ToolTip();
         tp.SetToolTip(RemoveButton, "Remove tranformation scheme");
     }
     catch (Exception ex)
     {
         CommonItem.ErrManger.ErrorManagement(ex, false, this);
     }
 }
Exemple #29
0
        public bool PerformAzureToGoogleActionForUnlistedVM(IList <string> vmNameList)
        {
            bool _return = false;

            try
            {
                if (vmNameList.IsNotNull())
                {
                    AzureVMLogger _prop = new AzureVMLogger();

                    var _listAllVM = googleService.GetAllVMLogDetail(_prop.VMLogSpreadSheetID, _prop.VMLogSheetName);

                    if (_listAllVM.IsNotNull())
                    {
                        var autoShutDetail = googleService.GetVMAutoShutDetail();

                        var _filteredVMList = _listAllVM.Where(x => !vmNameList.Any(i => CommonConstant.GetActualVMName(i).Equals(x.ServerName, StringComparison.OrdinalIgnoreCase)));

                        if (_filteredVMList.IsNotNull())
                        {
                            foreach (VMLogSheetDetail vmSheetDetail in _filteredVMList)
                            {
                                if (vmSheetDetail.IsNotNull())
                                {
                                    var vmDetail = azureService.GetVMDetail(vmSheetDetail.ResourceGroupName, vmSheetDetail.ServerName);
                                    if (vmDetail.IsNotNull() && autoShutDetail.IsNotNull())
                                    {
                                        bool _onSheetUserActive   = vmSheetDetail.UserActiveStatus.Contains(UserStatus.Active, StringComparison.OrdinalIgnoreCase);
                                        bool _onSheetServerActive = vmSheetDetail.ServerStatus.Contains(ServerStatus.Running, StringComparison.OrdinalIgnoreCase);


                                        if (vmDetail.PowerState == PowerState.Deallocating ||
                                            vmDetail.PowerState == PowerState.Deallocated ||
                                            vmDetail.PowerState == PowerState.Stopping ||
                                            vmDetail.PowerState == PowerState.Stopped)
                                        {
                                            if (_onSheetUserActive)
                                            {
                                                //Update User status to No and change datetime of user
                                                googleService.UpdateVmLogUserStatus(vmSheetDetail.rowId, UserStatus.InActive, true);
                                            }

                                            if (_onSheetServerActive)
                                            {
                                                //Update Server status to Stopped and change datetime of server
                                                googleService.UpdateVmLogServerStatus(vmSheetDetail.rowId, ServerStatus.Stopped, true);
                                            }
                                        }
                                        else if (vmDetail.PowerState == PowerState.Running ||
                                                 vmDetail.PowerState == PowerState.Starting)
                                        {
                                            if (!_onSheetServerActive)
                                            {
                                                googleService.UpdateVmLogServerStatus(vmSheetDetail.rowId, ServerStatus.Running, true);
                                            }
                                            else
                                            {
                                                DateTime?latestTime = vmSheetDetail.ServerDateTime > vmSheetDetail.UserActiveDateTime ? vmSheetDetail.ServerDateTime : vmSheetDetail.UserActiveDateTime;

                                                if (autoShutDetail.LastUpdated.Value.Subtract(latestTime.Value) >= autoShutDetail.AutoShutTime)
                                                {
                                                    //shutdown system with server status update to Stopped
                                                    azureService.StopVMByVmNameAsync(vmSheetDetail.ResourceGroupName, vmSheetDetail.ServerName);
                                                    googleService.UpdateVmLogServerStatus(vmSheetDetail.rowId, ServerStatus.Stopped, true);

                                                    if (_onSheetUserActive)
                                                    {
                                                        //Update User status to No and change datetime of user
                                                        googleService.UpdateVmLogUserStatus(vmSheetDetail.rowId, UserStatus.InActive, true);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    _return = true;
                }
            }
            catch (Exception ex)
            {
                _return = false;
            }

            return(_return);
        }
Exemple #30
0
        public bool PerformAzureToGoogleAction(IList <RunCommandRequest> requestList, string SessionHostName)
        {
            bool _return = false;

            try
            {
                if (requestList.IsNotNull())
                {
                    AzureVMLogger _prop        = new AzureVMLogger();
                    bool          isUserActive = requestList.Any(x => x.State.Contains("Active", StringComparison.OrdinalIgnoreCase));
                    string        azureVMName  = CommonConstant.GetActualVMName(SessionHostName);

                    var vmSheetDetail = googleService.GetVMLogDetail(_prop.VMLogSpreadSheetID, _prop.VMLogSheetName, azureVMName);

                    if (vmSheetDetail.IsNotNull())
                    {
                        var autoShutDetail = googleService.GetVMAutoShutDetail();

                        var vmDetail = azureService.GetVMDetail(vmSheetDetail.ResourceGroupName, azureVMName);
                        if (vmDetail.IsNotNull() && autoShutDetail.IsNotNull())
                        {
                            bool _onSheetUserActive   = vmSheetDetail.UserActiveStatus.Contains(UserStatus.Active, StringComparison.OrdinalIgnoreCase);
                            bool _onSheetServerActive = vmSheetDetail.ServerStatus.Contains(ServerStatus.Running, StringComparison.OrdinalIgnoreCase);

                            if (isUserActive)
                            {
                                if (!_onSheetUserActive)
                                {
                                    //Update User status to Yes and change datetime of user
                                    googleService.UpdateVmLogUserStatus(vmSheetDetail.rowId, UserStatus.Active, true);
                                }
                                if (!_onSheetServerActive)
                                {
                                    //Update Server status to Run and change datetime of server
                                    googleService.UpdateVmLogServerStatus(vmSheetDetail.rowId, ServerStatus.Running, true);
                                }
                            }
                            else
                            {
                                if (_onSheetUserActive)
                                {
                                    //Update User status to No and change datetime of user
                                    googleService.UpdateVmLogUserStatus(vmSheetDetail.rowId, UserStatus.InActive, true);
                                }

                                if (_onSheetServerActive)
                                {
                                    DateTime?latestTime = vmSheetDetail.ServerDateTime > vmSheetDetail.UserActiveDateTime ? vmSheetDetail.ServerDateTime : vmSheetDetail.UserActiveDateTime;

                                    if (autoShutDetail.LastUpdated.Value.Subtract(latestTime.Value) >= autoShutDetail.AutoShutTime)
                                    {
                                        //shutdown system with server status update to Stopped
                                        azureService.StopVMByVmNameAsync(vmSheetDetail.ResourceGroupName, azureVMName);
                                        googleService.UpdateVmLogServerStatus(vmSheetDetail.rowId, ServerStatus.Stopped, true);
                                    }
                                }
                            }
                        }
                    }


                    _return = true;
                }
            }
            catch (Exception ex)
            {
                _return = false;
            }

            return(_return);
        }