Beispiel #1
0
        public static Models.Core.Program GetProgramByCode(string programCode)
        {
            BusinessLayer.General.Logging.Log("Loading program info for code '" + programCode + "' from database", BusinessLayer.General.Logging.LogLevel.Debug);
            var session = Session.OpenSession();

            Models.Core.Program pgm = session.CreateCriteria(typeof(Models.Core.Program))
                                      .Add(Expression.Eq("Code", programCode))
                                      .UniqueResult <Models.Core.Program>();
            BusinessLayer.General.Logging.Log("Got program info for code '" + programCode + "'", BusinessLayer.General.Logging.LogLevel.Debug);
            return(pgm);
        }
Beispiel #2
0
        public static Models.Core.Program GetProgram(FHFormTab form)
        {
            Models.Core.Program pgm = null;
            string typ = GetProgramType(form);

            BusinessLayer.General.Logging.Log("Loading program info for '" + typ + "' from database", BusinessLayer.General.Logging.LogLevel.Debug);
            var session = Session.OpenSession();

            pgm = session.CreateCriteria(typeof(Models.Core.Program))
                  .Add(Expression.Eq("Form", typ))
                  .UniqueResult <Models.Core.Program>();
            BusinessLayer.General.Logging.Log("Got program info for '" + typ + "'", BusinessLayer.General.Logging.LogLevel.Debug);
            return(pgm);
        }
