一个grid公共模块
主界面
var P033_Query = function () {
var Designbusiness_Store = new Ext.data.JsonStore({ //专业数据集
url: "PdmP032.csx?tag=GetDesignbusiness",
fields: ["STANDA_SCHEDULE_ID", "STANDA_SCHEDULE_NAME"],
baseParams: { strWhere: " AND S_TYPE ='E' " },
root: "data",
id: "STANDA_SCHEDULE_ID",
toValue: function (v) {
var rec = Designbusiness_Store.getById(v);
return rec ? rec.data.STANDA_SCHEDULE_NAME : v;
},
autoLoad: true
});
var Designbusiness = new Ext.form.SComboBox({
width: 150,
triggerAction: "all",
store: Designbusiness_Store,
valueField: 'STANDA_SCHEDULE_ID',
displayField: 'STANDA_SCHEDULE_NAME'
});
var f_center_num = new Ext.form.NumberField({ name: 'COST_CENTER_ID', allowDecimals: false, allowNegative: false })
var f_center_name = new ef.TextField({ })
var f_subject = new ef.TextField({ })
var sm = new Ext.grid.CheckboxSelectionModel({});
var gridColumns = new eg.ColumnModel({
columns: [
sm,
{ header: "内码", dataIndex: "ID", hidden: true },
{ header: "成本中心编码" + prj.necessaryField, dataIndex: "COST_CENTER_ID", width: 100, editor: new Ext.form.NumberField({ name: 'COST_CENTER_ID', allowDecimals: false, allowNegative: false }) },
{ header: "归属科目" + prj.necessaryField, dataIndex: "ACC_ATT", editor: new ef.TextField({ name: 'ACC_ATT' }) },
{ header: "登记时间", dataIndex: "DEF_DATE", format: Date.patterns.ISO8601Short, xtype: 'datecolumn', hidden: true },
{ header: "登记人", dataIndex: "DEF_USR_ID", renderer: userStore.toValue, hidden: true },
{ header: "修改时间", dataIndex: "UPD_DATE", format: Date.patterns.ISO8601Short, xtype: 'datecolumn', hidden: true },
{ header: "修改人", dataIndex: "UPD_USR_ID", renderer: userStore.toValue, hidden: true }
]
});
var p_store = new Ext.data.JsonStore({ //数据集
url: "PdmP033.csx?tag=GetJsonList",
fields: ["ID", { name: "COST_CENTER_ID", allowBlank: false }, "UPD_USR_ID", "DEF_USR_ID",
{ name: "DEF_DATE", type: "date", dateFormat: Date.patterns.ISO8601Short },
{ name: "UPD_DATE", type: "date", dateFormat: Date.patterns.ISO8601Short }],
root: "data",
baseParams: {
sfields: ["COST_CENTER_ID"].join(prj.colSplit),
sfieldtypes: ['number'].join(prj.colSplit),
relations: [" = "].join(prj.colSplit),
page: "1",
},
id: "id",
totalProperty: "totalCount"
})
function getBaseParams(v) {
var p = {
svalues: [f_center_num.getValue()].join(prj.colSplit),
limit: pagebar.pageSize
};
Ext.apply(v.baseParams, p);
}
p_store.on('beforeload', getBaseParams);
var pagebar = new prj.util.PagingToolbar(p_store, 20);
var grid = new Ext.RSEGrid({ //数据显示面板
id: 'P033_btn_panel_grid',
border: false,
store: p_store,
sm: sm,
cm: gridColumns,
buttonAlign: 'left',
bbar: pagebar,
region: 'center'
});
var searchBtn = new Ext.Button({
text: "搜索",
iconCls: 'Icon16_Search',
handler: function () {
grid.getStore().load({ params: { start: 0 } });
}
});
var qtbr_1 = new Ext.Toolbar({
items: ["成本中心编码", f_center_num,'-', searchBtn]
})
var query_panel = new Ext.Panel({
id: 'P033_btn_panel',
border: false,
layout: "border",
isLoad: true,
items: [grid],
tbar: ['->'],
listeners: {
render: function (p) {
qtbr_1.render(p.tbar);
}
}
});
query_panel.grid = grid;
query_panel.load = function () {
}
query_panel.func = function () {
};
return query_panel;
}
public string GetJsonList()
{
try
{
S_VO v = new S_VO(Request);
string sql = "SELECT * FROM DES_REV_NODE_CONFIG WHERE 1=1 {0}";
DbUtil.Query(string.Format(sql, v.getCondition()), v);
return v.getJsonList();
}
catch (Exception ex)
{
throw ex;
}
}
添加
var P032_Add = function(action_url, query_panel) {
return new Ext.Button({
id: 'P032_Add',
handler: function () {
query_panel.grid.insertRows();
}
});
}
删除
var P032_Delete = function(action_url, query_panel) {
return new Ext.Button({
id: 'P032_delete',
handler: function() {
var grid = query_panel.grid;
var selectedRows = grid.getSelectionModel().getSelections();
if (selectedRows.length == 0) {
Ext.Msg.alert(MsgMrg.OptMsg, MsgMrg.OptNotSelectRow);
return;
}
Ext.Msg.confirm(MsgMrg.OptMsg, MsgMrg.OptIsDelSelect,
function(btn) {
if (btn == "yes") {
var v_ids = prj.util.GetDeleteIds(grid, selectedRows, "ID");
if (v_ids == null) { return; }
var mask = initPanelMask(query_panel);
mask.show();
Ext.Ajax.request({
url: action_url || "PdmP032.csx",
params: {
tag: "Delete",
ids: v_ids
},
success: function(response) {
var res = Ext.util.JSON.decode(response.responseText);
if (res.success) {
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptSuccess);
grid.success(true, selectedRows);
}
else {
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptFailure);
}
mask.hide();
mask = null;
},
failure: function() {
Ext.Msg.alert(MsgMrg.OptMsg, MsgMrg.OptException);
mask.hide();
mask = null;
}
})
}
}, this);
}
})
}
/// <summary>
/// 删除
/// </summary>
/// <returns></returns>
private string Delete()
{
string ids = Request.Form["ids"];
if (StringUtil.isNotNullOrBlank(ids))
{
try
{
string[] id = ids.Split(',');
List<string> del_sql_list = new List<string>();
for (int i = 0; i < id.Length; i++)
{
string strsql = string.Format("DELETE DES_REV_NODE_CONFIG WHERE id={0}", id[i]);
del_sql_list.Add(strsql);
}
DbUtil.ExecuteSqlTran(del_sql_list);
}
catch (Exception ex)
{
return @"{msg:'" + StringUtil.convert(ex.Message) + "'}";
}
return BusinessMessage.SUCCESS;
}
else
{
return BusinessMessage.PLEASE_SELECT_A_RECORD;
}
}
保存
///保存功能按钮
var P032_Save = function (action_url, query_panel) {
return new Ext.Button({
id: 'P032_Save',
handler: function () {
var cPanel = query_panel.grid;
var func = query_panel.func;
if (cPanel) {
if (cPanel.validate()) {
if (cPanel.activeEditor != null) {
cPanel.activeEditor.completeEdit();
}
var mask = initPanelMask(query_panel);
mask.show();
Ext.Ajax.request({
url: action_url || "PdmP032.csx",
params: {
tag: "SaveOrUpdate",
data: cPanel.getValues(),
fields: cPanel.getStore().fields.keys.join(',')
},
success: function (response, p) {
var res = Ext.util.JSON.decode(response.responseText);
if (res.success) {
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptSuccess);
func();
cPanel.getStore().load({ params: { start: 0 } });
}
else {
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptFailure);
}
mask.hide();
mask = null;
},
failure: function (response, p) {
var res = Ext.util.JSON.decode(response.responseText);
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptSuccess);
mask.hide();
mask = null;
}
});
} else {
Ext.Msg.alert(MsgMrg.OptMsg, MsgMrg.OptDataIsLegal);
}
} else {
Ext.Msg.alert(MsgMrg.OptMsg, MsgMrg.OptCfmDataPanel);
}
}
});
}
/// <summary>
/// 保存或修改
/// </summary>
/// <returns></returns>
private string SaveOrUpdate()
{
if (StringUtil.isNotNullOrBlank(Request.Form["data"]))
{
try
{
string userid = Convert.ToString(Session["userid"]);
SaveAndUpdate(Request.Form["fields"].ToString(), Request.Form["data"].ToString(), userid);
return Erp.Ship.Tool.BusinessMessage.OPERATION_SUCCESS;
}
catch (Exception ex)
{
return (@"{msg:'" + StringUtil.convert(ex.Message) + "'}");
}
}
else
{
return (Erp.Ship.Tool.BusinessMessage.NO_DATA_PROCESSED);
}
}
public void SaveAndUpdate(string rfields, string rrecs, string userid)
{
try
{
List<string> l = new List<string>();
DES_REV_NODE_CONFIG obj = null;
string[] fields = rfields.ToLower().Split(DbUtil.fieldSplit);
string[] recs = rrecs.Split(DbUtil.rowSplit);
IList<DES_REV_NODE_CONFIG> list = JsonUtil.JosnToObjects<DES_REV_NODE_CONFIG>(fields, recs);
if (null != list && list.Count > 0)
{
obj = new DES_REV_NODE_CONFIG();
foreach (var item in list)
{
if (StringUtil.isNullOrBlank(item.ID))
{
item.DEF_DATE = item.UPD_DATE = DateTime.Now;
item.UPD_USR_ID = item.DEF_USR_ID = userid;
l.Add(item.GetInsertSql());
}
else
{
obj.ID = item.ID;
if (obj.Retrieve())
{
JsonUtil.ObjectToObject(fields, obj, item);
obj.UPD_USR_ID = userid;
obj.UPD_DATE = DateTime.Now;
l.Add(obj.GetUpdateSql());
}
}
}
DbUtil.ExecuteSqlTran(l);
}
}
catch (Exception e)
{
throw e;
}
}
导出
var O019_export = function (action_url, query_panel) {
return new Ext.Button({
id: 'O019_export',
handler: function () {
Ext.Msg.confirm(MsgMrg.OptMsg, "确定导出此此图纸下发明细信息?",
function (btn) {
if (btn == "yes") {
var p = {
TYPE: query_panel.GetS_Type(), //专业区分
PROJ: query_panel.GetF_PROJ(), //项目
SHIPNO: query_panel.GetShipNo(), //号船
DRAWNO: query_panel.GetDRAW_NO(), //图号
DRAWNAME: query_panel.GetDRAW_NAME(), //图名
ORDERNUM:query_panel.GetDRAW_No_Field() //下单单号
}
var str = Ext.urlEncode(p);
var top = ((document.body.clientHeight - 400) / 2);
var left = ((document.body.clientWidth - 600) / 2);
var win = window.document.open("PdmO019.csx?tag=Export&" + str, '_blank',
"location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no,left=" + left + ",top=" + top + ",width=600,height=400");
}
}, this);
}
});
}
private void Export()
{
try
{
S_VO v = new S_VO();
string query_sql = GetQuerySql();
string strWhere = string.Empty;
string s_type = Request["TYPE"]; //专业区分
if (s_type!="")
{
strWhere += string.Format(" AND DIF.DRAW_TYPE={0}",s_type);
}
string PROJ = Request["PROJ"]; //项目
if (PROJ != "")
{
strWhere += string.Format(" AND PRI.ID={0}", PROJ);
}
string SHIPNO = Request["SHIPNO"]; //号船
if (SHIPNO != "")
{
strWhere += string.Format(" AND PR.PROJ_NO={0}", SHIPNO);
}
string DRAWNO = Request["DRAWNO"]; //图号
if (DRAWNO != "")
{
strWhere += string.Format(" AND DL.DRAW_NO like '{0}'", DRAWNO);
}
string DRAWNAME = Request["DRAWNAME"]; //图名
if (DRAWNAME != "")
{
strWhere += string.Format(" AND DL.DRAW_NAME like '{0}'", DRAWNAME);
}
string ORDERNUM = Request["ORDERNUM"]; //下单单号
if (ORDERNUM != "")
{
strWhere += string.Format(" AND DIF.DRAW_NO like '{0}'", ORDERNUM);
}
#region 导出
Erp.Ship.Business.Pdm.ExeclBusiness.O019.O019Excel excel = new Erp.Ship.Business.Pdm.ExeclBusiness.O019.O019Excel();
excel.FileName = "图纸下发明细报表.xls";
DataTable dt = DbUtil.QueryDT(string.Format(query_sql, strWhere));
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("下发单号", "DRAW_NO");
dic.Add("项目", "PROJ_NAME");
dic.Add("号船", "PROJ_ID");
dic.Add("业务区分", "MSVALUE");
dic.Add("下发人", "USERNAME");
excel.SetDataTableAndDictionary(dt,dic);
if (dt.Rows.Count > 0)
{
string url = Server.MapPath("~/FileTemplate/Pdm/O000/O018/template1.xls");
byte[] data = excel.CreateExcel(url);
Response.AppendHeader("Content-Disposition", "attachment; filename=" + excel.FileName);//HttpUtility.UrlEncode(r.FileName, Encoding.UTF8));
Response.ContentType = "application/ms-excel";
Response.AddHeader("Content-Length", data.Length.ToString());
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.BinaryWrite(data);
}
else
{
Response.Write("当前条件下没有图纸上传报错记录!");
}
#endregion
}
catch (Exception ex)
{
throw ex;
}
}
导入
var D021_import = function (action_url, query_panel) {
return new Ext.Button({
id: 'D021_import',
handler: function () {
var projInfo = query_panel.getProjInfoId(); //项目
var projNo = query_panel.getProjNoId(); //船号
var plan_version = query_panel.getVersionId();
if (plan_version == "") {
prityTip("提示", "版本必须选择!");
return;
}
if (projInfo == null || projInfo == '') { prityTip("提示", "项目必须选择!"); return; }
if (projNo == null || projNo == '') { prityTip("提示", "船号必须选择!"); return; }
var win = D021_Import_Win(projInfo, projNo, plan_version);
win.show();
}
});
}
function D021_Import_Win(projInfo, projNo, plan_ver) {
var isReDo = false, isUp = false;
var downTemplateBtn = new Ext.Button({
text: '下载模板',
//iconCls: 'Icon16_file_down',
handler: function () {
var str = Ext.urlEncode({ tag: 'DownTemplate' });
var top = ((document.body.clientHeight - 200) / 2);
var left = ((document.body.clientWidth - 200) / 2);
var win = window.document.open("PdmD021.csx?" + str, '_blank', "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no,left=" + left + ",top=" + top + ",width=400,height=400");
}
});
var importTemplateBtn = new Ext.Button({
text: '导入数据',
disabled: true,
//iconCls: 'icon_page_white_get',
handler: function () {
if (fibasic.getValue() == '') {
Ext.Msg.alert(MsgMrg.OptMsg, MsgMrg.OptChooseImport);
return;
};
if (!isUp) {
Ext.MessageBox.show({
title: "警告",
msg: "请先上传文件,再导入!",
icon: Ext.MessageBox.WARNING,
buttons: Ext.MessageBox.OK
});
return;
}
if (isReDo) {
Ext.MessageBox.show({
title: "警告",
msg: "请不要重新导入!",
icon: Ext.MessageBox.WARNING,
buttons: Ext.MessageBox.OK
});
return;
}
var mask = initPanelMask(win);
mask.show();
Ext.Ajax.request({
url: "PdmD021.csx?tag=ImportTemplateData",
params: {
plan_ver: plan_ver
},
//timeout: 3000000,
success: function (response, p) {
var res = Ext.util.JSON.decode(response.responseText);
if (res.success) {
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptImportFailure);
fibasic.reset();
importTemplateBtn.disable();
uploadTemplateBtn.enable()
fibasic.enable();
isReDo = true;
}
else {
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptImportFailure);
}
if (mask) {
mask.hide();
mask = null;
}
},
failure: function (response, p) {
var res = Ext.util.JSON.decode(response.responseText);
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptImportException);
if (mask) {
mask.hide();
mask = null;
}
}
});
}
});
var closeBtn = new Ext.Button({
text: "关闭",
iconCls: 'Icon16_tp',
handler: function () {
win.close();
}
});
var fibasic = new Ext.ux.form.FileUploadField({
style: 'margin:3 5 0 2',
width: 400,
height: 40,
allowBlank: false,
buttonText: '浏览',
blankText: '文件不能为空'
});
var fieldLabel = new Ext.form.Label({
style: 'margin:6 6 6 6',
html: '数据文件' + prj.necessaryField + ': '
});
var upform = new Ext.form.FormPanel({
frame: true,
bodyStyle: 'padding:2px;',
fileUpload: true,
region: "north",
border: false,
labelWidth: 70,
layout: 'column',
items: [fieldLabel, fibasic],
margins: '3 0 3 3',
height: 40
});
var gridColumns = new Ext.grid.ColumnModel({
columns: [
{ header: "内码", dataIndex: "ID", hidden: true },
{
header: "项目", dataIndex: "SHIP_ID", renderer: ProjInfoStoreAll.toValue
},
{ header: "登记时间", dataIndex: "DEF_DATE", format: Date.patterns.ISO8601Short, xtype: 'datecolumn', hidden: true },
{ header: "登记人", dataIndex: "DEF_USR_ID", renderer: userStore.toValue, hidden: true }
]
});
var upstore = new Ext.data.JsonStore({ //数据集
url: "PdmD021.csx?tag=GetExcelTempData",
fields: ["ID", { name: "SHIP_ID", allowBlank: false },"RESP_USR", "UPD_USR_ID", "DEF_USR_ID",
{ name: "UPD_DATE", type: "date", dateFormat: Date.patterns.ISO8601Short }],
root: "data",
id: "id",
totalProperty: "totalCount"
})
function getBaseParams(v) {
var p = {
limit: pagebar.pageSize
};
Ext.apply(Ext.version.startsWith('3') ? v.baseParams : v.proxy.extraParams, p);
}
upstore.on('beforeload', getBaseParams);
var pagebar = new prj.util.PagingToolbar(upstore, 20);
var upgrid = new Ext.RSEGrid({
id: 'D021_upgrid',
border: 1,
ChgCheck: false,
loadMask: true,
store: upstore,
cm: gridColumns,
margins: '3 3 3 3',
cmargins: '3 3 3 3',
bbar: pagebar,
region: 'center'
});
var uploadTemplateBtn = new Ext.Button({
text: '上传数据',
//iconCls: 'Icon16_file_upload',
handler: function () {
if (!fibasic.validate()) {
Ext.Msg.alert("消息", "请选择文件后,再进行上传操作");
return;
}
var filePath = fibasic.getValue().toUpperCase();
if (!(filePath.indexOf('.XLS') > 0 || filePath.indexOf('.XLSX') > 0)) {
fibasic.reset();
Ext.Msg.alert(MsgMrg.OptMsg, "上传文件类型必须是Excel");
return;
}
var mask = initPanelMask(win);
mask.show();
upform.getForm().submit({
url: "PdmD021.csx",
params: {
tag: 'UploadTemplateData',
projInfo: projInfo,
projNo: projNo,
plan_ver: plan_ver
},
success: function (form, action) {
var res = Ext.util.JSON.decode(action.response.responseText);
if (action.result.success) {
upgrid.getStore().load({ params: { start: 0 } });
isReDo = false;
isUp = true;
importTemplateBtn.enable();
uploadTemplateBtn.disable()
fibasic.disable();
} else {
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptFileUpFailure);
}
if (mask) {
mask.hide();
mask = null;
}
},
failure: function (form, action) {
var res = Ext.util.JSON.decode(action.response.responseText);
Ext.Msg.alert(MsgMrg.OptMsg, res.msg || res.message || MsgMrg.OptFileUpFailure);
if (mask) {
mask.hide();
mask = null;
}
}
});
}
});
var win = new Ext.Window({
modal: true,
constrain: true,
closable: false,
frame: true,
ChgCheck: false,
width: 800,
height: 500,
layout: "fit",
resizable: false,
closeAction: "hide",
layout: 'border',
id: "D021_Import_Win",
title: "非图任务计划导入",
tbar: [downTemplateBtn, '-', uploadTemplateBtn, '-', importTemplateBtn, '->', closeBtn],
items: [upform, upgrid],
})
return win;
}
下载模块
private void DownTemplate()
{
try
{
S_VO v = new S_VO();
Erp.Ship.Business.Pdm.ExeclBusiness.O019.O019Excel excel = new Erp.Ship.Business.Pdm.ExeclBusiness.O019.O019Excel();
excel.FileName = "图纸下发明细报表.xls";
DataTable dt = new DataTable();
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("下发单号", "DRAW_NO");
dic.Add("项目", "PROJ_NAME");
dic.Add("号船", "PROJ_ID");
dic.Add("业务区分", "MSVALUE");
dic.Add("下发人", "USERNAME");
excel.SetDataTableAndDictionary(dt,dic);
string url = Server.MapPath("~/FileTemplate/template.xlsx");
byte[] data = excel.CreateExcel(url);
Response.AppendHeader("Content-Disposition", "attachment; filename=" + excel.FileName);//HttpUtility.UrlEncode(r.FileName, Encoding.UTF8));
Response.ContentType = "application/ms-excel";
Response.AddHeader("Content-Length", data.Length.ToString());
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.BinaryWrite(data);
}
catch (Exception ex)
{
throw ex;
}
}
上传
private string UploadTemplateData()
{
try
{
string filename = null, fullName = null;
string savePath = null, fileType = null;
DataTable fdt = null, ndt = null; //文件数据,重新组织的结构
DataRow ndr = null; //文件数据行,重新组织的结构数据行
string user_id = Session["user_id"].ToString();
string projInfo = Request["projInfo"]; //项目
string projNo = Request["projNo"]; //船号
string plan_version = Request["plan_ver"]; //计划版本内码
string query_not_list_id_sql = "SELECT ID FROM GENERAL_DES_TASK WHERE TASK_CODE='{0}'";
DataTable dt_not_list_id = new DataTable();
if (IfReleasePlan(plan_version))
{
return @"{msg:'该版本已发布,不能上传文件!'}";
}
//依次:项目、船号、专业、任务类型、任务编号、任务名称、责任人、计划开始、计划结束、实际开始、实际结束、内码
string SHIP_ID = string.Empty, PROJ_NO = string.Empty, PROFESSION_DEF_ID = string.Empty, STANDA_SCHEDULE_NODE_ID = string.Empty, TASK_CODE = string.Empty, TASK_NAME = string.Empty, RESP_USR = string.Empty, PLAN_BEGIN = string.Empty, PLAN_END = string.Empty, ACTUAL_BEGIN = string.Empty, ACTUAL_END = string.Empty, ID = string.Empty;
if (Request.Files.Count > 0)
{
#region 上传文件读取
savePath = Server.MapPath(@"~/form/IPTExecel/updData/");
if (!Directory.Exists(savePath)) //检查在服务器上是否存在同名文件夹
{
Directory.CreateDirectory(savePath);
}
HttpPostedFile postedFile = Request.Files[0];
filename = Path.GetFileName(postedFile.FileName);
fullName = savePath + filename;
if (File.Exists(fullName)) //检查在服务器上是否存在同名文件
{
File.Delete(fullName);
}
postedFile.SaveAs(fullName);
fdt = new DataTable();
string[] sp = filename.Split('.');
fileType = sp[sp.Length - 1];
switch (fileType)
{
case "xls":
fdt = ExcelUtil.GetDataTableFromExcel(fullName);
break;
case "xlsx":
fdt = ExcelUtil.GetDataTableFromExcel(fullName);
break;
}
File.Delete(fullName);
#endregion
#region 设置列头
ndt = new DataTable();
ndt.Columns.Add("ID"); //项目
ndt.Columns.Add("SHIP_ID"); //项目
ndt.Columns.Add("PROJ_NO"); //船号
ndt.Columns.Add("PROFESSION_DEF_ID"); //专业
ndt.Columns.Add("STANDA_SCHEDULE_NODE_ID"); //任务类型
ndt.Columns.Add("TASK_CODE"); //任务编号
ndt.Columns.Add("TASK_NAME"); //任务名称
ndt.Columns.Add("RESP_USR"); //责任人
ndt.Columns.Add("PLAN_BEGIN"); //计划开始
ndt.Columns.Add("PLAN_END"); //计划结束
ndt.Columns.Add("ACTUAL_BEGIN"); //实际开始
ndt.Columns.Add("ACTUAL_END"); //实际结束
#endregion
if (fdt.Columns.Count != 11)
{
return @"{msg:'请检查上传文件模板是否正确!'}";
}
#region 赋值
if (fdt.Rows.Count > 2)
{
for (int i = 2; i < fdt.Rows.Count; i++)
{
ndr = ndt.NewRow();
ndr.BeginEdit();
SHIP_ID = fdt.Rows[i][0].ToString().Trim();
PROJ_NO = fdt.Rows[i][1].ToString().Trim();
PROFESSION_DEF_ID = fdt.Rows[i][2].ToString().Trim();
STANDA_SCHEDULE_NODE_ID = fdt.Rows[i][3].ToString().Trim();
TASK_CODE = fdt.Rows[i][4].ToString().Trim();
TASK_NAME = fdt.Rows[i][5].ToString().Trim();
RESP_USR = fdt.Rows[i][6].ToString().Trim();
PLAN_BEGIN = fdt.Rows[i][7].ToString().Trim();
PLAN_END = fdt.Rows[i][8].ToString().Trim();
ACTUAL_BEGIN = fdt.Rows[i][9].ToString().Trim();
ACTUAL_END = fdt.Rows[i][10].ToString().Trim();
if (TASK_CODE == "")
{
throw new Exception("任务编号不能为空!");
}
dt_not_list_id = DbUtil.QueryDT(string.Format(query_not_list_id_sql, TASK_CODE));
if (dt_not_list_id.Rows.Count == 0)
{
throw new Exception(string.Format("任务编号【{0}】无效!", TASK_CODE));
}
ID = dt_not_list_id.Rows[0][0].ToString();
if ((PLAN_BEGIN == "" && PLAN_END != "") || (PLAN_BEGIN != "" && PLAN_END == ""))
{
throw new Exception(string.Format("计划开始【{0}】计划结束【{1}】未同时输入!", PLAN_BEGIN, PLAN_END));
}
if (PLAN_BEGIN != "")
{
if (!IsDate(PLAN_BEGIN))
{
throw new Exception(string.Format("计划开始【{0}】不是日期类型", PLAN_BEGIN));
}
}
if (PLAN_END != "")
{
if (!IsDate(PLAN_END))
{
throw new Exception(string.Format("计划结束【{0}】不是日期类型", PLAN_END));
}
}
if (ACTUAL_BEGIN != "")
{
if (!IsDate(ACTUAL_BEGIN))
{
throw new Exception(string.Format("实际开始【{0}】不是日期类型", ACTUAL_BEGIN));
}
}
if (ACTUAL_END != "")
{
if (!IsDate(ACTUAL_END))
{
throw new Exception(string.Format("实际结束【{0}】不是日期类型", ACTUAL_END));
}
}
ndr["ID"] = ID; //内码
ndr["SHIP_ID"] = SHIP_ID; //项目
ndr["PROJ_NO"] = PROJ_NO; //船号
ndr["PROFESSION_DEF_ID"] = PROFESSION_DEF_ID; //专业
ndr["STANDA_SCHEDULE_NODE_ID"] = STANDA_SCHEDULE_NODE_ID; //任务类型
ndr["TASK_CODE"] = TASK_CODE; //任务编号
ndr["TASK_NAME"] = TASK_NAME; //任务名称
ndr["RESP_USR"] = RESP_USR; //责任人
ndr["PLAN_BEGIN"] = PLAN_BEGIN; //计划开始
ndr["PLAN_END"] = PLAN_END; //计划结束
ndr["ACTUAL_BEGIN"] = ACTUAL_BEGIN; //实际开始
ndr["ACTUAL_END"] = ACTUAL_END; //实际结束
ndr.EndEdit();
ndt.Rows.Add(ndr);
}
}
#endregion
}
else
{
return @"{msg:'上传文件没有数据!'}";
}
Session["D021ExcelTempData"] = ndt;
return new JSONHelper().CreateExtGrid(ndt);
}
catch (Exception ex)
{
return @"{msg:'" + StringUtil.convert(ex.Message) + "'}";
}
}
导入
private string ImportTemplateData()
{
try
{
DataTable dt = (DataTable)Session["D021ExcelTempData"];
List<string> list_sql = new List<string>();
string userid = Session["userid"].ToString();//当前用户
string plan_version = Request["plan_ver"]; //计划版本内码
if (IfReleasePlan(plan_version))
{
return @"{msg:'该版本已发布,不能导入文件!'}";
}
DateTime nowDate = DateTime.Now; //当前日期
//依次:内码、计划开始、计划结束、实际开始、实际结束
string ID = string.Empty, PLAN_BEGIN = string.Empty, PLAN_END = string.Empty, ACTUAL_BEGIN = string.Empty, ACTUAL_END = string.Empty;
//新增设计计划
string add_sql = @"INSERT INTO DESIGN_SCHEDULE
(DRAW_PLAN_VERSION_ID,
TASK_ID,
PLAN_BEGIN,
PLAN_END,
DEF_USR_ID,
DEF_DATE,
UPD_USR_ID,
UPD_DATE)
VALUES
({0},
{1},
to_date('{2}', 'yyyy-mm-dd hh24:mi:ss'),
to_date('{3}', 'yyyy-mm-dd hh24:mi:ss'),
'{4}',
to_date('{5}', 'yyyy-mm-dd hh24:mi:ss'),
'{4}',
to_date('{5}', 'yyyy-mm-dd hh24:mi:ss'))";
//修改设计计划
string update_sql = @"UPDATE DESIGN_SCHEDULE
SET PLAN_BEGIN = to_date('{0}', 'yyyy-mm-dd hh24:mi:ss'),
PLAN_END = to_date('{1}', 'yyyy-mm-dd hh24:mi:ss'),
UPD_USR_ID = '{2}',
UPD_DATE = to_date('{3}', 'yyyy-mm-dd hh24:mi:ss')
WHERE TASK_ID = {4}
AND DRAW_PLAN_VERSION_ID = {5}";
string update_sql2 = "UPDATE GENERAL_DES_TASK SET ACTUAL_BEGIN={0},ACTUAL_END={1},UPD_USR_ID='{2}',UPD_DATE=to_date('{3}','yyyy-mm-dd hh24:mi:ss') WHERE ID={4}";
if (dt.Rows.Count > 1)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
ID = dt.Rows[i]["ID"].ToString();//内码
PLAN_BEGIN = dt.Rows[i]["PLAN_BEGIN"].ToString(); //计划开始
PLAN_END = dt.Rows[i]["PLAN_END"].ToString(); //计划结束
ACTUAL_BEGIN = dt.Rows[i]["ACTUAL_BEGIN"].ToString(); //实际开始
ACTUAL_END = dt.Rows[i]["ACTUAL_END"].ToString(); //实际结束
dt_if_design_plan = DbUtil.QueryDT(string.Format(query_if_design_plan_exist_sql, ID, plan_version));
if (dt_if_design_plan.Rows.Count == 0)
{
list_sql.Add(string.Format(add_sql, plan_version, ID, PLAN_BEGIN, PLAN_END, userid, nowDate));
}
else
{
list_sql.Add(string.Format(update_sql, PLAN_BEGIN, PLAN_END, userid, nowDate, ID, plan_version));
}
list_sql.Add(string.Format(update_sql2, ACTUAL_BEGIN == "" ? "null" : "to_date('" + ACTUAL_BEGIN + "','yyyy-mm-dd hh24:mi:ss')", ACTUAL_END == "" ? "null" : "to_date('" + ACTUAL_END + "','yyyy-mm-dd hh24:mi:ss')", userid, nowDate, ID));
}
DbUtil.ExecuteSqlTran(list_sql);
return "{success:true,msg:'导入成功'}";
}
else
{
return "{success:false,msg:'没有数据需要导入!'}";
}
}
catch (Exception ex)
{
throw ex;
}
}