ExtensionFunction.cs 6.8 KB
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace Model
//{
//    public abstract class ExtensionFunction
//    {
//        protected List<ExtensionControl> extensions;
//        private Dictionary<string, int> reelID;

//        private void ReelIDInit()
//        {
//            reelID = new();
//            if (System.IO.File.Exists(FilePath.CONFIG_REELID))
//            {
//                string[] lines = System.IO.File.ReadAllLines(FilePath.CONFIG_REELID);
//                for (int i = 0; i < lines.Length; i++)
//                {
//                    string[] arr = lines[i].Split(',');
//                    if (arr.Length != 2) continue;
//                    reelID.Add(arr[0], Convert.ToInt32(arr[1]));
//                }
//            }
//        }

//        protected void ClearText()
//        {
//            for (int i = 0; i < extensions.Count; i++)
//            {
//                if (!extensions[i].CanClear) continue;
//                if (extensions[i].Control is Asa.FaceControl.FaceComboBox box)
//                    box.Items.Clear();
//                extensions[i].Control.Text = "";
//            }
//        }

//        protected void SetControlText(Dictionary<string, string> key)
//        {
//            for (int i = 0; i < extensions.Count; i++)
//            {
//                if (key.ContainsKey(extensions[i].Key))
//                    extensions[i].Control.Text = key[extensions[i].Key];
//            }
//        }

//        protected void SetControlText(string name, string text)
//        {
//            int index = extensions.FindIndex(match => match.Control.Name == name);
//            if (index > -1) extensions[index].Control.Text = text;
//        }

//        protected void SetComboItem(string name, string[] text)
//        {
//            int index = extensions.FindIndex(match => match.Control.Name == name);
//            if (index == -1) return;
//            Asa.FaceControl.FaceComboBox cbo = (Asa.FaceControl.FaceComboBox)extensions[index].Control;
//            cbo.Items.AddRange(text);
//            cbo.SelectedIndex = -1;
//        }
        
//        protected void SetComboSelected(string name, int index)
//        {
//            int idx = extensions.FindIndex(match => match.Control.Name == name);
//            if (idx == -1) return;
//            ((Asa.FaceControl.FaceComboBox)extensions[idx].Control).SelectedIndex = index;
//        }

//        protected string GetControlText(string name)
//        {
//            int index = extensions.FindIndex(match => match.Control.Name == name);
//            if (index == -1) return "";
//            return extensions[index].Control.Text;
//        }

//        //protected string GetControlTextFromKey(string key)
//        //{
//        //    int index = extensions.FindIndex(match => match.Key == key);
//        //    if (index == -1) return "";
//        //    return extensions[index].Control.Text;
//        //}

//        protected void SetControlEnabled(bool value, params string[] name)
//        {
//            for (int i = 0; i < name.Length; i++)
//            {
//                int index = extensions.FindIndex(match => match.Control.Name == name[i]);
//                if (index == -1) continue;
//                extensions[index].Control.Enabled = value;
//            }
//        }

//        protected void GetReelID(out string key, out string value)
//        {
//            //读取参数
//            string matchID = AppConfig.Read(AppConfigKey.REEL_ID_MATCH);
//            AppConfig.Read(AppConfigKey.REEL_ID_PLACES, out int matchPlace);
//            AppConfig.Read(AppConfigKey.REEL_ID_FILL_ZERO, out bool matchFill);
//            string matchPrefix = AppConfig.Read(AppConfigKey.REEL_ID_PREFIX);
//            string matchPostfix = AppConfig.Read(AppConfigKey.REEL_ID_POSTFIX);

//            //把key替换成实际值
//            string[] keys = ObjConversion.StrGetKey(matchID);
//            for (int i = 0; i < keys.Length; i++)
//            {
//                int index = extensions.FindIndex(match => match.Key == keys[i]);
//                if (index == -1) continue;
//                string oldValue = string.Format("[{0}]", keys[i]);
//                matchID = matchID.Replace(oldValue, extensions[index].Control.Text);
//            }

//            //查找是否存在
//            if (reelID == null) ReelIDInit();
//            if (!reelID.ContainsKey(matchID))
//                reelID.Add(matchID, 0);
//            int val = reelID[matchID] + 1;

//            //填充0
//            string text = matchPrefix;
//            if (matchFill)
//                text += string.Format("{0:d" + matchPlace + "}", val);
//            else
//                text += val.ToString();
//            text += matchPostfix;

//            key = matchID;
//            value = text;
//        }

//        protected void SetReelIDAdd(string key)
//        {
//            reelID[key]++;

//            int idx = 0;
//            string[] lines = new string[reelID.Count];
//            foreach (string s in reelID.Keys)
//                lines[idx++] = string.Format("{0},{1}", s, reelID[s]);
//            System.IO.File.WriteAllLines(FilePath.CONFIG_REELID, lines);
//        }

//        protected Dictionary<string, string> GetPrintKey()
//        {
//            Dictionary<string, string> key = new();
//            for (int i = 0; i < extensions.Count; i++)
//            {
//                if (extensions[i].Key == "") continue;
//                if (key.ContainsKey(extensions[i].Key))
//                    key[extensions[i].Key] = extensions[i].Control.Text;
//                else
//                    key.Add(extensions[i].Key, extensions[i].Control.Text);
//            }
//            return key;
//        }

//        protected bool CheckEmptyContent()
//        {
//            //返回true有空内容不打印
//            AppConfig.Read(AppConfigKey.LABEL_EMPTY_CHECK, out bool check);
//            if (!check) return false;
//            if (extensions == null) return true;

//            bool find = false;
//            for (int i = 0; i < extensions.Count; i++)
//            {
//                if (extensions[i].Key != "" && extensions[i].Control.Text == "")
//                {
//                    find = true;
//                    break;
//                }
//            }
//            if (find)
//            {
//                string text = Asa.FaceControl.Language.Dialog("LabelEmpty");
//                Asa.FaceControl.FaceMessageBox dlg = new("", text, System.Windows.Forms.MessageBoxButtons.YesNo);
//                System.Windows.Forms.DialogResult dr = dlg.ShowDialog();
//                return dr == System.Windows.Forms.DialogResult.No;

//            }

//            return false;
//        }

//    }
//}