logo
down
shadow

Structure to XML C# WinForms


Structure to XML C# WinForms

By : Brian Yu
Date : October 22 2020, 08:10 AM
this one helps. I am using a structure to store and access all my input variables that I will take from user. I have to take 22 inputs from user and save it to file and again read from file and load in form. I want to save this structure into xml. Unfortunately I am unable to do that as I am new to c#. , Try following :
code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace ConsoleApplication91
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            RootCell rootCell = new RootCell() {
                cells = new List<Cell>() {
                    new Cell() { cellName = "123"},
                    new Cell() { cellName = "456"}
                }
            };

            rootCell.Serialize(FILENAME, rootCell);
            RootCell readCells = rootCell.Deserialize(FILENAME);



        }
    }
    public class RootCell
    {
        [XmlElement("cells")]
        public List<Cell> cells { get; set; }

        public void Serialize(string filename, RootCell cells)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            XmlWriter writer = XmlWriter.Create(filename, settings);
            XmlSerializer serializer = new XmlSerializer(typeof(RootCell));

            serializer.Serialize(writer, cells);
            writer.Flush();
            writer.Close();
        }
        public  RootCell Deserialize(string filename)
        {
            XmlReader reader = XmlReader.Create(filename);
            XmlSerializer serializer = new XmlSerializer(typeof(RootCell));
            return (RootCell)serializer.Deserialize(reader);
        }


    }
    public class Cell
    {
        public string cellName { get; set; }
        public double cellAh { get; set; }
        public double cellNominalVoltage { get; set; }
        public double cellInternalResistance { get; set; }

        public double cylDeg05C25D { get; set; }
        public double cylDeg10C25D { get; set; }
        public double cylDeg20C25D { get; set; }
        public double cylDeg05C35D { get; set; }
        public double cylDeg10C35D { get; set; }
        public double cylDeg20C35D { get; set; }
        public double cylDeg05C45D { get; set; }
        public double cylDeg10C45D { get; set; }
        public double cylDeg20C45D { get; set; }

        public double calDeg1stY25D { get; set; }
        public double calDeg2ndY25D { get; set; }
        public double calDeg3rdY25D { get; set; }
        public double calDeg1stY35D { get; set; }
        public double calDeg2ndY35D { get; set; }
        public double calDeg3rdY35D { get; set; }
        public double calDeg1stY45D { get; set; }
        public double calDeg2ndY45D { get; set; }
        public double calDeg3rdY45D { get; set; }


    }
}


Share : facebook icon twitter icon
Winforms - best directory / project structure

Winforms - best directory / project structure


By : THomasW
Date : March 29 2020, 07:55 AM
I wish this helpful for you For me it depends on the model I'm following. If I'm using MVC it would be
code :
Project
-Models
-Controllers
-Views
Project
-Models
-Presenters
-Views
Project
-Models
--Inventory
-Controllers
--Inventory
---TransactionsController.cs
-Views
--Inventory
---Transactions
----EditTransactionsView.dfm
How to structure C++ Windows API programs like C# WinForms

How to structure C++ Windows API programs like C# WinForms


By : user3662522
Date : March 29 2020, 07:55 AM
To fix the issue you can do I have used my own Window class similar to what's shown below. This is a reply I poseted for a different question but you might find this useful. So here it is:
code :
#pragma once

#include <windows.h>
#include <process.h>
#include <iostream>

using namespace std;

static const char *g_AppName  = "Test";

class CMyWindow
{
    HWND  _hWnd;
    int _width;
    int _height;
public:
    CMyWindow(const int width,const int height):_hWnd(NULL),_width(width),_height(height)
    {
        _beginthread( &CMyWindow::thread_entry, 0, this);
    }

    ~CMyWindow(void)
    {
        SendMessage(_hWnd, WM_CLOSE, NULL, NULL);
    }


private:
    static void thread_entry(void * p_userdata)
    {
        CMyWindow * p_win = static_cast<CMyWindow*> (p_userdata);
        p_win->create_window();
        p_win->message_loop();
    }

    void create_window()
    {
        WNDCLASSEX wcex;

        wcex.cbSize         = sizeof(WNDCLASSEX);
        wcex.style          = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc    = &CMyWindow::WindowProc;
        wcex.cbClsExtra     = 0;
        wcex.cbWndExtra     = 0;
        wcex.hInstance      = GetModuleHandle(NULL);
        wcex.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
        wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
        wcex.lpszMenuName   = NULL;
        wcex.lpszClassName  = g_AppName;
        wcex.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

        RegisterClassEx(&wcex);

        _hWnd = CreateWindow(g_AppName, g_AppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, GetModuleHandle(NULL), NULL);

        ShowWindow(_hWnd, SW_SHOWDEFAULT);
        UpdateWindow(_hWnd);
    }

