Esempio n. 1
0
 public string JsSettings(string settingName = null)
 {
     try
     {
         DersaSqlManager DM       = new DersaSqlManager();
         string          userName = HttpContext.Current.User.Identity.Name;
         if (settingName == null)
         {
             System.Data.DataTable T = DM.ExecuteSPWithParams("USER_SETTING$List", new object[] { userName, Util.GetPassword(userName) });
             var query =
                 from System.Data.DataRow R in T.Rows
                 select new
             {
                 Name           = R["name"],
                 Value          = R["value"],
                 ReadOnly       = R["ReadOnly"],
                 Type           = R["value_type"],
                 ControlType    = (int)R["value_type"] == 1 ? "text" : "button",
                 ChildFormAttrs = (int)R["value_type"] == 1 ? null : new
                 {
                     Height       = 500,
                     Width        = 400,
                     DisplayValue = (int)R["value_type"] == 1 ? R["value"] : "...",
                     InfoLink     = (int)R["value_type"] == 1 ? "" : "Account/JsSettings?settingName=" + R["name"].ToString()
                 }
             };
             string result = JsonConvert.SerializeObject(query);
             return(result);
         }
         else
         {
             System.Data.DataTable T = DM.ExecuteSPWithParams("DERSA_USER$GetTextUserSetting", new object[] { userName, Util.GetPassword(userName), settingName });
             var query =
                 from System.Data.DataRow R in T.Rows
                 select new
             {
                 Name        = settingName,
                 Value       = R[0],
                 ReadOnly    = false,
                 Type        = 2,
                 ControlType = "textarea",
                 Height      = 200,
                 Width       = 300,
                 InfoLink    = ""
             };
             string result = JsonConvert.SerializeObject(query);
             return(result);
         }
     }
     catch
     {
         return("");
     }
 }
 public string List(string id)
 {
     try
     {
         DersaSqlManager DM       = new DersaSqlManager();
         string          userName = HttpContext.Current.User.Identity.Name;
         object          parent   = null;
         if (!id.Contains("#"))
         {
             parent = id;
         }
         string result = "[]";
         if (id == "STEREOTYPES")
         {
             result = Util.GetUserSetting(userName, "root stereotypes");
             Regex removeDigitsEx = new Regex("[0-9]");
             result = removeDigitsEx.Replace(result, "*");
         }
         else
         {
             result = JsonConvert.SerializeObject(DM.ExecuteSPWithParams("ENTITY$JTreeList", new object[] { parent, userName, Util.GetPassword(userName) }));
         }
         return(result);
     }
     catch (Exception exc)
     {
         return("");
     }
 }
Esempio n. 3
0
 public string SetUserSettings(string json_params)
 {
     try
     {
         IParameterCollection Params = Util.DeserializeParams(json_params);
         DersaSqlManager      DM     = new DersaSqlManager();
         string userName             = HttpContext.Current.User.Identity.Name;
         foreach (IParameter Param in Params)
         {
             try
             {
                 System.Data.DataTable T = DM.ExecuteSPWithParams("USER_SETTING$SetValue", new object[] { Param.Name, Param.Value, userName, Util.GetPassword(userName) });
                 if (T.Rows.Count > 0)
                 {
                     return(T.Rows[0][0].ToString());
                 }
             }
             catch
             {
                 throw;
             }
         }
         return("");
     }
     catch
     {
         throw;
     }
 }
 public string PropertiesForm(int id)
 {
     try
     {
         DersaSqlManager       DM       = new DersaSqlManager();
         string                userName = HttpContext.Current.User.Identity.Name;
         System.Data.DataTable T        = DM.ExecuteSPWithParams("ENTITY$GetAttributes", new object[] { id, userName, Util.GetPassword(userName) });
         var query =
             from System.Data.DataRow R in T.Rows
             select new
         {
             Name           = R["Name"],
             Value          = R["Value"],
             ReadOnly       = R["ReadOnly"],
             WriteUnchanged = R["WriteUnchanged"],
             Type           = R["Type"],
             ControlType    = (int)R["Type"] == 1 ? "text" : "button",
             ChildFormAttrs = (int)R["Type"] == 1 ? null : new
             {
                 Height       = 900,
                 Width        = 600,
                 DisplayValue = (int)R["Type"] == 1 ? R["Value"] : "...",
                 InfoLink     = (int)R["Type"] == 1 ? "" : "Node/PropertyForm?id=" + id.ToString() + "&prop_name=" + R["Name"].ToString() + "&prop_type=" + R["Type"].ToString()
             }
         };
         string result = JsonConvert.SerializeObject(query);
         return(result);
     }
     catch
     {
         return("");
     }
 }
