SVN r389
SVN-Revision: r389
This commit is contained in:
@@ -100,148 +100,37 @@ namespace Lskj.PubBomImport
|
||||
{
|
||||
try
|
||||
{
|
||||
//bool showType = Model != null && Model.ShowType.Equals("1") && !ERPInfo.Instance.UserName.Equals("管理员");
|
||||
//string fileName = importFileName;
|
||||
//if (File.Exists(fileName))
|
||||
//{
|
||||
// this.Hide();
|
||||
// WaitForm.ShowForm("正在导入数据...");
|
||||
// this.ParentView.GridControl.DataSource = this.ToExcelDataTable(fileName, out int count, out int errorCount, true);
|
||||
// WaitForm.HideForm();
|
||||
// if (!showType)
|
||||
// {
|
||||
// MessageUtil.Show(string.Format("成功导入{0}条数据,错误{1}条数据", count, errorCount));
|
||||
// }
|
||||
// this.Close();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// MessageUtil.Show("导入Excel文件不存在");
|
||||
// tipsEdit.Text = "请导入Excel模板";
|
||||
// btnImport.Enabled = false;
|
||||
//}
|
||||
//DialogResult dialogResult = frmBillInfo.ShowDialog();
|
||||
//if (dialogResult == DialogResult.OK)
|
||||
//{
|
||||
//}
|
||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||
dialog.Description = "选择导入文件夹";
|
||||
DialogResult dialogResult = dialog.ShowDialog();
|
||||
if (dialogResult == DialogResult.OK)
|
||||
{
|
||||
WaitForm.ShowForm("数据导入中");
|
||||
string dirPath = dialog.SelectedPath;
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(dirPath);
|
||||
FileInfo[] fileInfos = directoryInfo.GetFiles();
|
||||
FileInfo parentInfo = fileInfos.Where(n => n.Name.StartsWith("MX") && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (parentInfo != null)
|
||||
FrmProgress frmProgress = new FrmProgress();
|
||||
frmProgress.frmMain = this;
|
||||
frmProgress.ImportTimer.Tick += (ts, te) =>
|
||||
{
|
||||
WaitForm.ShowForm("数据导入中");
|
||||
DataTable parentTable = ExcelToDatatable(parentInfo.FullName, "", 5);
|
||||
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (DataRow dataRow in parentTable.Rows)
|
||||
{
|
||||
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{(dataRow["图号"] + "").Trim()}')");
|
||||
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak) values ('{(dataRow["图号"] + "").Trim().Replace("'", "''")}','{(dataRow["名称"] + "").Trim().Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}') end;");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||
}
|
||||
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
||||
frmBillInfo.OnLoad(Model);
|
||||
ParentView = frmBillInfo.GcMainView;
|
||||
frmBillInfo.ControlObj.OnDataSourceBindCallBack += (s, args) =>
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
WaitForm.ShowForm("数据导入中");
|
||||
DataTable childTable = new DataTable();
|
||||
foreach (GridColumn gridColumn in ParentView.Columns)
|
||||
{
|
||||
if (!childTable.Columns.Contains(gridColumn.FieldName))
|
||||
{
|
||||
childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType);
|
||||
}
|
||||
}
|
||||
foreach (DataRow parentRow in parentTable.Rows)
|
||||
{
|
||||
DataRow childRow = childTable.NewRow();
|
||||
childRow["ProductId"] = (parentRow["图号"] + "").Trim();
|
||||
childRow["appellation"] = (parentRow["名称"] + "").Trim();
|
||||
childRow["bak"] = (parentRow["备注"] + "").Trim();
|
||||
childRow["tamount"] = parentRow["套数"] + "";
|
||||
childRow["amount"] = parentRow["套数"] + "";
|
||||
childTable.Rows.Add(childRow);
|
||||
}
|
||||
ParentView.GridControl.DataSource = childTable;
|
||||
string controlSql = "select '' as billdocument_id,'0' affirmer,'0' rtagid,'{材料代码}' as productid";
|
||||
frmBillInfo.InitializeHeader(Model.MaintabFocusedRow, controlSql);
|
||||
frmBillInfo.BillSave();
|
||||
frmBillInfo.OnBillAdd();
|
||||
string productId = (Model.MaintabFocusedRow["材料代码"] + "").Trim();
|
||||
string billdocumentId = (Model.MaintabFocusedRow["单据编号"] + "").Trim();
|
||||
string updateParentVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id='{1}' and ProductId='{0}'";
|
||||
SqlHelper.ExecuteNonQuery(string.Format(updateParentVerSql, productId, billdocumentId));
|
||||
int.TryParse(Model.FirstRowIndex, out int index);
|
||||
FirstRowIndex = index;
|
||||
foreach (DataRow dataRow in parentTable.Rows)
|
||||
{
|
||||
int.TryParse(dataRow["套数"] + "", out int tamount);
|
||||
string code = (dataRow["图号"] + "").Trim();
|
||||
FileInfo childInfo = fileInfos.Where(n => n.Name.Contains(code) && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (childInfo != null)
|
||||
{
|
||||
DataTable detailTable = this.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
|
||||
foreach (DataRow detailRow in detailTable.Rows)
|
||||
{
|
||||
int.TryParse(detailRow["amount"] + "", out int lastAmount);
|
||||
detailRow["tamount"] = tamount;
|
||||
detailRow["amount"] = tamount > 0 ? (lastAmount * tamount) + "" : lastAmount + "";
|
||||
}
|
||||
ParentView.GridControl.DataSource = detailTable;
|
||||
frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql);
|
||||
frmBillInfo.BillSave();
|
||||
frmBillInfo.OnBillAdd();
|
||||
string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'";
|
||||
SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
WaitForm.HideForm();
|
||||
this.Close();
|
||||
}
|
||||
}));
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitForm.HideForm();
|
||||
MessageUtil.Show("未包含结构文件");
|
||||
this.Close();
|
||||
}
|
||||
frmProgress.ImportTimer.Enabled = false;
|
||||
frmProgress.StartImport(dirPath);
|
||||
};
|
||||
frmProgress.ImportTimer.Enabled = true;
|
||||
frmProgress.ShowDialog();
|
||||
frmProgress.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitForm.HideForm();
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WaitForm.HideForm();
|
||||
MessageUtil.Show(ex.Message);
|
||||
this.Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取按钮点击
|
||||
@@ -973,7 +862,7 @@ namespace Lskj.PubBomImport
|
||||
/// <param name="isDirectImport"></param>
|
||||
/// <param name="isBillImport"></param>
|
||||
/// <returns></returns>
|
||||
private DataTable ToExcelDataTable(string fileName, out int count, out int errorCount, bool isDirectImport = false, bool isBillImport = false)
|
||||
public DataTable ToExcelDataTable(string fileName, out int count, out int errorCount, bool isDirectImport = false, bool isBillImport = false)
|
||||
{
|
||||
count = 0;
|
||||
errorCount = 0;
|
||||
@@ -1737,4 +1626,31 @@ namespace Lskj.PubBomImport
|
||||
{
|
||||
case CellType.String:
|
||||
cellValue = cell.StringCellValue;
|
||||
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
cellValue = cell.NumericCellValue.ToString();
|
||||
break;
|
||||
case CellType.Boolean:
|
||||
cellValue = cell.BooleanCellValue.ToString();
|
||||
break;
|
||||
case CellType.Blank:
|
||||
break;
|
||||
default:
|
||||
cellValue.ToString();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cellValue = cell.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return cellValue;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user