Beispiel #3
0
        public static void OpenForm(string code)
        {
            try
            {
                var session             = Session.DatabaseConnection;
                Models.Core.Program pgm = session.CreateCriteria(typeof(Models.Core.Program))
                                          .Add(Expression.Eq("Code", code))
                                          .UniqueResult <Models.Core.Program>();

                if (pgm != null)
                {
                    string form   = pgm.Form;
                    string prefix = "FamiHub.UI.";
                    if (pgm.Form.StartsWith("*."))
                    {
                        prefix = "FamiHub.Core.";
                        form   = pgm.Form.Replace("*.", "");
                    }
                    dynamic ProjAndForm = prefix + form + ",FamiHub";
                    Type    objType     = Type.GetType(ProjAndForm);
                    Control objForm     = (Control)Activator.CreateInstance(objType);
                    ((FHFormTab)objForm).Show();
                }
                else
                {
                    if (!string.IsNullOrEmpty(code))
                    {
                        Interaction.ThrowMessage(Session.MainForm, "Input invalid");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandling.HandleException(ex);
            }
        }
Beispiel #4
0
        public static void Translate(this Control parent, string formName = null, IList <Models.Core.FormTranslation> trls = null)
        {
            try
            {
                string sessionLanguage = Session.CurrentUser?.Language ?? "en";

                if (formName == null)
                {
                    formName = GetProgramType((FHFormTab)parent);
                    if (parent is FHFormTab)
                    {
                        Models.Core.Program pgm = GetProgram((FHFormTab)parent);
                        parent.Text = pgm?.Description;
                        parent.Text = Localization.TranslateCpt(formName, "_form", sessionLanguage, parent.Text);
                        if (!string.IsNullOrEmpty(pgm?.Code))
                        {
                            parent.Text = parent.Text;
                        }

                        BusinessLayer.General.Logging.Log("Form title set to '" + parent.Text + "' for form " + formName, BusinessLayer.General.Logging.LogLevel.Debug);
                    }
                }

                if (trls == null)
                {
                    trls = Localization.GetFormTranslationsByForm(formName, sessionLanguage);
                }

                Models.Core.FormTranslation trl;
                foreach (Control c in parent.Controls)
                {
                    if (HasProperty(c, "Text") && ToTranslate(c))
                    {
                        if (c.Text != "" && c.Text != c.Name.ToString() && c.Text != "..." && c.Name.ToString().Substring(0, 3) != "ntr" && c.Name.ToString().Substring(0, 3) != "txt")
                        {
                            trl = trls.Cast <Models.Core.FormTranslation>().FirstOrDefault(i => i.Component == c.Name);
                            if (!string.IsNullOrEmpty(trl?.Translation))
                            {
                                c.Text = trl.Translation;
                            }
                            else
                            {
                                c.Text = Localization.TranslateCpt(formName, c.Name, sessionLanguage, c.Text);
                            }
                        }
                    }
                    if (c is DataGridView)
                    {
                        BusinessLayer.General.Logging.Log("Component '" + c.Name + "' is DataGridView, using other translation method", BusinessLayer.General.Logging.LogLevel.Debug);
                        DataGridView dgv = (DataGridView)c;
                        foreach (DataGridViewColumn column in dgv.Columns)
                        {
                            trl = trls.Cast <Models.Core.FormTranslation>().FirstOrDefault(i => i.Component == column.Name);
                            if (!string.IsNullOrEmpty(trl?.Translation))
                            {
                                column.HeaderText = trl.Translation;
                            }
                            else
                            {
                                column.HeaderText = Localization.TranslateCpt(formName, column.Name, sessionLanguage, column.HeaderText);
                            }
                        }
                    }
                    Translate(c, formName, trls);
                }
            }
            catch (Exception ex)
            {
                Common.ExceptionHandling.HandleException(ex);
            }
        }
Beispiel #5
0
        public static void Build()
        {
            try
            {
                var              session        = Session.DatabaseConnection;
                List <string>    Permissionlist = new List <string>();
                Models.Core.User user           = Session.CurrentUser;

                string nodename = null;
                Session.MainForm.navigationMenu.Controls.Clear();
                System.Drawing.Font nodeFont    = new System.Drawing.Font("Tahoma", 10);
                System.Drawing.Font topNodeFont = new System.Drawing.Font("Tahoma", 10, System.Drawing.FontStyle.Bold);
                ImageList           tabImages   = new ImageList();
                Session.MainForm.navigationMenu.ImageList = tabImages;
                int imageIdx = 0;

                if (user.UserGroup != null)
                {
                    IList <Models.Core.UserGroupMenu> userGroupMenus = session.CreateCriteria(typeof(Models.Core.UserGroupMenu))
                                                                       .Add(Expression.Eq("UserGroup", user.UserGroup))
                                                                       .AddOrder(Order.Asc("Sequence"))
                                                                       .List <Models.Core.UserGroupMenu>();

                    foreach (Models.Core.UserGroupMenu ugmMenu in userGroupMenus)
                    {
                        TreeView menuTree = new TreeView();
                        menuTree.SelectedNode       = null;
                        menuTree.SelectOnRightClick = true;
                        menuTree.Nodes.Clear();

                        Models.Core.Menu menu = ugmMenu.Menu;

                        IList <Models.Core.MenuItem> menuPrograms = session.CreateCriteria(typeof(Models.Core.MenuItem))
                                                                    .Add(Expression.Eq("Menu", menu))
                                                                    .AddOrder(Order.Asc("Sequence"))
                                                                    .List <Models.Core.MenuItem>();

                        foreach (Models.Core.MenuItem menuProgram in menuPrograms)
                        {
                            Models.Core.Program program = menuProgram.Program;
                            nodename = Localization.TranslateCpt(program.Form, "_form", Session.CurrentUser.Language ?? "en", program.Description);
                            menuTree.Nodes.Add(program.Code, nodename).NodeFont = nodeFont;
                            Permissionlist.Add(program.Code.ToLower());
                        }

                        NavigationTab objTabControls = new NavigationTab(menu.Description);
                        menuTree.Dock            = DockStyle.Fill;
                        menuTree.ShowLines       = false;
                        menuTree.NodeMouseClick += Session.MainForm.menuTree_MouseClick;
                        objTabControls.Controls.Add(menuTree);
                        if (!string.IsNullOrEmpty(menu.Icon))
                        {
                            tabImages.Images.Add(new Gizmox.WebGUI.Common.Resources.IconResourceHandle(menu.Icon));
                            objTabControls.ImageIndex = imageIdx;
                            imageIdx++;
                        }
                        Session.MainForm.navigationMenu.Controls.Add(objTabControls);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandling.HandleException(ex);
            }
        }
Beispiel #6
0
        private static void InstallProgramDefinition()
        {
            BusinessLayer.General.Logging.Log("Updating program table in database", BusinessLayer.General.Logging.LogLevel.Info);

            string data;

            Models.Core.Module packObj = null;
            Stream             pgmFile = Assembly.GetExecutingAssembly().GetManifestResourceStream("FamiHub.UI.Programs.txt");

            using (StreamReader reader = new StreamReader(pgmFile))
            {
                while (reader.Peek() >= 0)
                {
                    data = reader.ReadLine();

                    if (!string.IsNullOrEmpty(data))
                    {
                        BusinessLayer.General.Logging.Log(". Processing line: " + data.ToString(), BusinessLayer.General.Logging.LogLevel.Debug);
                        if (data.ToString().Substring(0, 2) != "''")
                        {
                            if (data.ToString().Substring(0, 1) == "*" &&
                                data.ToString().Substring(data.ToString().Length - 1, 1) == "*")
                            {
                                string[] packArray = data.Split(new char[] { '\\' });
                                string   package   = packArray[0].Trim('*');

                                BusinessLayer.General.Logging.Log(".. Processing line for module: '" + package + "'", BusinessLayer.General.Logging.LogLevel.Debug);
                                if (!string.IsNullOrEmpty(package?.Trim()))
                                {
                                    string packageDescr = "";

                                    try
                                    {
                                        packageDescr = packArray[1].Trim('*');
                                    }
                                    catch
                                    {
                                        BusinessLayer.General.Logging.Log("... Cannot determine module description for '" + package + "'", BusinessLayer.General.Logging.LogLevel.Warning);
                                    }

                                    if (packageDescr.Trim() == "")
                                    {
                                        packageDescr = package;
                                    }

                                    Models.Core.Module pack = Crud.GetById <Models.Core.Module, string>(package);
                                    if (pack == null)
                                    {
                                        BusinessLayer.General.Logging.Log("... Module doesn't exist, creating new module '" + package + "'", BusinessLayer.General.Logging.LogLevel.Debug);
                                        pack         = new Models.Core.Module();
                                        pack.Package = package;
                                    }

                                    BusinessLayer.General.Logging.Log("... Saving module '" + package + "'", BusinessLayer.General.Logging.LogLevel.Info);
                                    pack.Description = packageDescr;
                                    Crud.Put(pack);
                                    packObj = pack;
                                }
                                else
                                {
                                    BusinessLayer.General.Logging.Log(".. Found corrupt module definition, line skipped", BusinessLayer.General.Logging.LogLevel.Warning);
                                    package = null;
                                    packObj = null;
                                }
                            }
                            else
                            {
                                BusinessLayer.General.Logging.Log(".. Processing line for program: " + data.ToString(), BusinessLayer.General.Logging.LogLevel.Debug);
                                string[] array = data.Split(new char[] { '\\' });
                                string   desc  = array[0];
                                string   type  = array[1];
                                string   code  = array[2];
                                string   form  = array[3];

                                Models.Core.Program prog = Crud.GetById <Models.Core.Program, string>(form);
                                if (prog != null)
                                {
                                    BusinessLayer.General.Logging.Log("... Saving program '" + form + "'", BusinessLayer.General.Logging.LogLevel.Debug);
                                    prog.Code        = code;
                                    prog.Description = desc;
                                    prog.Form        = form;
                                    prog.Type        = type;
                                    prog.Package     = packObj;
                                }
                                else
                                {
                                    BusinessLayer.General.Logging.Log("... Program doesn't exist, creating new program '" + form + "'", BusinessLayer.General.Logging.LogLevel.Debug);
                                    prog = new Models.Core.Program()
                                    {
                                        Code        = code,
                                        Description = desc,
                                        Form        = form,
                                        Type        = type,
                                        Package     = packObj
                                    };
                                }

                                Crud.Put(prog);
                            }
                        }
                        else
                        {
                            BusinessLayer.General.Logging.Log(".. Skipping line because this is a comment", BusinessLayer.General.Logging.LogLevel.Debug);
                        }
                    }
                }
            }

            BusinessLayer.General.Logging.Log("Updated program table in database", BusinessLayer.General.Logging.LogLevel.Info);
        }