Esempio n. 5
0
 public ActionResult Index()
 {
     if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
     {
         if (!Dersa.Models.User.Exists(System.Web.HttpContext.Current.User.Identity.Name))
         {
             return(RedirectToAction("Login", "Account"));
         }
         string userName = System.Web.HttpContext.Current.User.Identity.Name;
         ViewBag.Login = userName;
         DersaSqlManager       DM = new DersaSqlManager();
         System.Data.DataTable T  = DM.ExecuteSPWithParams("DERSA_USER$GetTextUserSetting", new object[] { userName, Util.GetPassword(userName), "toolbox JSON" });
         if (T != null && T.Rows.Count > 0)
         {
             ViewBag.ToolBoxData = T.Rows[0][0];
         }
         else
         {
             ViewBag.ToolBoxData = "[]";
         }
         return(View());
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }
Esempio n. 6
0
        public string Info(string login)
        {
            DersaSqlManager DM = new DersaSqlManager();

            System.Data.DataTable T = DM.ExecuteSPWithParams("DERSA_USER$GetInfo", new object[] { login });
            T.Rows[0]["email"] = Cryptor.Decrypt(T.Rows[0]["email"].ToString(), Util.GetDefaultPassword());
            return(JsonConvert.SerializeObject(T));
        }
        public string MethodsForm(int id)
        {
            try
            {
                string               SqlExecAction = "alert";
                DersaSqlManager      DM            = new DersaSqlManager();
                string               userName      = HttpContext.Current.User.Identity.Name;
                IParameterCollection UserParams    = new ParameterCollection();
                UserParams.Add("@login", userName);
                UserParams.Add("@password", Util.GetPassword(userName));
                int userPermissions = DM.ExecuteSPWithResult("DERSA_USER$GetPermissions", false, UserParams);
                int canExecSql      = userPermissions & 1;
                if (canExecSql != 0)
                {
                    UserParams.Add("@user_setting_name", "Выполнять SQL локально");
                    int execSqlLocal    = DM.ExecuteSPWithResult("DERSA_USER$GetBoolUserSetting", false, UserParams);
                    int canExecLocalSql = userPermissions & 2;
                    if (execSqlLocal > 0 && canExecLocalSql != 0)
                    {
                        SqlExecAction = "exec";
                    }
                }

                System.Data.DataTable T = DM.ExecuteSPWithParams("ENTITY$GetMethods", new object[] { id, userName, Util.GetPassword(userName) });
                int i     = 1;
                var query =
                    from System.Data.DataRow R in T.Rows
                    select new
                {
                    Name           = R["name"],
                    Value          = "",
                    ReadOnly       = false,
                    Type           = -1,
                    ControlType    = "button",
                    ChildFormAttrs = new
                    {
                        Height          = 800,
                        Width           = 600,
                        DisplayValue    = "...",
                        InfoLink        = (int)R["get_result_type"] == 1 ? "Node/ExecMethodForm?id=" + id.ToString() + "&method_name=" + R["name"].ToString() : "",
                        SaveLink        = "Query/ExecSql",//GetSaveLink((int)R["get_result_type"], R["name"].ToString(), id),
                        OnClick         = GetOnClick((int)R["get_result_type"], R["name"].ToString(), id),
                        ActionAfterExec = SqlExecAction
                    }
                };
                string result = JsonConvert.SerializeObject(query);
                return(result);
            }
            catch
            {
                return("");
            }
        }
        public string Rename(string id, string name)
        {
            int intId = -1;

            try
            {
                intId = int.Parse(id);
            }
            catch { }
            if (intId < 0)//диаграммы и проч.
            {
                try
                {
                    DersaSqlManager DM       = new DersaSqlManager();
                    string          userName = HttpContext.Current.User.Identity.Name;
                    string          result   = JsonConvert.SerializeObject(DM.ExecuteSPWithParams("ENTITY$Rename", new object[] { id, name, userName, Util.GetPassword(userName) }));
                    return(result);
                }
                catch
                {
                    return("");
                }
            }
            //для нормальных объектов используем объектные методы
            try
            {
                string          userName    = HttpContext.Current.User.Identity.Name;
                StereotypeBaseE objToRename = StereotypeBaseE.GetSimpleInstance(intId);
                if (objToRename != null)
                {
                    return(objToRename.Rename(userName, name));
                }
                return("");
            }
            catch
            {
                return("");
            }
            //try
            //{
            //    DersaSqlManager DM = new DersaSqlManager();
            //    string userName = HttpContext.Current.User.Identity.Name;
            //    string result = JsonConvert.SerializeObject(DM.ExecuteSPWithParams("ENTITY$Rename", new object[] { id, name, userName, Util.GetPassword(userName) }));
            //    return result;
            //}
            //catch
            //{
            //    return "";
            //}
        }
 public string Restore(int id)
 {
     try
     {
         DersaSqlManager DM       = new DersaSqlManager();
         string          userName = HttpContext.Current.User.Identity.Name;
         string          result   = JsonConvert.SerializeObject(DM.ExecuteSPWithParams("ENTITY$Restore", new object[] { id, userName, Util.GetPassword(userName) }));
         return(result);
     }
     catch
     {
         return("");
     }
 }
Esempio n. 10
0
 public virtual string Rename(string userName, string objectName)
 {
     try
     {
         if (this.Parent != null && !(this.Parent as StereotypeBaseE).AllowModifyChildren())
         {
             return("");
         }
         DersaSqlManager DM     = new DersaSqlManager();
         string          result = JsonConvert.SerializeObject(DM.ExecuteSPWithParams("ENTITY$Rename", new object[] { this.Id, objectName, userName, Util.GetPassword(userName) }));
         return(result);
     }
     catch
     {
         return("");
     }
 }
Esempio n. 11
0
        public ActionResult Report(string proc_name, string parameters)
        {
            DersaSqlManager      M      = new DersaSqlManager();
            IParameterCollection Params = Util.DeserializeParams(parameters);

            if (Params.Contains("proc_name") || !string.IsNullOrEmpty(proc_name))
            {
                if (Params.Contains("proc_name"))
                {
                    proc_name = Params["proc_name"].Value.ToString();
                    Params.Remove("proc_name");
                }
                System.Data.DataTable T = M.ExecuteSPWithParams(proc_name, Params);
                return(View(T));
            }
            else
            {
                throw new System.Exception("procedure for report is not defined!");
            }
        }
Esempio n. 12
0
        public static string SetTextProperty(int entity, string prop_name, string prop_value, string userName = null)
        {
            DersaSqlManager DM = userName == null? new DersaSqlManager(): new DersaAnonimousSqlManager();

            if (userName == null)
            {
                userName = HttpContext.Current.User.Identity.Name;
            }
            try
            {
                System.Data.DataTable T = DM.ExecuteSPWithParams("ENTITY$SetAttribute", new object[] { entity, prop_name, prop_value, userName, Util.GetPassword(userName) });
                if (T != null && T.Rows.Count > 0)
                {
                    return(T.Rows[0][0].ToString());
                }
            }
            catch
            {
                throw;
            }
            return("");
        }
Esempio n. 13
0
 public virtual void Drop(string userName, int options)
 {
     try
     {
         if (!this.AllowDrop())
         {
             return;
         }
         if (this.Parent == null)
         {
             return;
         }
         if (!(this.Parent as StereotypeBaseE).AllowModifyChildren())
         {
             return;
         }
         DersaSqlManager DM = new DersaSqlManager();
         DM.ExecuteSPWithParams("ENTITY$Remove", new object[] { this.Id, userName, Util.GetPassword(userName), options });
     }
     catch
     {
     }
 }
Esempio n. 14
0
 public string Description(string id, string attr_name)
 {
     try
     {
         DersaSqlManager       DM       = new DersaSqlManager();
         string                userName = HttpContext.Current.User.Identity.Name;
         System.Data.DataTable T        = DM.ExecuteSPWithParams("ENTITY$GetDescription", new object[] { id, attr_name, userName, Util.GetPassword(userName) });
         string                result   = "";
         if (T.Rows.Count > 0)
         {
             result = T.Rows[0][0].ToString();
         }
         if (attr_name == "DiagramXmlAdditional")
         {
             XmlDocument addXml = new XmlDocument();
             addXml.LoadXml(result);
         }
         return(result);
     }
     catch (Exception exc)
     {
         return("");
     }
 }
Esempio n. 15
0
        public static void DropRelation(int id, string userName)
        {
            DersaSqlManager DM = new DersaSqlManager();

            DM.ExecuteSPWithParams("ENTITY$Remove", new object[] { id, userName, Util.GetPassword(userName), 0 });
        }
Esempio n. 16
0
        public string GetInsertSubmenu(int id)
        {
            DataTable menuLevels = JsonConvert.DeserializeObject <DataTable>(JsonConvert.SerializeObject(
                                                                                 new object[] {
                new
                {
                    name       = "Package",
                    icon       = "/icons/Package.gif",
                    level      = 1,
                    is_submenu = false
                },
                new
                {
                    name       = "Entity",
                    icon       = "/icons/Entity.gif",
                    level      = 1,
                    is_submenu = false
                },
                new
                {
                    name       = "Attribute",
                    icon       = "/icons/Attribute.gif",
                    level      = 1,
                    is_submenu = false
                },
                new
                {
                    name       = "Script",
                    icon       = "/icons/Script.gif",
                    level      = 1,
                    is_submenu = false
                },
                new
                {
                    name       = "Procedure",
                    icon       = "/icons/Procedure.gif",
                    level      = 1,
                    is_submenu = false
                },
                new
                {
                    name       = "Method",
                    icon       = "/icons/Method.gif",
                    level      = 1,
                    is_submenu = false
                },
                new
                {
                    name       = "прочие",
                    icon       = "",
                    level      = 1,
                    is_submenu = true
                }
            }));
            DersaSqlManager DM               = new DersaSqlManager();
            string          userName         = HttpContext.Current.User.Identity.Name;
            DataTable       childStereotypes = DM.ExecuteSPWithParams("ENTITY$GetChildStereotypes", new object[] { id, userName, Util.GetPassword(userName) });
            var             result           = from DataRow RL in menuLevels.Rows
                                               where RL["level"].ToString() == "1" && (childStereotypes.Select("name = '" + RL["name"].ToString() + "'").Length > 0 || (bool)RL["is_submenu"])//аналог exists
                                               select
                                               new
            {
                label    = RL["name"],
                icon     = RL["icon"],
                children = from DataRow RS in childStereotypes.Rows
                           where menuLevels.Select("name = '" + RS["name"].ToString() + "'").Length == 0 && (bool)RL["is_submenu"]
                           select
                           new
                {
                    label = RS["name"],
                    icon  = RS["icon_path"]
                }
            };

            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 17
0
        public string ExecSql(string json_params)
        {
            IParameterCollection Params = Util.DeserializeParams(json_params);

            if (!Params.Contains("SQL"))
            {
                return(json_params);
            }
            else
            {
                DersaSqlManager      M          = new DersaSqlManager();
                string               sql        = Params["SQL"].Value.ToString().Replace("$gt$", ">").Replace("$lt$", "<");
                IParameterCollection UserParams = new ParameterCollection();
                string               userName   = HttpContext.Current.User.Identity.Name;
                UserParams.Add("@login", userName);
                UserParams.Add("@password", Util.GetPassword(userName));
                int userPermissions = M.ExecuteSPWithResult("DERSA_USER$GetPermissions", false, UserParams);
                int canExecSql      = userPermissions & 1;
                if (canExecSql == 0)
                {
                    return("You have no permissions to exec SQL in database.");
                }
                UserParams.Add("@user_setting_name", "Выполнять SQL локально");
                int execSqlLocal    = M.ExecuteSPWithResult("DERSA_USER$GetBoolUserSetting", false, UserParams);
                int canExecLocalSql = userPermissions & 2;
                if (execSqlLocal > 0)
                {
                    if (canExecLocalSql == 0)
                    {
                        return("You have no permissions to exec SQL locally.");
                    }
                    else
                    {
                        string queryId = GetQueryId(sql);
                        (UserParams["@user_setting_name"] as IParameter).Value = "Функция вызова локального клиента SQL";
                        System.Data.DataTable VT = M.ExecuteSPWithParams("DERSA_USER$GetTextUserSetting", UserParams);
                        if (VT == null || VT.Rows.Count < 1)
                        {
                            throw new Exception("Функция вызова локального клиента SQL не определена");
                        }
                        string functionBody = VT.Rows[0][0].ToString();
                        var    result       = new { action = functionBody, arg_name = "queryId", arg = queryId };
                        return(JsonConvert.SerializeObject(result));
                    }
                }

                try
                {
                    string result = "Unknown error";
                    if (Params.Contains("Server") && Params["Server"].Value != null)
                    {
                        string     connectionString = string.Format("Server={0};Database={1};user={2};password={3}", Params["Server"].Value, Params["Database"].Value, Params["Login"].Value, Params["Password"].Value);
                        SqlManager ExecM            = new SqlManager(connectionString);
                        result = ExecM.ExecMultiPartSql(sql);
                    }
                    else
                    {
                        DersaUserSqlManager UM = new DersaUserSqlManager();
                        result = UM.ExecMultiPartSql(sql);
                    }
                    if (result != "")
                    {
                        return(result);
                    }
                    return("Запрос успешно выполнен:\n\n" + sql);
                }
                catch (Exception exc)
                {
                    return(exc.Message);
                }
            }
        }