    void message_loop()
    {
        MSG msg = {0};

        while (GetMessage(&msg, NULL, 0, 0))
        {
            if(msg.message == WM_QUIT)
            {
                break;
            }

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    static LRESULT WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch(uMsg)
        {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        case WM_POWERBROADCAST:
            {
                //power management code here
            }

        }

        return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
};
How to structure a project in Winforms using MVP pattern?

How to structure a project in Winforms using MVP pattern?


By : Mohannad_firon
Date : March 29 2020, 07:55 AM
wish of those help Honestly, this is a very subjective question. The way I am doing this today may not be the way I do this for the next application. It simply works out well for me. Also, what works for me may not be the way anyone else would do it - not that mine is wrong, better, or worse.
Naming conventions will help:
EF Code Structure in WinForms

EF Code Structure in WinForms


By : asdf
Date : March 29 2020, 07:55 AM
This might help you If you are using C#6 you could use ?. null conditional operator to check if ComboBox.SelectedValue is null before you use .ToString():
code :
var memberRecord = new ClubMember()
{// Tab ID
    Name = txtName.Text,
    Surname = txtSurname.Text,
    PassportNumber = (Int32)txtPasspt.text,
    MaritalStatus = cboMarital.SelectedValue?.ToString(),
    Gender = cboGender.SelectedValue?.ToString(),
    DOB = dtpDob.Value,
    DataEntrada = dtpDataEntra.Value,
    Photo = ConvertImgToBinary(picBoxPhoto.Image),
    Country = cboCountry.SelectedValue?.ToString(),
};
var memberRecord = new ClubMember()
{// Tab ID
    Name = txtName.Text,
    Surname = txtSurname.Text,
    PassportNumber = (Int32)txtPasspt.text,
    MaritalStatus = cboMarital.SelectedValue == null ? null : cboMarital.SelectedValue.ToString(),
    Gender = cboGender.SelectedValue == null ? null : cboGender.SelectedValue.ToString(),
    DOB = dtpDob.Value,
    DataEntrada = dtpDataEntra.Value,
    Photo = ConvertImgToBinary(picBoxPhoto.Image),
    Country = cboCountry.SelectedValue == null ? null : cboCountry.SelectedValue.ToString(),
};
c# winforms - Display tree structure as tab formatted text

c# winforms - Display tree structure as tab formatted text


By : Anil
Date : March 29 2020, 07:55 AM
help you fix your problem The assumption you make on this line is incorrect: It only indents the first child node.
code :
retText += "\t" + ExportTreeNode(node.Nodes);
public static string ExportTreeNode(TreeNodeCollection treeNodes, string indent = "")
retText += node.Text + "\n";

// Recursively check the children of each node in the nodes collection.
retText += "\t" + ExportTreeNode(node.Nodes);
retText += indent + node.Text + "\n";

// Recursively check the children of each node in the nodes collection.
retText += ExportTreeNode(node.Nodes, indent + "\t");
Related Posts Related Posts :
  • How do request a correct access token in ASP.NET Core for Azure AD to access Microsoft Graph
  • How to run a .NET Core console application on Linux
  • UI not updating for bound element
  • C# Odata v4 open type raw values
  • DocumentFormat.OpenXml Modify Creator Propery of Document
  • How to SetBasePath in ConfigurationBuilder in Core 2.0
  • ASP MVC5 public readonly variable changes value when it should not
  • How to conditionally select item from hashset with queryable linq?
  • Progress Bar C# not showing the real progress
  • Correct logic to reconnect in SignalR with HubConnection
  • ComboBox with two or more sections
  • .NET listbox to SQLite DB
  • C# Ninject binding from Dictionary<Type, Type>
  • asp.net mvc -view displaying real-time progress status
  • Getting reference to dependent in service with generic type
  • Implementing EqualityCompare vs overriding GetHashCode and Equals
  • C# Linq Find all indexes of item in List<int> within another List<int>
  • XML image how to display at data grid columns in c#.net
  • How to override Equals and GetHash of HashSet
  • Creating Windows authentication and SQL Server authentication in login form
  • How to interop with Azure Service Bus topics created by MassTransit using Rebus?
  • MVC 5 Google Calendar Integration
  • C# - Use parallel arrays to calculate cost of a phone call in GUI
  • Use a int in entire code
  • How to display newly added element at the top of StackPanel in WPF?
  • T4MVC is generating T4MVC.cs and T4MVC1.cs
  • Remove blur effect on certain controls inside UserControl
  • Sql Transcation Query to Linq Query in Wcf Rest Service
  • Setting AWS S3 credentials in C# app
  • does not contain in an ObservableCollection
  • App doesn't run it crashed directly after I started it
  • Is it possible in Entity Framework MVC application to run .sql scripts on a different database
  • Type Inference with Deconstruct tuple assignment extension methods
  • Setting up mock objects for EF dbcontext to test repository methods
  • Using C# in XSLT with MSXSL 6.0
  • Absolute positioning of UIElement in FlowDocument in WPF
  • Display debuggers not showing up in Visual Studio 2017
  • Discord.NET Users playing the same game
  • Azure function output API call to 3rd party service
  • Unable to determine the relationship represented by navigation property ASP.NET core 2.0 Entity Framework
  • Regex to find group of Regex inside a word
  • When calling a method, when to reference the class, and when to reference the object?
  • AmazonCloudWatchLogsClient async methods failing with no error
  • Create FileStream in memory instead of saving a physical file on disk
  • ViewBag data coming from ActionFilter is persisting in session even after database
  • ERROR: the name 'lvSubCategories' does not exist in the current context
  • Why datetime can't recognise the string?
  • Getting 500 error while requesting to webservice using Ajax AutoCompleteExtender
  • The property 'x' is not a navigation property of entity type 'y'
  • ASP.NET MVC - How to generate empty input boxes in loop when model is empty?
  • Need help writing regular expression
  • Add/remove buttons to a panel with an arraylist c#
  • Linq .Where(type = typeof(xxx)) comparison is always false
  • Using EF6 Code First without migrations to an existing db how do I specify column names of the many to many join table?
  • C# - Using Thread.Sleep precisely in a console application
  • Add item to a List<Tuple> inside another list
  • Double[,], inversion C#
  • Counting a string to ensure the input is within a min/max boundary
  • Assign invalidValue to Enum variable (why is this not throwing an Exception?)
  • Namespace or type specified in the project-level Imports 'System.Threading.Tasks' doesn't contain any public member or c
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org