.NET MAUI HTML Circles

Kalyan A 360 Reputation points
2025-02-21T19:05:31.2066667+00:00

Here is the code to create Venn Diagrams,

I want A-B in B-A A ∩ B IN Intersecting circles.

A-B 1,2 in purple

B-A 5 in brown

A ∩ B muddy in 3,4

The intersecting circles can be enlarged

@page "/Venn"
<PageTitle>Set Theory</PageTitle>
<div style="display: flex; justify-content: space-around; margin-bottom: 20px;">
    <!-- Circle A -->
    <div style="position: relative; width: 250px; height: 250px; background-color: yellow; border-radius: 100%; opacity: 0.5;">
        <ul>
            @foreach (var todo in todos)
            {
                <li>
                    @if (todo.IsEditing)
                    {
                        <input @bind="todo.Title" />
                        <button disabled=@isdisabled @onclick="() => UpdateItem(todo)">Update</button>
                        <button disabled=@isdisabled @onclick="() => CancelEdit(todo)">Cancel</button>
                    }
                    else
                    {
                        <span>@todo.Title</span>
                        <button disabled=@isdisabled @onclick="() => EditItem(todo)">Edit</button>
                        <button disabled=@isdisabled @onclick="() => DeleteItem(todo)">Delete</button>
                    }
                </li>
            }
        </ul>
        <br>
        <input placeholder="Add a Number" @bind="newTodo" />
        <button disabled=@isdisabled @onclick="AddTodo">Add Set A</button> <br>
    </div>
    <!-- Circle B -->
    <div style="position: relative; width: 250px; height: 250px; background-color: springgreen; border-radius: 100%; opacity: 0.5;">
        <br />
        <ul>
            @foreach (var todob in todosb)
            {
                <li>
                    @if (todob.IsEditing)
                    {
                        <input @bind="todob.Title" />
                        <button disabled=@isdisabled @onclick="() => UpdateItemb(todob)">Update</button>
                        <button disabled=@isdisabled @onclick="() => CancelEditb(todob)">Cancel</button>
                    }
                    else
                    {
                        <span>@todob.Title</span>
                        <button disabled=@isdisabled @onclick="() => EditItemb(todob)">Edit</button>
                        <button disabled=@isdisabled @onclick="() => DeleteItemb(todob)">Delete</button>
                    }
                </li>
            }
        </ul>
        <br>
        <input placeholder="Add a Number Set B" @bind="newTodob" />
        <button disabled=@isdisabled @onclick="AddTodoB">Add Set B</button> <br>
        <br>
    </div>
</div>
<button @onclick="CalculateSets">Calculate</button>
<div style="position: relative; width: 300px; height: 200px; margin-top: 20px;">
    <!-- Circle A-B -->
    <div style="position: absolute; width: 200px; height: 200px; background-color: blue; opacity: 0.5;border-radius: 100%;  left: 50px; top: 25px;"></div>
    <!-- Circle B-A -->
    <div style="position: absolute; width: 200px; height: 200px; background-color:brown;opacity: 0.5; border-radius: 100%;   left: 125px; top: 25px;"></div>
</div>
<br />
<div  >
    <h4 style="color: blue; opacity: 0.5;">A - B</h4>
    <ul>
        @foreach (var item in aminusblist)
        {
            <li>@item.Title</li>
        }
    </ul>
</div>
<div >
    <h4 style="color:brown ;opacity: 0.5;">B - A</h4>
    <ul>
        @foreach (var item in bminusalist)
        {
            <li>@item.Title</li>
        }
    </ul>
</div>
<div>
    <h4 style="color:brown ; color:#52157D; opacity: 0.5;"> A ∩ B</h4>
    <ul>
        @foreach (var item in interlist)
        {
            <li>@item.Title</li>
        }
    </ul>
</div>
<div>
    <h4 style="    opacity: 0.5;"> A∪B</h4>
    <ul>
        @foreach (var item in unionlist)
        {
            <li>@item.Title</li>
        }
    </ul>
</div>
<br>
<button @onclick="DeleteAll">Clear All Set A </button> <br>
<button @onclick="DeleteAllB">Clear All Set B</button> <br>
<br>
<div>
    <p style="color: red;">
        @errmsg
    </p>
