ahmedaziz
Well-known member
- Joined
- Feb 22, 2023
- Messages
- 55
- Programming Experience
- 1-3
I work on asp.net core 7 . i have list have over than one millions rows when it executed it take too much time to finish
too much time reach to 1 day
Branches List return 1 millions rows
so please what enhancement or technologies can use to make process select and update faster according to my code
or if you have another way can do this code with best way faster so if you know any way please tell me
if another or new technology tel me
my code details
too much time reach to 1 day
list return 1 milions:
var BranchesList = _OsuBranch.GetList(x => x.BRTYPE == "BR" && x.OSU_Is_Active == "Y");
block branch list and what inside it is very slow:
if (BranchesList != null && BranchesList.Any())
{
//select and update take too much time
}
so please what enhancement or technologies can use to make process select and update faster according to my code
or if you have another way can do this code with best way faster so if you know any way please tell me
if another or new technology tel me
my code details
function update cost is very slow implementation and take too much time:
public async Task UpdateCost()
{
DateTime Fdate;
DateTime TDate;
try
{
string JDEsql = "";
string NAVsql = "";
DataTable JDEds = new DataTable();
int totalRows = 0;
int JDEtotalRows = 0;
TDate = DateTime.Now;
Fdate = DateTime.Now.AddDays(-7);
string date1 = Fdate.ToString("yyyy-MM-dd");
string date2 = TDate.ToString("yyyy-MM-dd");
string strBranch = "";
string TotalJDERows = "";// = "Total JDE Rows: " + JDEtotalRows;
string TotalUpdatedRows = "";// = "Total Updated Rows: " + totalRows;
string RunningCost = "";
string FromDateToDate = "";
string AppID = "";
var BranchesList = _OsuBranch.GetList(x => x.BRTYPE == "BR" && x.OSU_Is_Active == "Y");
if (BranchesList != null && BranchesList.Any())
{
foreach (var branch in BranchesList)
{
strBranch = branch.brcode.ToString();
AppID = _OsuBranch.GetFirst(x => x.brcode == strBranch).AppID.ToString();
string strBranches;
var strSubUnit = _OsuBranch.GetFirst(x => x.brcode == strBranch && x.DeptNo == "058").JSubUnit.ToString();//.JSubUnit.ToString(); //getSubUnint(strBranch);
if (strSubUnit == null || strSubUnit.CompareTo("0") <= 0)
{
strSubUnit = "0";
}
else
{
strSubUnit = _OsuBranch.GetFirst(x => x.brcode == strBranch && x.DeptNo == "058")?.JSubUnit.ToString();
}
if (strSubUnit.ToString() == "0")
{
strBranches = string.Format("'{0}'", strBranch);// "'" + strBranch + "'";
}
else
{
strBranches = string.Format("'{0}','{1}'", strBranch, strSubUnit.ToString().Trim());
}
RunningCost = "Running Cost Update for Branch " + strBranches;
FromDateToDate = "From Date: " + date1 + " To Date: " + date2;
var vdSalesList = _salesDetails.GetList(x => Convert.ToDateTime(x.sldate) >= Convert.ToDateTime(FormatDateAsyyyyMMdd(date1)) && Convert.ToDateTime(x.sldate) <= Convert.ToDateTime(FormatDateAsyyyyMMdd(date2)));
DataTable dtvdSales = ConvertListToDataTable<SalesDetails>(vdSalesList);
if (dtvdSales.Rows.Count > 0)
{
foreach (DataRow de in dtvdSales.Rows)
{
JDEsql = "SELECT SDDOCO, SDITM, SDAITM, SDUOM, (SDUNCS/10000) AS SDUNCS ,SDTRDJ ";
JDEsql += " FROM PRODDTA.F42119 ";
JDEsql += " WHERE (SDKCOO in ( '00001','00005')) AND (SDDCTO = 'SP') AND (SDTRDJ >= " + GeneralFunction.DateTimeToJulian(Convert.ToDateTime(date1)) + ") AND (SDTRDJ <= " + GeneralFunction.DateTimeToJulian(Convert.ToDateTime(date2)) + ") "; // AND LTRIM(SDEMCU) IN ( " + strBranches + ")
JDEsql += " and SDDOCO in (" + de["DOCO"] + ") and SDITM=" + de["JDEItemNo"] + " and SDAITM='" + de["itemno"] + "' and SDUOM ='" + de["SUOM"] + "' ";
JDEsql += " UNION ";
JDEsql += " SELECT SDDOCO, SDITM, SDAITM, SDUOM, (SDUNCS/10000) AS SDUNCS ,SDTRDJ ";
JDEsql += " FROM PRODDTA.F4211 ";
JDEsql += " WHERE (SDKCOO in ( '00001','00005')) AND (SDDCTO = 'SP') AND (SDTRDJ >= " + GeneralFunction.DateTimeToJulian(Convert.ToDateTime(date1)) + ") AND (SDTRDJ <= " + GeneralFunction.DateTimeToJulian(Convert.ToDateTime(date2)) + ") "; // AND LTRIM(SDEMCU) IN ( " + strBranches + ")
JDEsql += " and SDDOCO in (" + de["DOCO"] + ") and SDITM=" + de["JDEItemNo"] + " and SDAITM='" + de["itemno"] + "' and SDUOM ='" + de["SUOM"] + "' ";
JDEds = await _ConnectionDatabase.ReadDatabaseUsingClassLibrary(JDEsql);
if (JDEds.Rows.Count > 0)
{
foreach (DataRow dr in JDEds.Rows)
{
JDEtotalRows++;
int num = 0;
num = await _salesDetails.Update(
x =>
x.brcode == strBranch &&
x.JDEItemNo == dr["SDITM"].ToString() &&
x.itemno == dr["SDAITM"].ToString().Trim() &&
x.Doco == dr["SDDOCO"].ToString().Trim() &&
x.SUOM == dr["SDUOM"].ToString().Trim() &&
x.UnitCost == 0,
x =>
{
x.UnitCost = Convert.ToDecimal(dr["SDUNCS"].ToString());
});
totalRows += num;
}
}
}
TotalJDERows = "Total JDE Rows: " + JDEtotalRows;
TotalUpdatedRows = "Total Updated Rows: " + totalRows;
}
}
}
}
catch (Exception ex)
{
}