protected void lnkbtnUpload_OnClick(object sender, EventArgs e) { string msg = string.Empty; if (!FileUpload.HasFile) { FileUpload.Focus(); msg = "Please Select Excel File!"; ShowMessageErr(msg); return; } if (ddlDateRange.SelectedValue == "0") { ddlDateRange.Focus(); msg = "Please Select Date Range!"; ShowMessageErr(msg); return; } if (ddlLocation.SelectedValue == "0") { ddlLocation.Focus(); msg = "Please Select Location!"; ShowMessageErr(msg); return; } OpenTyreDAL objOpenStockAccess = new OpenTyreDAL(); string excelfilename = string.Empty; try { using (TransactionScope Tran = new TransactionScope(TransactionScopeOption.Required)) { excelfilename = ApplicationFunction.UploadFileServerControl(FileUpload, "ExcelTyre", "OpeningStockAccessories"); if ((System.IO.Path.GetExtension(excelfilename) == ".xls") || (System.IO.Path.GetExtension(excelfilename) == ".xlsx")) { DataTable dt = ReadExcelFile("~/ExcelTyre/" + excelfilename); Int64 value = 0; OpenTyreDAL clsOpngStck = new OpenTyreDAL(); DataTable DtnotUpload = dt.Clone(); OpenTyreDAL objItem = new OpenTyreDAL(); for (int count = 0; count < dt.Rows.Count; count++) { var lst = objItem.GetItemDetailsExl(Convert.ToString(dt.Rows[count]["TyreName"]).Trim()); if (lst.Count <= 0) { ShowMessageErr(Convert.ToString(dt.Rows[count]["TyreName"].ToString()).Trim() + " Item Does Not Exist!"); return; } else { string Type = dt.Rows[count]["Type"].ToString(); if (Type == "New" || Type == "Old" || Type == "Retrieted") { string Type_Idno = (Type == "New") ? "1" : (Type == "Old") ? "2" : "3"; dt.Rows[count]["Type_Idno"] = Type_Idno; } else { ShowMessageErr(Convert.ToString(dt.Rows[count]["Type"].ToString()).Trim() + " Type Does Not Exist of " + dt.Rows[count]["TyreName"].ToString() + " Item!"); return; } } } int dttruncate = objOpenStockAccess.TurncatePartsAccessoriesFromExcel(ApplicationFunction.ConnectionString()); value = clsOpngStck.InsertPartsByExcel(dt, ApplicationFunction.ConnectionString()); BindGridDB(); } else { msg = "Excel File Format Not Supported!"; ShowMessageErr(msg); return; } } } catch (Exception Ex) { } }