</div>
@code {
    private int errcount=0;
    public class TodoItem
    {
        public double Title { get; set; }
        public bool IsDone { get; set; }
        public double OrigNum { get; set; } // Add a property to store the original description
        public bool IsEditing { get; set; }
    }
    int rancnt; private string skip;
    private List<TodoItem> todos = new();
    private List<TodoItem> listsort = new();
    private List<TodoItemB> todosb = new();
    private List<TodoItemB> listsortb = new();
    private bool isdisabled = false; private double newTodo;
    public class TodoItemB
    {
        public double Title { get; set; }
        public bool IsDone { get; set; }
        public double OrigNum { get; set; } // Add a property to store the original description
        public bool IsEditing { get; set; }
    }
    public class Groups
    {
        public double Title { get; set; }
    }
    public class GroupsA
    {
        public double Title { get; set; }
    }
    public class GroupsB
    {
        public double Title { get; set; }
    }
    public class UnionList
    {
        public double Title { get; set; }
    }
    public class CommonList
    {
        public double Title { get; set; }
    }
    public class AminusBList
    {
        public double Title { get; set; }
    }
    public class Summary
    {
        public double Title { get; set; }
        public int cnts { get; set; }
    }
    private string setA;
    private string setB;
    private List<int> aMinusB = new();
    private List<int> bMinusA = new();
    private List<int> intersection = new();
    private double newTodob; int rancnta; int rancntb; int meansum; int maxnum; int minnum; int val1; int val2; int val0;
    private string errmsg; private string skipa; private string skipb; private int max; private int ran; private decimal calcmean; private decimal calcmedian; int median = 0; private int[] myNum = { 0 };
    private List<Groups> modegroups = new(); private List<Groups> groupsa = new(); private List<Groups> groupsb = new(); private List<CommonList> unionlist = new(); private List<CommonList> aminusblist = new(); private List<CommonList> bminusalist = new(); 
    private List<CommonList> interlist = new();
    private List<Groups> tempgroups = new(); private string display = "N"; private double[] medarr; private double[] groupaarr; private double[] groupbarr; private double[] commonarr; private double[] aminusb = { 0 };
    private List<Summary> sumgroups = new(); private string displayaminusb; private string onsubmit; private int scale1; private int scale2; int unioncount; int bminusacount; int aminuscount; int inscount;
    private void AddTodo()
    {
        errcount = 0;
        display = "N"; onsubmit = "N";
        myNum[0] = 0; maxnum = 0; minnum = 0; val0 = 0; val1 = 0; val2 = 0;
        aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
        ran = 0;
        rancnta = 0; rancntb = 0; meansum = 0; calcmean = 0; calcmedian = 0;
        errmsg = "";
        skipa = "N";
        errmsg = "";
        var resultx = todos.FirstOrDefault(c => c.Title == newTodo);
        if (resultx == null)
        { skipa = "N"; }
        else { errcount++; errmsg = "Cannot Allow duplicates"; }
        if (!IsWholeNumber(Convert.ToDouble(newTodo)))
        {
            string innum0 = newTodo.ToString();
            scale1 = innum0.Length - innum0.IndexOf('.') - 1;
        }
        if (scale1 > 2)
        {
            errcount++;
            errmsg = "Enter number with two decimals";
        }
        if ((newTodo < 0) || (newTodo > 100))
        {
            errcount++;
            errmsg = "Enter number between 0 and 100";
        }
        int cnt = todos.Count();
        if (cnt > 10)
        {
            errcount++;
            errmsg = "Cannot enter number more than 10 numbers";
        }
        if (errcount==0)
        {
            todos.Add(new TodoItem { Title = newTodo });
        }
        newTodo = 0;
        listsort = todos.OrderBy(p => p.Title).ToList();
        groupsa = listsort.Select(g => new Groups { Title = g.Title }).ToList();
    }
    private void UpdateItem(TodoItem task)
    {
        display = "N";
        skip = "N";
        errmsg = "";
        if ((task.Title < 0) || (task.Title > 100))
        {
            skip = "Y";
            errmsg = "Enter number between 0 and 100";
        }
        if (skip == "N")
        {
            task.IsEditing = false;
            myNum[0] = 0; maxnum = 0; minnum = 0; val0 = 0; val1 = 0; val2 = 0;
            sumgroups.Clear();
            ran = 0;
            rancnt = 0; meansum = 0; calcmean = 0; calcmedian = 0;
            errmsg = "";
        }
        else
        {
            task.IsEditing = true;
            task.Title = task.OrigNum; // Revert to the original number
        }
    }
    private void DeleteItem(TodoItem numx)
    {
        rancnta = 0; rancntb = 0; inscount = 0; unioncount = 0; aminuscount = 0; bminusacount = 0;
        display = "N";
        ran = 0; maxnum = 0; minnum = 0;
        rancnt = 0; meansum = 0; calcmean = 0; calcmedian = 0; val0 = 0; val1 = 0; val2 = 0;
        todos.Remove(numx);
        listsort = todos.OrderBy(p => p.Title).ToList();
        listsort = todos.OrderBy(p => p.Title).ToList();
        groupsa = listsort.Select(g => new Groups { Title = g.Title }).ToList();
        aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
    }
    private void CancelEdit(TodoItem task)
    {
        errmsg = "";
        task.IsEditing = false;
        task.Title = task.OrigNum; // Revert to the original number
    }
    private void EditItem(TodoItem task)
    {
        task.IsEditing = true;
        task.OrigNum = task.Title; // Revert to the original number
    }
    //
    //
    private void UpdateItemb(TodoItemB task)
    {
        display = "N";
        skip = "N";
        errmsg = "";
        if ((task.Title < 0) || (task.Title > 100))
        {
            skip = "Y";
            errmsg = "Enter number between 0 and 100";
        }
        if (skip == "N")
        {
            task.IsEditing = false;
            myNum[0] = 0; maxnum = 0; minnum = 0; val0 = 0; val1 = 0; val2 = 0;
            sumgroups.Clear();
            ran = 0;
            rancnt = 0; meansum = 0; calcmean = 0; calcmedian = 0;
            errmsg = "";
        }
        else
        {
            task.IsEditing = true;
            task.Title = task.OrigNum; // Revert to the original number
        }
    }
    private void AddTodoB()
    {
        display = "N"; onsubmit = "N";
        myNum[0] = 0; maxnum = 0; minnum = 0; val0 = 0; val1 = 0; val2 = 0;
        aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
        ran = 0;
        rancnta = 0; rancntb = 0; meansum = 0; calcmean = 0; calcmedian = 0;
        errmsg = "";
        skipb = "N";
        errmsg = "";
        var resultx = todosb.FirstOrDefault(c => c.Title == newTodob);
        if (!IsWholeNumber(Convert.ToDouble(newTodob)))
        {
            string innum1 = newTodob.ToString();
            scale1 = innum1.Length - innum1.IndexOf('.') - 1;
        }
        if (scale2 > 2)
        {
            skipa = "Y";
            errmsg = "Enter number with two decimals";
        }
        if (resultx == null)
        { skipb = "N"; }
        else { skipb = "Y"; errmsg = "Cannot Allow duplicates"; }
        if ((newTodob < 0) || (newTodob > 100))
        {
            skipb = "Y";
            errmsg = "Enter number between 0 and 100";
        }
        int cntb = todosb.Count();
        if (cntb > 10)
        {
            skipb = "Y";
            errmsg = "Cannot enter number more than 10 numbers";
        }
        if (skipb == "N")
        {
            todosb.Add(new TodoItemB { Title = newTodob });
        }
        newTodob = 0;
        listsortb = todosb.OrderBy(p => p.Title).ToList();
        groupsb = listsortb.Select(g => new Groups { Title = g.Title }).ToList();
    }
    private void CancelEditb(TodoItemB task)
    {
        errmsg = "";
        task.IsEditing = false;
        task.Title = task.OrigNum; // Revert to the original number
    }
    private void DeleteItemb(TodoItemB numx)
    {
        rancnta = 0; rancntb = 0; inscount = 0; unioncount = 0; aminuscount = 0; bminusacount = 0;
        display = "N";
        ran = 0; maxnum = 0; minnum = 0;
        rancnt = 0; meansum = 0; calcmean = 0; calcmedian = 0; val0 = 0; val1 = 0; val2 = 0;
        todosb.Remove(numx);
        listsortb = todosb.OrderBy(p => p.Title).ToList();
        groupsb = listsortb.Select(g => new Groups { Title = g.Title }).ToList();
        aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
    }
    private void EditItemb(TodoItemB task)
    {
        task.IsEditing = true;
        task.OrigNum = task.Title; // Revert to the original number
    }
    //
    static bool IsWholeNumber(double value)
    {
        return value == Math.Floor(value);
    }
    private void DeleteAllB()
    {
        rancnta = 0; rancntb = 0; inscount = 0; unioncount = 0; aminuscount = 0; bminusacount = 0;
        onsubmit = "N";
        int rem = todosb.Count();
        errmsg = "";
        if (rem > 0)
        {
            aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
            todosb.Clear();
            listsortb.Clear();
        }
        else
        { errmsg = "No records to Delete"; }
        isdisabled = false;
    }
    private void DeleteAll()
    {
        rancnta = 0; rancntb = 0; inscount = 0; unioncount = 0; aminuscount = 0; bminusacount = 0;
        onsubmit = "N";
        int rem = todos.Count();
        if (rem > 0)
        {
            todos.Clear();
            listsort.Clear(); aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
        }
        else
        { errmsg = "No records to Delete"; }
        isdisabled = false;
    }
    private void CalculateSets()
    {
      //  var setAList = todos;
      ///  var setBList = todosb;
isdisabled=true;
        onsubmit = "Y"; aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
        errmsg = "";
        rancnta = todos.Count();
        rancntb = todosb.Count();
        var tempgroupsa = groupsa.Select(n => n.Title).ToList();
        groupaarr = tempgroupsa.ToArray();
        var tempgroupsb = groupsb.Select(n => n.Title).ToList();
        groupbarr = tempgroupsb.ToArray();
        var n = groupaarr.Length;
        var m = groupbarr.Length;
        //A-B
        for (int i = 0; i < groupaarr.Length; i++)
        {
            var resulty = groupsb.FirstOrDefault(c => c.Title == groupaarr[i]);
            if (resulty == null)
            {
                displayaminusb = "Y";
                aminusblist.Add(new CommonList { Title = groupaarr[i] });
            }
        }
        aminuscount = aminusblist.Count();
        if (aminuscount == 0)
        { errmsg = "Empty Result "; }
        if (n == 0)
        { errmsg = "Empty Set A "; }
        //B-A
        for (int i = 0; i < groupbarr.Length; i++)
        {
            var resultz = groupsa.FirstOrDefault(c => c.Title == groupbarr[i]);
            if (resultz == null)
            {
                displayaminusb = "Y";
                bminusalist.Add(new CommonList { Title = groupbarr[i] });
            }
        }
        bminusacount = bminusalist.Count();
        // A Union B
        for (int i = 0; i < groupaarr.Length; i++)
        {
            unionlist.Add(new CommonList { Title = groupaarr[i] });
        }
        for (int i = 0; i < groupbarr.Length; i++)
        {
            var resultx = unionlist.FirstOrDefault(c => c.Title == groupbarr[i]);
            if (resultx == null)
            {
                unionlist.Add(new CommonList { Title = groupbarr[i] });
            }
        }
        unionlist = unionlist.OrderBy(p => p.Title).ToList();
        unioncount = unionlist.Count();
        // A Intersection B
        for (int i = 0; i < groupaarr.Length; i++)
        {
            var resultn = groupsb.FirstOrDefault(c => c.Title == groupaarr[i]);
            if (resultn != null)
            {
                interlist.Add(new CommonList { Title = groupaarr[i] });
            }
        }
        inscount = interlist.Count();
    }
}
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,942 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Kalyan A 360 Reputation points
    2025-02-22T13:49:19.25+00:00

    It works I used github copilot for suggestions

     
    @page "/DataNav/Venn"
    <PageTitle>Set Theory</PageTitle>
    <div style="display: flex; justify-content: space-around; margin-bottom: 20px;">
        <!-- Circle A -->
        <div style="position: relative; width: 250px; height: 250px; background-color: paleturquoise; border-radius: 100%; opacity: 0.5;">
             <span style="position: absolute; top: 50%; left: 5%; transform: translate(-50%, -50%); color: black;">
                
            <ul>
                @foreach (var todo in todos)
                {
                        <li>
                        @if (todo.IsEditing)
                        {
                                    <input @bind="todo.Title" />
                                    <button disabled=@isdisabled @onclick="() => UpdateItem(todo)">Update</button>
                                    <button disabled=@isdisabled @onclick="() => CancelEdit(todo)">Cancel</button>
                        }
                        else
                        {
                                    <span>@todo.Title</span>
                                    <button disabled=@isdisabled @onclick="() => EditItem(todo)">Edit</button>
                                    <button disabled=@isdisabled @onclick="() => DeleteItem(todo)">Delete</button>
                        }
                        </li>
                }
            </ul>
            </span>
            <br>
              <span style="position: absolute; top: 50%; left: 70%; transform: translate(-50%, -50%); color: black;">
                <h4>Set A</h4>
                  <ul>
                @foreach (var todo in todos)
                {
                     <li>
               @todo.Title 
                    </li>
                   }
                         </ul>
                  </span>
            <br>
             <span style="position: absolute; top: 90%; left: 100%; transform: translate(-50%, -50%); color: black;">
            <input placeholder="Add a Number" @bind="newTodo" />
            <button disabled=@isdisabled @onclick="AddTodo">Add Set A</button> <br>
            </span>
        </div>
        <!-- Circle B -->
        <div style="position: relative; width: 250px; height: 250px; background-color:lightgreen; border-radius: 100%; opacity: 0.5;">
           
            
             <span style="position: absolute; top: 50%; left: 5%; transform: translate(-50%, -50%); color: black;">
            
            <ul>
                @foreach (var todob in todosb)
                {
                        <li>
                        @if (todob.IsEditing)
                        {
                                    <input @bind="todob.Title" />
                                    <button disabled=@isdisabled @onclick="() => UpdateItemb(todob)">Update</button>
                                    <button disabled=@isdisabled @onclick="() => CancelEditb(todob)">Cancel</button>
                        }
                        else
                        {
                                    <span>@todob.Title</span>
                                    <button disabled=@isdisabled @onclick="() => EditItemb(todob)">Edit</button>
                                    <button disabled=@isdisabled @onclick="() => DeleteItemb(todob)">Delete</button>
                        }
                        </li>
                }
            </ul>
           
            
            
            </span>
            <span style="position: absolute; top: 50%; left: 70%; transform: translate(-50%, -50%); color: black;">
                <h4>Set B</h4>
                <ul>
                    @foreach (var todob in todosb)
                    {
                        <li>
                            @todob.Title
                            </li>
                    }
                </ul>
            </span>
            
            <br>
             <span style="position: absolute; top: 90%; left: 100%; transform: translate(-50%, -50%); color: black;">
            <input placeholder="Add a Number Set B" @bind="newTodob" />
            <button disabled=@isdisabled @onclick="AddTodoB">Add Set B</button> <br>
            </span>
            <br>
        </div>
    </div>
    <button @onclick="CalculateSets">Calculate</button>
    <div style="position: relative; width: 300px; height: 200px; margin-top: 20px;">
        <!-- Circle A-B -->
        <div style="position: absolute; width: 200px; height: 300px; background-color: paleturquoise; opacity: 0.5; border-radius: 150%; left: 50px; top: 25px;">
            <span style="position: absolute; top: 50%; left: 20%; transform: translate(-50%, -50%); color: black;">
                A - B
                
            <span>
                 <ul>
                        @foreach (var item in aminusblist)
                        {
                        <li>@item.Title</li>
                        }
               </ul>
            </span>
            
            </span>
        </div>
        <!-- Circle B-A -->
        <div style="position: absolute; width: 200px; height: 300px; background-color:lightgreen; opacity: 0.5; border-radius: 150%; left: 125px; top: 25px;">
          
               <span style="position: absolute; top: 40%; left: 35%; transform: translate(-50%, -50%); color: black;">
               A ∩ B
                <span>
                      <ul>
                        @foreach (var item in interlist)
                        {
                        <li>@item.Title</li>
                        }
               </ul>
                </span>
            </span>
            
            
            
            
            <span style="position: absolute; top: 50%; left: 80%; transform: translate(-50%, -50%); color: black;">
                        
                B - A
            
                <span>
                     <ul>
                        @foreach (var item in bminusalist)
                        {
                        <li>@item.Title</li>
                        }
                  </ul>
                </span>
            </span>
        </div>
    </div>
    <br />
     
    <div>
        <h4 style="opacity: 0.5;">A ∪ B</h4>
        <ul>
            @foreach (var item in unionlist)
            {
                    <li>@item.Title</li>
            }
        </ul>
    </div>
    <br>
    <button @onclick="DeleteAll">Clear All Set A</button> <br>
    <button @onclick="DeleteAllB">Clear All Set B</button> <br>
    <br>
    <div>
        <p style="color: red;">
            @errmsg
        </p>
    </div>
    @code {
        private int errcount=0;
        public class TodoItem
        {
            public double Title { get; set; }
            public bool IsDone { get; set; }
            public double OrigNum { get; set; } // Add a property to store the original description
            public bool IsEditing { get; set; }
        }
        int rancnt; private string skip;
        private List<TodoItem> todos = new();
        private List<TodoItem> listsort = new();
        private List<TodoItemB> todosb = new();
        private List<TodoItemB> listsortb = new();
        private bool isdisabled = false; private double newTodo;
        public class TodoItemB
        {
            public double Title { get; set; }
            public bool IsDone { get; set; }
            public double OrigNum { get; set; } // Add a property to store the original description
            public bool IsEditing { get; set; }
        }
        public class Groups
        {
            public double Title { get; set; }
        }
        public class GroupsA
        {
            public double Title { get; set; }
        }
        public class GroupsB
        {
            public double Title { get; set; }
        }
        public class UnionList
        {
            public double Title { get; set; }
        }
        public class CommonList
        {
            public double Title { get; set; }
        }
        public class AminusBList
        {
            public double Title { get; set; }
        }
        public class Summary
        {
            public double Title { get; set; }
            public int cnts { get; set; }
        }
        private string setA;
        private string setB;
        private List<int> aMinusB = new();
        private List<int> bMinusA = new();
        private List<int> intersection = new();
        private double newTodob; int rancnta; int rancntb; int meansum; int maxnum; int minnum; int val1; int val2; int val0;
        private string errmsg; private string skipa; private string skipb; private int max; private int ran; private decimal calcmean; private decimal calcmedian; int median = 0; private int[] myNum = { 0 };
        private List<Groups> modegroups = new(); private List<Groups> groupsa = new(); private List<Groups> groupsb = new(); private List<CommonList> unionlist = new(); private List<CommonList> aminusblist = new(); private List<CommonList> bminusalist = new(); 
        private List<CommonList> interlist = new();
        private List<Groups> tempgroups = new(); private string display = "N"; private double[] medarr; private double[] groupaarr; private double[] groupbarr; private double[] commonarr; private double[] aminusb = { 0 };
        private List<Summary> sumgroups = new(); private string displayaminusb; private string onsubmit; private int scale1; private int scale2; int unioncount; int bminusacount; int aminuscount; int inscount;
        private void AddTodo()
        {
            errcount = 0;
            display = "N"; onsubmit = "N";
            myNum[0] = 0; maxnum = 0; minnum = 0; val0 = 0; val1 = 0; val2 = 0;
            aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
            ran = 0;
            rancnta = 0; rancntb = 0; meansum = 0; calcmean = 0; calcmedian = 0;
            errmsg = "";
            skipa = "N";
            errmsg = "";
            var resultx = todos.FirstOrDefault(c => c.Title == newTodo);
            if (resultx == null)
            { skipa = "N"; }
            else { errcount++; errmsg = "Cannot Allow duplicates"; }
            if (!IsWholeNumber(Convert.ToDouble(newTodo)))
            {
                string innum0 = newTodo.ToString();
                scale1 = innum0.Length - innum0.IndexOf('.') - 1;
            }
            if (scale1 > 2)
            {
                errcount++;
                errmsg = "Enter number with two decimals";
            }
            if ((newTodo < 0) || (newTodo > 100))
            {
                errcount++;
                errmsg = "Enter number between 0 and 100";
            }
            int cnt = todos.Count();
            if (cnt > 9)
            {
                errcount++;
                errmsg = "Cannot enter number more than 10 numbers";
            }
            if (errcount==0)
            {
                todos.Add(new TodoItem { Title = newTodo });
            }
            newTodo = 0;
            listsort = todos.OrderBy(p => p.Title).ToList();
            groupsa = listsort.Select(g => new Groups { Title = g.Title }).ToList();
        }
        private void UpdateItem(TodoItem task)
        {
            display = "N";
            skip = "N";
            errmsg = "";
            if ((task.Title < 0) || (task.Title > 100))
            {
                skip = "Y";
                errmsg = "Enter number between 0 and 100";
            }
            if (skip == "N")
            {
                task.IsEditing = false;
                myNum[0] = 0; maxnum = 0; minnum = 0; val0 = 0; val1 = 0; val2 = 0;
                sumgroups.Clear();
                ran = 0;
                rancnt = 0; meansum = 0; calcmean = 0; calcmedian = 0;
                errmsg = "";
            }
            else
            {
                task.IsEditing = true;
                task.Title = task.OrigNum; // Revert to the original number
            }
        }
        private void DeleteItem(TodoItem numx)
        {
            rancnta = 0; rancntb = 0; inscount = 0; unioncount = 0; aminuscount = 0; bminusacount = 0;
            display = "N";
            ran = 0; maxnum = 0; minnum = 0;
            rancnt = 0; meansum = 0; calcmean = 0; calcmedian = 0; val0 = 0; val1 = 0; val2 = 0;
            todos.Remove(numx);
            listsort = todos.OrderBy(p => p.Title).ToList();
            listsort = todos.OrderBy(p => p.Title).ToList();
            groupsa = listsort.Select(g => new Groups { Title = g.Title }).ToList();
            aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
        }
        private void CancelEdit(TodoItem task)
        {
            errmsg = "";
            task.IsEditing = false;
            task.Title = task.OrigNum; // Revert to the original number
        }
        private void EditItem(TodoItem task)
        {
            task.IsEditing = true;
            task.OrigNum = task.Title; // Revert to the original number
        }
        //
        //
        private void UpdateItemb(TodoItemB task)
        {
            display = "N";
            skip = "N";
            errmsg = "";
            if ((task.Title < 0) || (task.Title > 100))
            {
                skip = "Y";
                errmsg = "Enter number between 0 and 100";
            }
            if (skip == "N")
            {
                task.IsEditing = false;
                myNum[0] = 0; maxnum = 0; minnum = 0; val0 = 0; val1 = 0; val2 = 0;
                sumgroups.Clear();
                ran = 0;
                rancnt = 0; meansum = 0; calcmean = 0; calcmedian = 0;
                errmsg = "";
            }
            else
            {
                task.IsEditing = true;
                task.Title = task.OrigNum; // Revert to the original number
            }
        }
        private void AddTodoB()
        {
            display = "N"; onsubmit = "N";
            myNum[0] = 0; maxnum = 0; minnum = 0; val0 = 0; val1 = 0; val2 = 0;
            aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
            ran = 0;
            rancnta = 0; rancntb = 0; meansum = 0; calcmean = 0; calcmedian = 0;
            errmsg = "";
            skipb = "N";
            errmsg = "";
            var resultx = todosb.FirstOrDefault(c => c.Title == newTodob);
            if (!IsWholeNumber(Convert.ToDouble(newTodob)))
            {
                string innum1 = newTodob.ToString();
                scale1 = innum1.Length - innum1.IndexOf('.') - 1;
            }
            if (scale2 > 2)
            {
                skipa = "Y";
                errmsg = "Enter number with two decimals";
            }
            if (resultx == null)
            { skipb = "N"; }
            else { skipb = "Y"; errmsg = "Cannot Allow duplicates"; }
            if ((newTodob < 0) || (newTodob > 100))
            {
                skipb = "Y";
                errmsg = "Enter number between 0 and 100";
            }
            int cntb = todosb.Count();
            if (cntb > 9)
            {
                skipb = "Y";
                errmsg = "Cannot enter number more than 10 numbers";
            }
            if (skipb == "N")
            {
                todosb.Add(new TodoItemB { Title = newTodob });
            }
            newTodob = 0;
            listsortb = todosb.OrderBy(p => p.Title).ToList();
            groupsb = listsortb.Select(g => new Groups { Title = g.Title }).ToList();
        }
        private void CancelEditb(TodoItemB task)
        {
            errmsg = "";
            task.IsEditing = false;
            task.Title = task.OrigNum; // Revert to the original number
        }
        private void DeleteItemb(TodoItemB numx)
        {
            rancnta = 0; rancntb = 0; inscount = 0; unioncount = 0; aminuscount = 0; bminusacount = 0;
            display = "N";
            ran = 0; maxnum = 0; minnum = 0;
            rancnt = 0; meansum = 0; calcmean = 0; calcmedian = 0; val0 = 0; val1 = 0; val2 = 0;
            todosb.Remove(numx);
            listsortb = todosb.OrderBy(p => p.Title).ToList();
            groupsb = listsortb.Select(g => new Groups { Title = g.Title }).ToList();
            aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
        }
        private void EditItemb(TodoItemB task)
        {
            task.IsEditing = true;
            task.OrigNum = task.Title; // Revert to the original number
        }
        //
        static bool IsWholeNumber(double value)
        {
            return value == Math.Floor(value);
        }
        private void DeleteAllB()
        {
            rancnta = 0; rancntb = 0; inscount = 0; unioncount = 0; aminuscount = 0; bminusacount = 0;
            onsubmit = "N";
            int rem = todosb.Count();
            errmsg = "";
            if (rem > 0)
            {
                aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
                todosb.Clear();
                listsortb.Clear();
            }
            else
            { errmsg = "No records to Delete"; }
            isdisabled = false;
        }
        private void DeleteAll()
        {
            rancnta = 0; rancntb = 0; inscount = 0; unioncount = 0; aminuscount = 0; bminusacount = 0;
            onsubmit = "N";
            int rem = todos.Count();
            if (rem > 0)
            {
                todos.Clear();
                listsort.Clear(); aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
            }
            else
            { errmsg = "No records to Delete"; }
            isdisabled = false;
        }
        private void CalculateSets()
        {
          //  var setAList = todos;
          ///  var setBList = todosb;
    isdisabled=true;
            onsubmit = "Y"; aminusblist.Clear(); bminusalist.Clear(); unionlist.Clear(); interlist.Clear();
            errmsg = "";
            rancnta = todos.Count();
            rancntb = todosb.Count();
            var tempgroupsa = groupsa.Select(n => n.Title).ToList();
            groupaarr = tempgroupsa.ToArray();
            var tempgroupsb = groupsb.Select(n => n.Title).ToList();
            groupbarr = tempgroupsb.ToArray();
            var n = groupaarr.Length;
            var m = groupbarr.Length;
            //A-B
            for (int i = 0; i < groupaarr.Length; i++)
            {
                var resulty = groupsb.FirstOrDefault(c => c.Title == groupaarr[i]);
                if (resulty == null)
                {
                    displayaminusb = "Y";
                    aminusblist.Add(new CommonList { Title = groupaarr[i] });
                }
            }
            aminuscount = aminusblist.Count();
            if (aminuscount == 0)
            { errmsg = "Empty Result "; }
            if (n == 0)
            { errmsg = "Empty Set A "; }
            //B-A
            for (int i = 0; i < groupbarr.Length; i++)
            {
                var resultz = groupsa.FirstOrDefault(c => c.Title == groupbarr[i]);
                if (resultz == null)
                {
                    displayaminusb = "Y";
                    bminusalist.Add(new CommonList { Title = groupbarr[i] });
                }
            }
            bminusacount = bminusalist.Count();
            // A Union B
            for (int i = 0; i < groupaarr.Length; i++)
            {
                unionlist.Add(new CommonList { Title = groupaarr[i] });
            }
            for (int i = 0; i < groupbarr.Length; i++)
            {
                var resultx = unionlist.FirstOrDefault(c => c.Title == groupbarr[i]);
                if (resultx == null)
                {
                    unionlist.Add(new CommonList { Title = groupbarr[i] });
                }
            }
            unionlist = unionlist.OrderBy(p => p.Title).ToList();
            unioncount = unionlist.Count();
            // A Intersection B
            for (int i = 0; i < groupaarr.Length; i++)
            {
                var resultn = groupsb.FirstOrDefault(c => c.Title == groupaarr[i]);
                if (resultn != null)
                {
                    interlist.Add(new CommonList { Title = groupaarr[i] });
                }
            }
            inscount = interlist.Count();
        }
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.