Ejemplo n.º 1
0
 public static string GetErrorText(this FunctionItem instance)
 {
     if (lastError.ContainsKey(instance.GetHashCode()))
     {
         return(lastError[instance.GetHashCode()]);
     }
     return("");
 }
Ejemplo n.º 2
0
        private void gridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (WFlag == WFlag_Free)
            {
                int rowIndex    = e.RowIndex;
                int columnIndex = e.ColumnIndex;

                if (rowIndex >= 0 && columnIndex == 1)
                {
                    FunctionItem    item       = version.Pages[PageIndex].Items[rowIndex];
                    DataGridViewRow currentRow = gridView.Rows[rowIndex];
                    string          errorText  = "";


                    WFlag = WFlag_Busy;
                    if (item.FormStyle == "文本框")
                    {
                        string value = "0";
                        if (currentRow.Cells["value"].Value != null)
                        {
                            value = currentRow.Cells["value"].Value.ToString();
                        }

                        item.Write(value);
                        errorText = item.GetErrorText();
                    }
                    else if (item.FormStyle == "下拉列表")
                    {
                        string str = currentRow.Cells["value"].Value.ToString();
                        int    key = item.ValueStringMap.GetKey(str);

                        if (key != -1)
                        {
                            item.Write(key.ToString());
                        }

                        errorText = item.GetErrorText();
                    }
                    else if (item.FormStyle == "单选框")
                    {
                        string value = currentRow.Cells["value"].Value.ToString();
                        if (value.ToLower() == "true")
                        {
                            item.Write("1");
                        }
                        else if (value.ToLower() == "false")
                        {
                            item.Write("0");
                        }
                        errorText = item.GetErrorText();
                    }

                    //每次修改数据就刷新列表
                    backgroundWorker1.RunWorkerAsync(new FunctionBag {
                        Items = version.Pages[PageIndex].Items, IsReload = true
                    });

                    WaitBox.Wait();//对话框中断等待
                    WFlag = WFlag_Free;

                    gridView.Rows[rowIndex].Cells[2].Value = errorText;
                }
            }
        }
Ejemplo n.º 3
0
        public static object Read(this FunctionItem instance, bool isReload = false)
        {
            if (value_temp.ContainsKey(instance.GetHashCode()) != true)
            {
                value_temp.Add(instance.GetHashCode(), null);
            }
            if (lastError.ContainsKey(instance.GetHashCode()) != true)
            {
                lastError.Add(instance.GetHashCode(), "");
            }

            if (!isReload)
            {
                if (value_temp[instance.GetHashCode()] != null)
                {
                    return(value_temp[instance.GetHashCode()]);
                }
            }
            //读内存
            try
            {
                int  pid     = ModifierConfigEx.ProcessInfo.Pid;
                long address = instance.Address.GetAddress();

                Type valueType = instance.GetValueType();

                switch (valueType.Name)
                {
                case "Int64":
                    value_temp[instance.GetHashCode()] = APIHelper.ReadMemoryByBinary(pid, address, instance.StartPlace, instance.Size);
                    break;

                case "Int32":
                    value_temp[instance.GetHashCode()] = APIHelper.ReadMemoryByInt32(pid, address);
                    break;

                case "Int16":
                    value_temp[instance.GetHashCode()] = APIHelper.ReadMemoryByInt16(pid, address);
                    break;

                case "Byte":
                    value_temp[instance.GetHashCode()] = APIHelper.ReadMemoryByByte(pid, address);
                    break;

                case "Double":
                    value_temp[instance.GetHashCode()] = APIHelper.ReadMemoryByDouble(pid, address);
                    break;

                case "Single":
                    value_temp[instance.GetHashCode()] = APIHelper.ReadMemoryByFloat(pid, address);
                    break;

                case "String":
                    value_temp[instance.GetHashCode()] = APIHelper.ReadMemoryByString(pid, address, instance.Size);
                    break;

                case "Byte[]":
                    value_temp[instance.GetHashCode()] = APIHelper.ReadMemoryByBytes(pid, address, instance.Size);
                    break;

                default:
                    break;
                }
                //读取成功,错误信息清除
                lastError[instance.GetHashCode()] = "";
            }
            catch (Exception ex)
            {
                value_temp[instance.GetHashCode()] = -1;
                lastError[instance.GetHashCode()]  = ex.Message;
            }
            return(value_temp[instance.GetHashCode()]);
        }
Ejemplo n.º 4
0
 public static Type GetValueType(this FunctionItem instance)
 {
     return(Type.GetType(instance.ValueType));
 }
Ejemplo n.º 5
0
        public static void Write(this FunctionItem instance, string value)
        {
            if (value_temp.ContainsKey(instance.GetHashCode()) != true)
            {
                value_temp.Add(instance.GetHashCode(), null);
            }
            if (lastError.ContainsKey(instance.GetHashCode()) != true)
            {
                lastError.Add(instance.GetHashCode(), "");
            }
            //读取成功之后改写这个value_temp
            //value_temp = value;
            //写内存
            if (instance.ReadOnly != true)
            {
                try
                {
                    int  pid     = ModifierConfigEx.ProcessInfo.Pid;
                    long address = instance.Address.GetAddress();

                    Type valueType = instance.GetValueType();

                    //若写的值为整形最大/小,则忽略
                    if (double.Parse(value) == int.MaxValue || double.Parse(value) == int.MinValue)
                    {
                        return;
                    }

                    //判断大小
                    if (instance.MaxValue != int.MaxValue || instance.MinValue != int.MinValue)
                    {
                        if (double.Parse(value) > instance.MaxValue || double.Parse(value) < instance.MinValue)
                        {
                            throw new Exception("值应该大于" + instance.MinValue + ",且小于" + instance.MaxValue);
                        }
                    }


                    switch (valueType.Name)
                    {
                    case "Int64":
                        object obj = Int64.Parse(value);

                        APIHelper.WriteMemoryByBinary(pid, address, instance.StartPlace, instance.Size, (Int64)obj);
                        value_temp[instance.GetHashCode()] = obj;
                        break;

                    case "Int32":
                        obj = Int32.Parse(value);

                        APIHelper.WriteMemoryByInt32(pid, address, (Int32)obj);
                        value_temp[instance.GetHashCode()] = obj;

                        break;

                    case "Int16":
                        obj = Int16.Parse(value);

                        APIHelper.WriteMemoryByInt16(pid, address, (Int16)obj);
                        value_temp[instance.GetHashCode()] = obj;
                        break;

                    case "Byte":
                        obj = Byte.Parse(value);

                        APIHelper.WriteMemoryByByte(pid, address, (byte)obj);
                        value_temp[instance.GetHashCode()] = obj;
                        break;

                    case "Double":
                        obj = Double.Parse(value);

                        APIHelper.WriteMemoryByDouble(pid, address, (double)obj);
                        value_temp[instance.GetHashCode()] = obj;

                        break;

                    case "Single":
                        obj = Single.Parse(value);

                        APIHelper.WriteMemoryByFloat(pid, address, Single.Parse(value));
                        value_temp[instance.GetHashCode()] = obj;

                        break;

                    case "String":
                        byte[] bytes = System.Text.Encoding.Unicode.GetBytes(value);

                        APIHelper.WriteMemoryByBytes(pid, address, bytes);
                        value_temp[instance.GetHashCode()] = bytes;

                        break;

                    default:
                        break;
                    }
                    //写成功,清除错误信息
                    lastError[instance.GetHashCode()] = "";
                }
                catch (Exception ex)
                {
                    lastError[instance.GetHashCode()] = ex.Message;
                    //throw ex;
                }
            }
        }