Exemplo n.º 1
0
        private void Save()
        {
            //dodawanie urządzenia do bazy

            //tworzenie obiektów i przypisanie im wartości z wypełnionego formularza
            genre tmpGenre = new genre();

            tmpGenre.genre_name = KindOfDevice.ToLower();

            device tmpDevice = new device();

            tmpDevice.genre             = tmpGenre;
            tmpDevice.manufacturer_name = ManufacturerName.ToLower();
            tmpDevice.model_name        = ModelName.ToLower();
            tmpDevice.serial_number     = SerialNumber.ToLower();

            try
            {
                CostPerDay      = CostPerDay.Replace(".", ",");
                tmpDevice.price = Convert.ToDouble(CostPerDay);
            }

            catch (Exception e)
            {
                File.AppendAllText(MainWindowViewModel.PathToLog, e.ToString());
                System.Windows.MessageBox.Show("Zła wartość liczbowa");
                return;
            }

            try
            {
                using (SubscriptionContext context = new SubscriptionContext())
                {
                    context.devices.Add(tmpDevice);
                    context.SaveChanges();
                }
                System.Windows.MessageBox.Show("Dodano urządzenie do bazy.");
            }
            catch (Exception e)
            {
                File.AppendAllText(MainWindowViewModel.PathToLog, e.ToString());
                System.Windows.MessageBox.Show("Nie dodano urządzenia do bazy.");
            }
        }
