Exemplo n.º 1
0
        public static T ToEnum(EnumParser <T>[] list, string str, T default_value)
        {
            object obj1 = Useful.ToEnum(typeof(T), (object)str);

            if (obj1 != null)
            {
                return((T)obj1);
            }
            int result;

            if (int.TryParse(str, out result))
            {
                object obj2 = Useful.ToEnum(typeof(T), (object)result);
                if (obj2 != null)
                {
                    return((T)obj2);
                }
            }
            foreach (EnumParser <T> enumParser in list)
            {
                if (enumParser.CanParseForOtherCase(str))
                {
                    return(enumParser.SuccessValue);
                }
            }
            return(default_value);
        }
Exemplo n.º 2
0
        public bool CanParse(string str)
        {
            if (string.Compare(m_to_string, str, true) == 0 || string.Compare(m_success_value.ToString(), str, true) == 0)
            {
                return(true);
            }
            object obj1 = Useful.ToEnum(typeof(T), (object)str);

            if (obj1 != null && m_success_value.Equals((object)(T)obj1))
            {
                return(true);
            }
            int result;

            if (int.TryParse(str, out result))
            {
                object obj2 = Useful.ToEnum(typeof(T), (object)result);
                if (obj2 != null && m_success_value.Equals((object)(T)obj2))
                {
                    return(true);
                }
            }
            if (m_other_to_enum_strings != null)
            {
                foreach (string strA in m_other_to_enum_strings)
                {
                    if (string.Compare(strA, str, true) == 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public static void ChangeClientSize_Center(Form form, Size new_client_size, bool is_hide_window_when_update)
        {
            if (form == null || new_client_size.Width <= 0 || new_client_size.Height <= 0)
            {
                throw new ArgumentException("引수エラ\x30FC");
            }
            if (form.ClientSize == new_client_size)
            {
                return;
            }
            Point positionCenter     = Useful.GetPositionCenter(form);
            Size  size               = form.Size - form.ClientSize + new_client_size;
            Point positionFromCenter = Useful.GetPositionFromCenter(positionCenter, size);

            if (is_hide_window_when_update)
            {
                bool visible = form.Visible;
                form.Visible = false;
                form.SetBounds(positionFromCenter.X, positionFromCenter.Y, size.Width, size.Height);
                form.Visible = visible;
            }
            else
            {
                form.SetBounds(positionFromCenter.X, positionFromCenter.Y, size.Width, size.Height);
            }
        }
Exemplo n.º 4
0
        public static XmlNode XmlAddPoint(XmlNode p_node, string node_name, Point p)
        {
            XmlNode node = Useful.XmlAddNode(p_node, node_name);

            Useful.XmlAddAttribute(node, "x", p.X.ToString());
            Useful.XmlAddAttribute(node, "y", p.Y.ToString());
            return(node);
        }
Exemplo n.º 5
0
 public static Point GetPositionFromCenter(Form form, Point center_pos)
 {
     if (form == null)
     {
         return(Point.Empty);
     }
     else
     {
         return(Useful.GetPositionFromCenter(center_pos, form.Size));
     }
 }
Exemplo n.º 6
0
 public static XmlNode XmlGetElement(XmlNode parent, string name, string name2)
 {
     if (parent == null)
     {
         return((XmlNode)null);
     }
     foreach (XmlNode node in parent.ChildNodes)
     {
         if (node.Name == name && Useful.XmlGetAttribute(node, "name", "") == name2)
         {
             return(node);
         }
     }
     return((XmlNode)null);
 }
Exemplo n.º 7
0
        public static XmlDocument XmlCreateXml(string root_name, string version)
        {
            if (string.IsNullOrEmpty(root_name))
            {
                return((XmlDocument)null);
            }
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.AppendChild((XmlNode)xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", (string)null));
            xmlDocument.AppendChild((XmlNode)xmlDocument.CreateElement(root_name));
            if (!string.IsNullOrEmpty(version))
            {
                Useful.XmlAddAttribute((XmlNode)xmlDocument.DocumentElement, "version", version);
            }
            return(xmlDocument);
        }
Exemplo n.º 8
0
        public static XmlNode XmlAddNode(XmlNode p_node, string node_name, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return((XmlNode)null);
            }
            name = name.Trim();
            if (string.IsNullOrEmpty(name))
            {
                return((XmlNode)null);
            }
            XmlNode node = Useful.XmlAddNode(p_node, node_name);

            Useful.XmlAddAttribute(node, "name", name);
            return(node);
        }
Exemplo n.º 9
0
        public static T ToEnum(string str, T default_value)
        {
            object obj1 = Useful.ToEnum(typeof(T), (object)str);

            if (obj1 != null)
            {
                return((T)obj1);
            }
            int result;

            if (int.TryParse(str, out result))
            {
                object obj2 = Useful.ToEnum(typeof(T), (object)result);
                if (obj2 != null)
                {
                    return((T)obj2);
                }
            }
            return(default_value);
        }
Exemplo n.º 10
0
        public static string XmlGetElementText(XmlNode parent, string name)
        {
            if (parent == null)
            {
                return("");
            }
            XmlNode node = (XmlNode)parent[name];

            if (node == null)
            {
                return("");
            }
            string firstText = Useful.XmlGetFirstText(node);

            if (!string.IsNullOrEmpty(firstText))
            {
                return(firstText);
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 11
0
        public static Point XmlGetPoint(XmlNode p_node, string node_name, Point default_p)
        {
            if (p_node == null)
            {
                return(default_p);
            }
            XmlNode xmlNode = (XmlNode)p_node[node_name];

            if (xmlNode == null)
            {
                return(default_p);
            }
            XmlAttribute xmlAttribute1 = xmlNode.Attributes["x"];
            XmlAttribute xmlAttribute2 = xmlNode.Attributes["y"];

            if (xmlAttribute1 == null || xmlAttribute2 == null)
            {
                return(default_p);
            }
            else
            {
                return(Useful.ToPoint(xmlAttribute1.Value, xmlAttribute2.Value, default_p));
            }
        }
Exemplo n.º 12
0
 public static void ChangeClientSize_Center(Form form, Size new_client_size)
 {
     Useful.ChangeClientSize_Center(form, new_client_size, false);
 }
Exemplo n.º 13
0
 public static object ToEnum(Type enumType, object value, object default_value)
 {
     return(Useful.ToEnum(enumType, value) ?? default_value);
 }
Exemplo n.º 14
0
        /*-------------------------------------------------------------------------
         *
         * ---------------------------------------------------------------------------*/
        private void initialize(string window_title, Exception ex, string message_top, string url, string device_info_string)
        {
            InitializeComponent();

            // エラー内容生成
            string message = "";

            if (!String.IsNullOrEmpty(message_top))
            {
                message += message_top + "\n";
            }

            // 日時
            message += "DATE:" + Useful.TojbbsDateTimeString(DateTime.Now) + "\n";

            // OSバージョン
            OperatingSystem os = Environment.OSVersion;

            message += "OS:" + os.VersionString + "\n";
            message += "OS:" + Useful.GetOsName(os) + "\n";

            // device info string
            if (!String.IsNullOrEmpty(device_info_string))
            {
                message += "DeviceInfo:" + device_info_string + "\n";
            }

            if (ex == null)
            {
                //
                message += "エラー内容が不明";
            }
            else
            {
                message += "Message: " + ex.Message + "\nStackTrace:\n";
                message += make_error_message(ex.StackTrace);
            }
            m_message = message;

            // windowタイトル
            if (!String.IsNullOrEmpty(window_title))
            {
                this.Text = window_title;
            }

            // エラー内容
            textBox1.AcceptsReturn = true;
            textBox1.Lines         = m_message.Split(new char[] { '\n' });
            textBox1.Select(0, 0);

            // エラー報告ボタン
            if (!String.IsNullOrEmpty(url))
            {
                m_url = url;
            }
            else
            {
                m_url           = "";
                button2.Enabled = false;
                label2.Text     = "--";
            }
        }