SVN-Revision: r735
This commit is contained in:
wyf
2025-06-14 15:19:44 +00:00
parent 57887a4fec
commit c9b69fb6dc
11 changed files with 1151 additions and 640 deletions
+33 -151
View File
@@ -61,10 +61,8 @@ namespace Lskj.PubBomImportNew
{
try
{
InitlizeSpiltLocation();
InitEvents();
InitGridColumns();
InitMulitControl();
InitDataSource();
}
catch (Exception ex)
@@ -75,33 +73,6 @@ namespace Lskj.PubBomImportNew
}
}
/// <summary>
/// 导入按钮点击
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnBtnImportClick(object sender, EventArgs e)
{
try
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = false;
dialog.InitialDirectory = Properties.Settings.Default.LastSelectFolder;
dialog.Title = "选择导入文件";
dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
DialogResult dialogResult = dialog.ShowDialog();
if (dialogResult == DialogResult.OK)
{
Properties.Settings.Default.LastSelectFolder = Path.GetDirectoryName(dialog.FileName);
FrmProgress frmProgress = new FrmProgress();
frmProgress.StartImportInFileByZB(dialog.FileName.ToList());
}
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
}
}
/// <summary>
/// 读取按钮点击
/// </summary>
/// <param name="sender"></param>
@@ -118,34 +89,31 @@ namespace Lskj.PubBomImportNew
if (result == DialogResult.OK)
{
string fileName = importFileName = dialog.FileName;
tipsEdit.Text = string.Format("当前读取文件:{0},请绑定列后点击导入", Path.GetFileName(fileName));
string colFields = this.gcMain.GridView.Columns.ToString(',');
int.TryParse(Model.FirstRowIndex, out FirstRowIndex);
DataTable dataTable = ExcelToDatatable(fileName, Model, Model.SheetName, FirstRowIndex);
int.TryParse(Model.stratRowHand, out FirstRowIndex);
DataTable dataTable = ExcelToDatatable(fileName, Model, "", FirstRowIndex);
DataTable importTable = GetSourceTable(dataTable);
DataTable sourceTable = this.gcMain.GridControl.DataSource as DataTable;
if (dataTable != null)
{
try
{
if (!string.IsNullOrEmpty(Model.ReadTableCond))
{
DataView view = new DataView(dataTable);
view.RowFilter = Model.ReadTableCond;
dataTable = view.ToTable();
}
}
catch (Exception)
{
}
this.gc_Right.SetGridViewDataSource(dataTable);
}
//if (dataTable != null)
//{
// try
// {
// if (!string.IsNullOrEmpty(Model.ReadTableCond))
// {
// DataView view = new DataView(dataTable);
// view.RowFilter = Model.ReadTableCond;
// dataTable = view.ToTable();
// }
// }
// catch (Exception)
// {
// }
//}
if (sourceTable != null && sourceTable.Rows.Count > 0)
{
if (sourceTable.Rows.Count != importTable.Rows.Count)
{
this.gcMain.SetGridViewDataSource(importTable);
this.condTxtEdit.Text = "";
}
else
{
@@ -164,22 +132,18 @@ namespace Lskj.PubBomImportNew
if (!isComplete)
{
this.gcMain.SetGridViewDataSource(importTable);
this.condTxtEdit.Text = "";
}
}
}
else
{
this.gcMain.SetGridViewDataSource(importTable);
this.condTxtEdit.Text = "";
}
}
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
tipsEdit.Text = "请导入Excel模板";
gc_Right.SetGridViewDataSource(new DataTable());
this.DialogResult = DialogResult.Cancel;
}
}
@@ -192,8 +156,6 @@ namespace Lskj.PubBomImportNew
{
try
{
string condFilter = this.condTxtEdit.Text.Trim();
string condPurview = this.purview_Mulit.EditValue;
string unionColumn = GetUnionColumn();
string sql = "if exists(select * from P_SpecialImportTab where moduleId = '{0}' and rightMenuName = '{1}') " +
"begin " +
@@ -202,7 +164,7 @@ namespace Lskj.PubBomImportNew
"else begin " +
"insert into P_SpecialImportTab (moduleId,rightMenuName,Ls_CondFilter,Ls_UnionColumn,Ls_CondPurview) values ('{0}','{1}','{2}','{3}','{4}') " +
"end";
sql = string.Format(sql, Model.ModuleCode, Model.ModuleId, condFilter.Replace("'", "''"), unionColumn.Replace("'", "''"), condPurview.Replace("'", "''"));
sql = string.Format(sql, Model.ModuleCode, Model.ModuleId, "", unionColumn.Replace("'", "''"), "");
SqlHelper.ExecuteNonQuery(sql);
MessageUtil.Show("保存成功");
}
@@ -234,25 +196,6 @@ namespace Lskj.PubBomImportNew
MessageUtil.Show(string.Format("取消绑定列失败,原因:{0}", ex.Message));
}
}
/// <summary>
/// 分隔条位置改变时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnSplitMainContainerPositionChanged(object sender, EventArgs e)
{
try
{
if (this.Model != null)
{
IniHelper.Write(string.Format("PubSpecialImport_SplitMain_{0}", this.Model.ModuleCode), this.splitMainContainer.SplitterPosition + "");
}
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
}
}
#endregion
#region
/// <summary>
@@ -261,28 +204,8 @@ namespace Lskj.PubBomImportNew
private void InitEvents()
{
this.btnRead.Click += OnBtnReadClick;
this.btnImport.Click += OnBtnImportClick;
this.btnOk.Click += OnBtnOkClick;
this.btnCancel.Click += OnBtnCancelClick;
this.splitMainContainer.SplitterPositionChanged += OnSplitMainContainerPositionChanged;
}
/// <summary>
/// 设置分割条位置
/// </summary>
private void InitlizeSpiltLocation()
{
try
{
string splitMainWidth = IniHelper.Read(string.Format("PubSpecialImport_SplitMain_{0}", this.Model.ModuleCode));//通过Key获取Value值
if (!string.IsNullOrEmpty(splitMainWidth))
{
this.splitMainContainer.SplitterPosition = Convert.ToInt32(splitMainWidth);
}
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
}
}
/// <summary>
/// 初始化表格列
@@ -315,37 +238,6 @@ namespace Lskj.PubBomImportNew
searchEdit.View.Tag = searchEdit;
}
/// <summary>
/// 初始化多选控件
/// </summary>
private void InitMulitControl()
{
if (!ERPInfo.Instance.UserName.Equals("管理员"))
{
pl_purview.Visible = false;
return;
}
purview_Mulit.LabelText = "";
purview_Mulit.ValueMember = "UserId";
purview_Mulit.TextField = "UserName";
purview_Mulit.ValueField = "UserId";
purview_Mulit.Model = new ControlModel()
{
FieldType = ControlType.LabMultiSelectValue,
};
string fields = string.Empty;
if (BaseImpl.HasExistsColumn("P_EmployeeTab", "SignBmp"))
fields = ",SignBmp";
if (BaseImpl.HasExistsColumn("P_EmployeeTab", "Password"))
fields += ",Password";
if (BaseImpl.HasExistsColumn("P_EmployeeTab", "AD_Id"))
fields += ",AD_Id";
string sqlValue = string.Format("select EmployeeId UserId,LoginAccount UserCode,EmployeeName UserName {0} from P_EmployeeTab WHERE sign=0 and UseFlag=1 order by loginaccount", fields);
DataTable dataSource = SqlHelper.ExecuteDataTable(sqlValue);
purview_Mulit.SourceSQL = sqlValue;
purview_Mulit.SetDataSource(dataSource);
purview_Mulit.TextEdit.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
}
/// <summary>
/// 初始化数据
/// </summary>
private void InitDataSource()
@@ -401,17 +293,7 @@ namespace Lskj.PubBomImportNew
if (dataTable != null && dataTable.Rows.Count > 0)
{
DataRow dataRow = dataTable.Rows[0];
string condFilter = dataRow["Ls_CondFilter"] + "";
string unionColumn = dataRow["Ls_UnionColumn"] + "";
string condPurview = dataRow["Ls_CondPurview"] + "";
string[] values = condPurview.Trim(',').Split(',');
if (!values.Contains(ERPInfo.Instance.UserId))
{
condTxtEdit.ReadOnly = true;
}
this.condTxtEdit.Text = condFilter;
this.purview_Mulit.EditText = condPurview;
List<string> unionColumnList = unionColumn.Split(',').ToList();
DataTable sourceTable = GetSourceTable(unionColumnList);
this.gcMain.GridControl.DataSource = sourceTable;
@@ -525,7 +407,7 @@ namespace Lskj.PubBomImportNew
startRow = mergrRange.LastRow + 1;
if (mergrRange != null)
{
if (mergrRange.FirstColumn < mergrRange.LastColumn && !Model.CustomerServiceApp)
if (mergrRange.FirstColumn < mergrRange.LastColumn)//&& !Model.CustomerServiceApp
{
isBandTitle = true;
bandRow = sheet.GetRow(mergrRange.LastRow + 1);
@@ -764,18 +646,18 @@ namespace Lskj.PubBomImportNew
GridView gridView = ParentView;
DataTable columnsTable = gcMain.gridControl.DataSourceTable();
DataTable table = gridView.GridControl.DataSourceTable();
DataTable sourceDataTable = ExcelToDatatable(fileName, Model, Model.SheetName, FirstRowIndex);
DataTable sourceDataTable = ExcelToDatatable(fileName, Model, "", FirstRowIndex);
DataView filterDataView = new DataView(sourceDataTable);
try
{
if (!string.IsNullOrEmpty(Model.ReadTableCond))
{
filterDataView.RowFilter = Model.ReadTableCond;
}
}
catch (Exception)
{
}
//try
//{
// if (!string.IsNullOrEmpty(Model.ReadTableCond))
// {
// filterDataView.RowFilter = Model.ReadTableCond;
// }
//}
//catch (Exception)
//{
//}
List<DataRow> dataRows = columnsTable.Rows.Cast<DataRow>().Where(n => !string.IsNullOrEmpty(n["excelFieldName"] + "") && !string.IsNullOrEmpty(n["clientFieldName"] + "")).ToList();
int index = gridView is BandedGridView ? FirstRowIndex + 1 : FirstRowIndex;
isBillImport = index == FirstRowIndex ? true : isBillImport;
@@ -807,7 +689,7 @@ namespace Lskj.PubBomImportNew
startRow = mergrRange.LastRow + 1;
if (mergrRange != null)
{
if (mergrRange.FirstColumn < mergrRange.LastColumn && !Model.CustomerServiceApp)
if (mergrRange.FirstColumn < mergrRange.LastColumn)//&& !Model.CustomerServiceApp
{
isBandTitle = true;
bandRow = sheet.GetRow(mergrRange.LastRow + 1);
@@ -870,7 +752,7 @@ namespace Lskj.PubBomImportNew
ToAssignment = true;
CurrentRow = i;
DataRow rowSource = sourceDataTable.Rows[i - startRow];
if (!filterDataView.Cast<DataRowView>().Any(rowView => rowView.Row == rowSource) || !ValidateCond(condTxtEdit.Text, rowSource))
if (!filterDataView.Cast<DataRowView>().Any(rowView => rowView.Row == rowSource))
{
continue;
}
@@ -893,7 +775,7 @@ namespace Lskj.PubBomImportNew
startRow = mergrRange.LastRow + 1;
if (mergrRange != null)
{
if (mergrRange.FirstColumn < mergrRange.LastColumn && !Model.CustomerServiceApp)
if (mergrRange.FirstColumn < mergrRange.LastColumn)//&& !Model.CustomerServiceApp
{
isBandTitle = true;
bandRow = sheet.GetRow(mergrRange.LastRow + 1);