using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFBScriptJ
{
public class Class1
{
sampleDbEntities sd = new sampleDbEntities();
static Product d = new Product();
public static void Insert()
{
using (sampleDbEntities sd = new sampleDbEntities())
{
var t = new Product
{
Product_Name = d.Product_Name,
Product_Name1 = d.Product_Name1,
Product_Name2 = d.Product_Name2,
Product_Name3 = d.Product_Name3,
Product_Name4 = d.Product_Name4,
Product_Name5 = d.Product_Name5,
Product_Name6 = d.Product_Name6,
Product_Name7 = d.Product_Name7,
Product_Price = d.Product_Price,
Product_Price1 = d.Product_Price1,
Product_Price4 = d.Product_Price4,
Product_Price2 = d.Product_Price2,
Product_Price3 = d.Product_Price3,
Product_Price5 = d.Product_Price5,
Product_Price6 = d.Product_Price6,
Product_Price7 = d.Product_Price7,
};
sd.Products.Add(t);
try
{
sd.SaveChanges();
}
catch (DbEntityValidationException e)
{
foreach (var eve in e.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
}
}
throw;
}
}
}
static void Main(string[] args)
{
List<string> lines = System.IO.File.ReadAllLines(@"C:\khadar\Demo.mnk").ToList();
int count = 0;
int second = 8;
int value = 0;
for (int i = 8; i <= lines.Count; i = i + second)
{
count = i;
if (count == 8)
{
var firstEightLine = lines.Take(count).ToList();
foreach (var line in firstEightLine)
{
var content = line.Split(',');
if (line[0] == '1')
{
d.Product_Name = content[1].ToString();
d.Product_Price = content[2].ToString();
}
else if (line[0] == '2')
{
d.Product_Name1 = content[1].ToString();
d.Product_Price1 = content[2].ToString();
}
else if (line[0] == '3')
{
d.Product_Name2 = content[1].ToString();
d.Product_Price2 = content[2].ToString();
}
else if (line[0] == '4')
{
d.Product_Name3 = content[1].ToString();
d.Product_Price3 = content[2].ToString();
}
else if (line[0] == '5')
{
d.Product_Name4 = content[1].ToString();
d.Product_Price4 = content[2].ToString();
}
else if (line[0] == '6')
{
d.Product_Name5 = content[1].ToString();
d.Product_Price5 = content[2].ToString();
}
else if (line[0] == '7')
{
d.Product_Name6 = content[1].ToString();
d.Product_Price6 = content[2].ToString();
}
else if (line[0] == '8')
{
d.Product_Name7 = content[1].ToString();
d.Product_Price7 = content[2].ToString();
}
}
Insert();
}
else
{
var secondline = lines.Skip(count - second).Take(8).ToList();
foreach (var line in secondline)
{
var content = line.Split(',');
if (line[0] == '1')
{
d.Product_Name = content[1].ToString();
d.Product_Price = content[2].ToString();
}
else if (line[0] == '2')
{
d.Product_Name1 = content[1].ToString();
d.Product_Price1 = content[2].ToString();
}
else if (line[0] == '3')
{
d.Product_Name2 = content[1].ToString();
d.Product_Price2 = content[2].ToString();
}
else if (line[0] == '4')
{
d.Product_Name3 = content[1].ToString();
d.Product_Price3 = content[2].ToString();
}
else if (line[0] == '5')
{
d.Product_Name4 = content[1].ToString();
d.Product_Price4 = content[2].ToString();
}
else if (line[0] == '6')
{
d.Product_Name5 = content[1].ToString();
d.Product_Price5 = content[2].ToString();
}
else if (line[0] == '7')
{
d.Product_Name6 = content[1].ToString();
d.Product_Price6 = content[2].ToString();
}
else if (line[0] == '8')
{
d.Product_Name7 = content[1].ToString();
d.Product_Price7 = content[2].ToString();
}
var mainvalue = count - second;
}
Insert();
}
}
}
}
}
</string>