Exemplo n.º 2
0
        public string GenerateReactView(string name)
        {
            var rv = GetResource($"{name}.txt", "Spa.React.views")
                     .Replace("$modelname$", ModelName.ToLower());
            Type modelType = Type.GetType(SelectedModel);

            if (name == "table")
            {
                StringBuilder fieldstr = new StringBuilder();
                var           pros     = FieldInfos.Where(x => x.IsListField == true).ToList();
                fieldstr.Append(Environment.NewLine);
                for (int i = 0; i < pros.Count; i++)
                {
                    var    item   = pros[i];
                    string label  = modelType.GetProperty(item.FieldName).GetPropertyDisplayName();
                    string render = "columnsRender";
                    if (string.IsNullOrEmpty(item.RelatedField) == false)
                    {
                        var subtype = Type.GetType(item.RelatedField);
                        if (subtype == typeof(FileAttachment))
                        {
                            render = "columnsRenderImg";
                        }
                    }
                    fieldstr.Append($@"{{
        dataIndex: ""{item.FieldName}"",
        title: ""{label}"",
        render: {render} 
    }}");
                    if (i < pros.Count - 1)
                    {
                        fieldstr.Append(",");
                    }
                    fieldstr.Append(Environment.NewLine);
                }
                return(rv.Replace("$columns$", fieldstr.ToString()));
            }
            if (name == "models")
            {
                StringBuilder fieldstr = new StringBuilder();
                var           pros     = FieldInfos.Where(x => x.IsFormField == true).ToList();

                for (int i = 0; i < pros.Count; i++)
                {
                    var    item  = pros[i];
                    string label = modelType.GetProperty(item.FieldName).GetPropertyDisplayName();
                    if (string.IsNullOrEmpty(item.RelatedField) == false)
                    {
                        var subtype = Type.GetType(item.RelatedField);
                        if (item.SubField == "`file")
                        {
                            fieldstr.Append($@"{item.FieldName}: <UploadImg />");
                        }
                        else
                        {
                            fieldstr.Append($@"{item.FieldName}: <Select placeholder=""{label}"" showArrow allowClear></Select>");
                        }
                    }
                    else
                    {
                        var  proType   = modelType.GetProperty(item.FieldName).PropertyType;
                        Type checktype = proType;
                        if (proType.IsNullable())
                        {
                            checktype = proType.GetGenericArguments()[0];
                        }
                        if (checktype == typeof(bool) || checktype.IsEnum())
                        {
                            fieldstr.Append($@"{item.FieldName}: <Switch checkedChildren={{<Icon type=""check"" />}} unCheckedChildren={{<Icon type=""close"" />}} />");
                        }
                        else if (checktype.IsPrimitive || checktype == typeof(string))
                        {
                            fieldstr.Append($@"{item.FieldName}: <Input placeholder=""请输入 {label}"" />");
                        }
                        else if (checktype == typeof(DateTime))
                        {
                            fieldstr.Append($@"{item.FieldName}: <Input placeholder=""请输入 {label}"" />");
                        }
                    }
                    if (i < pros.Count - 1)
                    {
                        fieldstr.Append(",");
                    }
                    fieldstr.Append(Environment.NewLine);
                }
                return(rv.Replace("$fields$", fieldstr.ToString()));
            }

            if (name == "search")
            {
                StringBuilder fieldstr = new StringBuilder();
                var           pros     = FieldInfos.Where(x => x.IsSearcherField == true).ToList();

                for (int i = 0; i < pros.Count; i++)
                {
                    var    item  = pros[i];
                    string label = modelType.GetProperty(item.FieldName).GetPropertyDisplayName();

                    fieldstr.Append($@"
<Form.Item label=""{label}"" {{...formItemLayout}}>
    {{getFieldDecorator('{item.FieldName}', {{
        initialValue: Store.searchParams['{item.FieldName}']
    }})(Models.{item.FieldName})}}
</Form.Item>
");
                    fieldstr.Append(Environment.NewLine);
                }
                return(rv.Replace("$fields$", fieldstr.ToString()));
            }
            if (name == "details")
            {
                StringBuilder addfield    = new StringBuilder();
                StringBuilder editfield   = new StringBuilder();
                StringBuilder detailfield = new StringBuilder();
                var           pros        = FieldInfos.Where(x => x.IsFormField == true).ToList();

                for (int i = 0; i < pros.Count; i++)
                {
                    var    item       = pros[i];
                    var    property   = modelType.GetProperty(item.FieldName);
                    string label      = property.GetPropertyDisplayName();
                    bool   isrequired = property.IsPropertyRequired();
                    string rules      = "rules: []";
                    if (isrequired == true)
                    {
                        rules = $@"rules: [{{ ""required"": true, ""message"": ""{label}不能为空"" }}]";
                    }

                    if (string.IsNullOrEmpty(item.RelatedField) == false && item.SubField == "`file")
                    {
                        addfield.Append($@"
<InfoShellCol span={{24}}>
    <Form.Item label=""{label}""  {{...formItemLayoutRow}}>
        {{getFieldDecorator('{item.FieldName}', {{

        }})(Models.{item.FieldName})}}
    </Form.Item >
</InfoShellCol>
");
                        editfield.Append($@"
<InfoShellCol span={{24}}>
    <Form.Item label=""{label}""  {{...formItemLayoutRow}}>
        {{getFieldDecorator('{item.FieldName}', {{
            initialValue: details['{item.FieldName}']
        }})(Models.{item.FieldName})}}
    </Form.Item >
</InfoShellCol>
");
                        detailfield.Append($@"
<InfoShellCol span={{24}}>
    <Form.Item label=""{label}""  {{...formItemLayoutRow}}>
        <span>
            <ToImg fileID={{details['{item.FieldName}']}} />
        </span>
    </Form.Item >
</InfoShellCol>
");
                    }
                    else
                    {
                        addfield.Append($@"
<Form.Item label=""{label}"" {{...formItemLayout}}>
    {{getFieldDecorator('{item.FieldName}', {{
        {rules}
    }})(Models.{item.FieldName})}}
</Form.Item>
");

                        editfield.Append($@"
<Form.Item label=""{label}"" {{...formItemLayout}}>
    {{getFieldDecorator('{item.FieldName}', {{
        {rules},
        initialValue: toValues(details['{item.FieldName}'])
    }})(Models.{item.FieldName})}}
</Form.Item>
");

                        detailfield.Append($@"
<Form.Item label=""{label}"" {{...formItemLayout}}>
    <span>{{toValues(details['{item.FieldName}'], ""span"")}}</span>
</Form.Item>
");
                    }
                    addfield.Append(Environment.NewLine);
                    editfield.Append(Environment.NewLine);
                    detailfield.Append(Environment.NewLine);
                }
                return(rv.Replace("$addfields$", addfield.ToString()).Replace("$editfields$", editfield.ToString()).Replace("$detailfields$", detailfield.ToString()));
            }

            return(rv);
        }
Exemplo n.º 3
0
        public void DoGen()
        {
            File.WriteAllText($"{ControllerDir}\\{ModelName}Controller.cs", GenerateController(), Encoding.UTF8);

            File.WriteAllText($"{VmDir}\\{ModelName}VM.cs", GenerateVM("CrudVM"), Encoding.UTF8);
            File.WriteAllText($"{VmDir}\\{ModelName}ListVM.cs", GenerateVM("ListVM"), Encoding.UTF8);
            File.WriteAllText($"{VmDir}\\{ModelName}BatchVM.cs", GenerateVM("BatchVM"), Encoding.UTF8);
            File.WriteAllText($"{VmDir}\\{ModelName}ImportVM.cs", GenerateVM("ImportVM"), Encoding.UTF8);
            File.WriteAllText($"{VmDir}\\{ModelName}Searcher.cs", GenerateVM("Searcher"), Encoding.UTF8);

            if (UI == UIEnum.LayUI)
            {
                File.WriteAllText($"{ViewDir}\\Index.cshtml", GenerateView("ListView"), Encoding.UTF8);
                File.WriteAllText($"{ViewDir}\\Create.cshtml", GenerateView("CreateView"), Encoding.UTF8);
                File.WriteAllText($"{ViewDir}\\Edit.cshtml", GenerateView("EditView"), Encoding.UTF8);
                File.WriteAllText($"{ViewDir}\\Delete.cshtml", GenerateView("DeleteView"), Encoding.UTF8);
                File.WriteAllText($"{ViewDir}\\Details.cshtml", GenerateView("DetailsView"), Encoding.UTF8);
                File.WriteAllText($"{ViewDir}\\Import.cshtml", GenerateView("ImportView"), Encoding.UTF8);
                File.WriteAllText($"{ViewDir}\\BatchEdit.cshtml", GenerateView("BatchEditView"), Encoding.UTF8);
                File.WriteAllText($"{ViewDir}\\BatchDelete.cshtml", GenerateView("BatchDeleteView"), Encoding.UTF8);
            }
            if (UI == UIEnum.React)
            {
                if (Directory.Exists($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}") == false)
                {
                    Directory.CreateDirectory($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}");
                }
                if (Directory.Exists($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\views") == false)
                {
                    Directory.CreateDirectory($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\views");
                }
                if (Directory.Exists($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\store") == false)
                {
                    Directory.CreateDirectory($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\store");
                }
                File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\views\\action.tsx", GenerateReactView("action"), Encoding.UTF8);
                File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\views\\details.tsx", GenerateReactView("details"), Encoding.UTF8);
                File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\views\\models.tsx", GenerateReactView("models"), Encoding.UTF8);
                File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\views\\other.tsx", GenerateReactView("other"), Encoding.UTF8);
                File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\views\\search.tsx", GenerateReactView("search"), Encoding.UTF8);
                File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\views\\table.tsx", GenerateReactView("table"), Encoding.UTF8);
                File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\store\\index.ts", GetResource("index.txt", "Spa.React.store").Replace("$modelname$", ModelName.ToLower()), Encoding.UTF8);
                File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\index.tsx", GetResource("index.txt", "Spa.React").Replace("$modelname$", ModelName.ToLower()), Encoding.UTF8);
                File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\{ModelName.ToLower()}\\style.less", GetResource("style.txt", "Spa.React").Replace("$modelname$", ModelName.ToLower()), Encoding.UTF8);

                var index = File.ReadAllText($"{MainDir}\\ClientApp\\src\\pages\\index.ts");
                if (index.Contains($"path: '/{ModelName.ToLower()}'") == false)
                {
                    index = index.Replace("/**WTM**/", $@"
, {ModelName.ToLower()}: {{
        name: '{ModuleName.ToLower()}',
        path: '/{ModelName.ToLower()}',
        component: () => import('./{ModelName.ToLower()}').then(x => x.default) 
    }}
/**WTM**/
 ");
                    File.WriteAllText($"{MainDir}\\ClientApp\\src\\pages\\index.ts", index, Encoding.UTF8);
                }

                var menu = File.ReadAllText($"{MainDir}\\ClientApp\\src\\subMenu.json");
                if (menu.Contains($@"""Path"": ""/{ModelName.ToLower()}""") == false)
                {
                    var i = menu.LastIndexOf("}");
                    menu = menu.Insert(i + 1, $@"
,{{
        ""Key"": ""{Guid.NewGuid().ToString()}"",
        ""Name"": ""{ModuleName.ToLower()}"",
        ""Icon"": ""menu-fold"",
        ""Path"": ""/{ModelName.ToLower()}"",
        ""Component"": ""{ModelName.ToLower()}"",
        ""Action"": [],
        ""Children"": []
    }}
");
                    File.WriteAllText($"{MainDir}\\ClientApp\\src\\subMenu.json", menu, Encoding.UTF8);
                }
            }
        }