Sunday 26 March 2023

06. aspnet mvc Create page with Entity Framework | Asp.Net MVC create re...


Asp.Net MVC CRUD 

Controller Code:  FreindController.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcTeach.Controllers
{
    public class FriendController : Controller
    {
        dbMbkTestEntities db = new dbMbkTestEntities();
        // GET: Friend
        public ActionResult Index()
        {
            var FrndList = (from a in db.tblFriends select a).ToList();
            return View(FrndList);
        }


        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(tblFriend frnd)
        {
            tblFriend newFrnd = new tblFriend();
            newFrnd.FriendName = frnd.FriendName;
            newFrnd.City = frnd.City;
            newFrnd.Mobile = frnd.Mobile;
            db.tblFriends.Add(frnd);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
    }
}



@model MvcTeach.tblFriend

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>


@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>tblFriend</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @*<div class="form-group">
            @Html.LabelFor(model => model.FriendID, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.FriendID, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.FriendID, "", new { @class = "text-danger" })
            </div>
        </div>*@

        <div class="form-group">
            @Html.LabelFor(model => model.FriendName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.FriendName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.FriendName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.City, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Mobile, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Mobile, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Mobile, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

05. aspnet mvc index page List entity framework | asp.net mvc list page ...



CONTROLLER CODE:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcTeach.Controllers
{
    public class FriendController : Controller
    {
        dbMbkTestEntities db = new dbMbkTestEntities();
        // GET: Friend
        public ActionResult Index()
        {
            var FrndList = (from a in db.tblFriends select a).ToList();
            return View(FrndList);
        }

    
    }
}



INDEX.CSHTML page code



@model IEnumerable<MvcTeach.tblFriend>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        @*<th>
            @Html.DisplayNameFor(model => model.FriendID)
        </th>*@
        <th>
            @Html.DisplayNameFor(model => model.FriendName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.City)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Mobile)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        @*<td>
            @Html.DisplayFor(modelItem => item.FriendID)
        </td>*@
        <td>
            @Html.DisplayFor(modelItem => item.FriendName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.City)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Mobile)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.FriendID }) |
            @Html.ActionLink("Details", "Details", new { id=item.FriendID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.FriendID })
        </td>
    </tr>
}

</table>






Saturday 18 March 2023

Create Graph vfp save in General field DBF table | Save graph in dbf | S...


Before starting first create table ABC.DBF

Name -  Character  -100
gGraph - General 



============================================

Code: Graph2.prg
SET DATE BRITISH
#DEFINE TAB CHR(9)
#DEFINE CRLF CHR(13)+CHR(10)
#DEFINE DOGS_LOC "Dogs"
#DEFINE CATS_LOC "Cats"


_cliptext = ""+TAB+CATS_LOC+TAB+DOGS_LOC+CRLF+"1994"+TAB+"11"+TAB+"22"+CRLF+"1995"+TAB+"33"+TAB+"44"+CRLF+"1996"+TAB+"55"+TAB+"55"+CRLF

use abc
APPEND blank
replace name WITH TTOC(DATETIME())
APPEND GENERAL gGraph CLASS "MSGraph.Chart" DATA _Cliptext

Saturday 11 March 2023

Create graph using graph wizard in visual foxpro | Visual foxpro graph using wizard



CREATE CURSOR grafthis (QuarterType c(6), SalesAmt n(5,2))
INSERT INTO grafthis VALUES ("Q1", 100.45)
INSERT INTO grafthis VALUES ("Q2", 160.90)
INSERT INTO grafthis VALUES ("Q3", 120.09)
INSERT INTO grafthis VALUES ("Q4", 250.65)
DO HOME(1)+"Wizards\WZGraph.App" 

Tuesday 7 March 2023

grid export to xlsx | Convert Visual Foxpro Grid to XLSX Excel | VFP 9 G...




LOCAL lCXlsxPath

lCXlsxPath = SYS(5)+ADDBS(SYS(2003))+"InvoSum.xlsx"

thisform.vfpxworkbookxlsx1.SaveGridToWorkbookEx(thisform.grid1,lcxlsxpath,.T.,"InvoSummary")

Friday 3 March 2023

zatca qr code C# AspNet | QR Code ZATCA AspNet WebForm | zatca qr gene...



