protected void btnOkay_Click(object sender, EventArgs e)
        {
            
            int i = 0;
            Page.Validate("ValidationCheck");
            if (Page.IsValid)
            {
                System.Threading.Thread.Sleep(2000);
                if (_mode == UIMode.mode.edit)
                {

                    i = UpdateData();
                    if (i == -1)
                    {
                        lblErrorMsg.Text = "Thông tin không đầy đủ";
                        ClientScript.RegisterStartupScript(this.GetType(), "onload", "onError();", true);
                        MultiView1.ActiveViewIndex = 0;
                    }
                    else if (i == -2)
                    {
                        lblErrorMsg.Text = "Tiến trình xử lý bị lỗi";
                        ClientScript.RegisterStartupScript(this.GetType(), "onload", "onError();", true);
                        MultiView1.ActiveViewIndex = 2;
                    }
                    else if (i == -3)
                    {
                        lblErrorMsg.Text = "Dữ liệu đã tồn tại";
                        ClientScript.RegisterStartupScript(this.GetType(), "onload", "onError();", true);
                        MultiView1.ActiveViewIndex = 2;
                    }
                    else if (i == 1)
                    {
                        lblResult.Text = "Cập nhật thành công";
                        string forward_url = string.Empty;
                       
                            if (ddlRouter.SelectedItem.Text != "Mặc định")
                            {
                                if (ddlPathFile.SelectedIndex > 0 && ddlListInContent.SelectedIndex > 0)
                                {
                                    if (ddlPortalList.SelectedValue != string.Empty)
                                        forward_url += "portalId=" + ddlPortalList.SelectedValue;
                                    if (ddlListInContent.SelectedValue != string.Empty)
                                        forward_url += "&selectedTabId=" + ddlListInContent.SelectedValue;
                                    forward_url += "&createdTabId=" + _idx;
                                    if (ddlPathFile.SelectedValue != string.Empty)
                                        forward_url += "&createdTabPath=" + ddlPathFile.SelectedValue;
                                    if (ddlContentItem.SelectedItem.Text != string.Empty)
                                        forward_url += "&contentItemKey=" + ddlContentItem.SelectedItem.Text + "&keyWords=" + StringHandleClass.convertTitle2Link(ddlContentItem.SelectedItem.Text);
                                    if (ddlCultureCode.SelectedValue != string.Empty)
                                        forward_url += "&lang=" + ddlCultureCode.SelectedValue;
                                    if (ddlRouter.SelectedValue != string.Empty)
                                        forward_url += "&router=" + ddlRouter.SelectedValue;

                                    if (ddlPathFile.SelectedIndex > 0 && ddlListInContent.SelectedIndex > 0)
                                        Response.Redirect("~/modules/admin/tabs/admin_front_tab_control.aspx?" + forward_url);
                                }
                            }
                            else
                            {
                                TabController tab_obj = new TabController();
                                RouteController route_obj = new RouteController();
                                var data_route = route_obj.GetDetails(int.Parse(ddlRouter.SelectedValue));
                                string routerUrl = data_route.RouteUrl;

                                int resultupdate = tab_obj.UpdateLinkFrontPage(_idx.ToString(), routerUrl, data_route.RouteId, Session["UserId"].ToString());
                            }
                        }
                        MultiView1.ActiveViewIndex = 1;
                        ClientScript.RegisterStartupScript(this.GetType(), "onload", "onSuccess();", true);
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "onload", "onError();", true);
                        MultiView1.ActiveViewIndex = 2;
                    }
               
            }
        }
Ejemplo n.º 2
0
        public static int WriteFileRouter(int PortalId, int ContentItemId, string CultureCode, bool Discontinued, string HomeDirectory, string RouterPath, string RouterFile)
        {
            List <aspnet_Routes> lst = RouteController.GetListByPortalIdCultureCodeStatus(PortalId, ContentItemId, CultureCode, Discontinued);

            if (!Directory.Exists(HomeDirectory))
            {
                Directory.CreateDirectory(HomeDirectory);
            }

            if (!Directory.Exists(RouterPath))
            {
                Directory.CreateDirectory(RouterPath);
            }

            string FileRouterPath = Path.Combine(RouterPath, RouterFile);

            if (!System.IO.File.Exists(FileRouterPath))
            {
                System.IO.File.Create(FileRouterPath);
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();

            FileHandleClass file_obj = new FileHandleClass();
            FileInfo        fileInfo = new FileInfo(FileRouterPath);
            string          n = file_obj.ReadFile(fileInfo.FullName);
            int             start = 0; int end = 0;

            if (n.IndexOf("//start") > -1)
            {
                start = n.IndexOf("//start");
            }

            if (n.IndexOf("//end") > -1)
            {
                end = n.IndexOf("//end");
            }

            string content = n.Replace(n.Substring(start + 7, end - start - 7), "\r\n            ");

            file_obj.UpDateFile(fileInfo.FullName, content);
            n = file_obj.ReadFile(fileInfo.FullName);
            string optionparams = string.Empty;

            for (int i = 0; i < lst.Count; i++)
            {
                string RouteName              = lst[i].RouteName;
                string RouteUrl               = lst[i].RouteUrl;
                string PhysicalFile           = lst[i].PhysicalFile;
                bool   CheckPhysicalUrlAccess = lst[i].CheckPhysicalUrlAccess;
                string RouteValueDictionary   = StringDirectionProcess(lst[i].RouteValueDictionary);
                if (RouteValueDictionary != "")
                {
                    RouteValueDictionary = ", new System.Web.Routing.RouteValueDictionary { " + RouteValueDictionary + " })";
                }
                else
                {
                    RouteValueDictionary = ")";
                }
                string newrow = "routes.MapPageRoute(\"" + RouteName + "\", \"" + RouteUrl + "\", \"" + PhysicalFile + "\"," + CheckPhysicalUrlAccess.ToString().ToLower() + RouteValueDictionary + ";";
                n = n.Replace("//end", newrow + System.Environment.NewLine + "            //end");
                file_obj.UpDateFile(fileInfo.FullName, n);
            }

            return(1);
        }