Zatca.aspx  UI QR CodeFile Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="zatca.aspx.cs" Inherits="ManojKallaTutorial.zatca" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <asp:Image ID="imgQrCode" runat="server" />
            <br />
        <br />  
        <asp:Button ID="btnSubmit" runat="server" Text="Generate QR Code"  OnClick="btnSubmit_Click"/>
    </div>
    </form>
</body>
</html>






Zatca.aspx.cs  QR CodeFile Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ManojKallaTutorial
{
    public partial class zatca : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string SellerName = "Abudl Khalid Yeman";
            string TaxNo = "191786123125987";
            DateTime DtVal = DateTime.Now;
            Double TotalAmt = 100000;
            Double TaxAmt = 1000;
            string GenFile = GenerateQrCode(SellerName, TaxNo, DtVal, TotalAmt, TaxAmt);
            imgQrCode.ImageUrl = "http://localhost:50358/QR/"+GenFile;
       }

        public string GenerateQrCode(string SellerName, string TaxNo, DateTime DtTime,Double Total, Double Tax )
        {
            string FileName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + ".png";
            TLVCls tlv = new TLVCls(SellerName, TaxNo, DtTime, Total, Tax);
            System.Drawing.Image img =  tlv.toQrCode();
            img.Save(@"C:\Users\Admin\Documents\visual studio 2015\Projects\EFDemoWebForm\Entity\QR\" + FileName, System.Drawing.Imaging.ImageFormat.Png);
            return FileName;
        }


    }
}




TLVCls Class File Code:


using System;
using System.Text;
using System.Drawing;
using System.Collections.Generic;
using ZXing;
using ZXing.Common;

namespace ManojKallaTutorial
{
    public class TLVCls
    {
        byte[] Seller;
        byte[] VatNo;
        byte[] dateTime;
        byte[] Total;
        byte[] Tax;

        public TLVCls(String Seller, String TaxNo, DateTime dateTime, Double Total, Double Tax)
        {
            this.Seller = Encoding.UTF8.GetBytes(Seller);
            this.VatNo = Encoding.UTF8.GetBytes(TaxNo);

            this.dateTime = Encoding.UTF8.GetBytes(dateTime.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'"));
            this.Total = Encoding.UTF8.GetBytes(Total.ToString());
            this.Tax = Encoding.UTF8.GetBytes(Tax.ToString());
        }

        private String getasText(int Tag, byte[] Value)
        {
            return (Tag).ToString("X2") + (Value.Length).ToString("X2") + BitConverter.ToString(Value).Replace("-", string.Empty);
        }

        private byte[] getBytes(int id, byte[] Value)
        {
            byte[] val = new byte[2 + Value.Length];
            val[0] = (byte)id;
            val[1] = (byte)Value.Length;
            Value.CopyTo(val, 2);
            return val;
        }

        private String getString()
        {
            String TLV_Text = "";
            TLV_Text += this.getasText(1, this.Seller);
            TLV_Text += this.getasText(2, this.VatNo);
            TLV_Text += this.getasText(3, this.dateTime);
            TLV_Text += this.getasText(4, this.Total);
            TLV_Text += this.getasText(5, this.Tax);
            return TLV_Text;
        }

        public override string ToString()
        {
            return this.getString();
        }

        public String ToBase64()
        {
            List<byte> TLV_Bytes = new List<byte>();
            TLV_Bytes.AddRange(getBytes(1, this.Seller));
            TLV_Bytes.AddRange(getBytes(2, this.VatNo));
            TLV_Bytes.AddRange(getBytes(3, this.dateTime));
            TLV_Bytes.AddRange(getBytes(4, this.Total));
            TLV_Bytes.AddRange(getBytes(5, this.Tax));
            return Convert.ToBase64String(TLV_Bytes.ToArray());
        }

        public Bitmap toQrCode(int width = 250, int height = 250)
        {

            BarcodeWriter barcodeWriter = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new EncodingOptions
                {
                    Width = width,
                    Height = height
                }
            };
            Bitmap QrCode = barcodeWriter.Write(this.ToBase64());

            return QrCode;
        }


    }

}

Wednesday 1 March 2023

VFP how to create image button | VFP Image Command Button | Image on command button


Image on Command Button in Visual Foxpro 9 - VFP9| Image Button in Visual Foxpro 9 - VFP9



Double Click on Form goto Init


thisform.btnDelete.Picture = CURDIR()+"\DELETE.BMP"


Advantage of using CURDIR() is while vfp application run it will take current path automatically.


Don't use Picture property directly of command button. This recorded as hardcoded path in form.



Thank You