/// <summary> /// 将备注信息数据保存到数据库 /// </summary> /// <param name="dataSet1"></param> public static void SaveRemarksInfo(DataSet dataSet1) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); cmd.CommandText = "select Top 0 * from SA_RemarksInfo "; SqlDataAdapter adp = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adp.Fill(dt); BaseSQL.UpdateDataTable(adp, dataSet1.Tables["RemarksInfo"]); trans.Commit(); } catch (Exception ex) { trans.Rollback(); dataSet1.Tables["RemarksInfo"].RejectChanges(); throw ex; } } } }
/// <summary> /// 保存付款类型信息 /// </summary> public bool SavePayTypeList(DataTable updateDataTable, string payTypeNoStr) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); cmd.CommandText = "select * from PUR_PayTypeList where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, updateDataTable); //cmd.CommandText = string.Format("select * from PUR_PayTypeList where PayTypeNo='{0}'", payTypeNoStr); //adapterHead = new SqlDataAdapter(cmd); //tmpHeadTable.Rows.Clear(); //adapterHead.Fill(tmpHeadTable); cmd.CommandText = string.Format("select Sum(PayPercentum) from PUR_PayTypeList where PayTypeNo='{0}'", payTypeNoStr); int sumInt = DataTypeConvert.GetInt(cmd.ExecuteScalar()); if (sumInt != 100) { trans.Rollback(); //MessageHandler.ShowMessageBox("付款百分比的合计必须是100,请查询后再重新操作。"); MessageHandler.ShowMessageBox(f.tsmiFkbfbd.Text); return(false); } //保存日志到日志表中 string logStr = "对[付款类型信息]表进行[修改]操作:"; for (int i = 0; i < updateDataTable.Rows.Count; i++) { logStr += string.Format("主键的值为[{0}]百分比的值为[{1}]说明的值为[{2}];", updateDataTable.Rows[i]["AutoId"].ToString(), updateDataTable.Rows[i]["PayPercentum"].ToString(), updateDataTable.Rows[i]["PayPercentumText"].ToString()); } LogHandler.RecordLog(cmd, logStr); trans.Commit(); return(true); } catch (Exception ex) { trans.Rollback(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 执行删除 /// </summary> private bool DoDelete(DataRow updateRow) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); if (DeleteRowBefore != null) { if (!DeleteRowBefore(updateRow, cmd)) { trans.Rollback(); updateRow.Table.RejectChanges(); return(false); } } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, TableCaption, updateRow, PrimaryKeyColumn); cmd.CommandText = string.Format("select * from {0} where 1=2", TableName); SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, updateRow.Table); if (DeleteRowAfter != null) { if (!DeleteRowAfter(updateRow, cmd)) { trans.Rollback(); updateRow.Table.RejectChanges(); return(false); } } trans.Commit(); return(true); } catch (Exception ex) { trans.Rollback(); updateRow.Table.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存流程表 /// </summary> /// <param name="headRow">流程图主表行信息</param> /// <param name="connectorList">流程图中的所有连接线列表</param> /// <param name="shapeList">流程图中的所有状态节点列表</param> public int SaveWorkFlow(DataRow headRow, List <DiagramConnector> connectorList, List <DiagramShape> shapeList) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); DateTime nowTime = BaseSQL.GetServerDateTime(); int autoIdInt = 0; if (DataTypeConvert.GetInt(headRow["Enabled"]) == 1 && CheckWorkFlowType(cmd, DataTypeConvert.GetInt(headRow["AutoId"]), DataTypeConvert.GetInt(headRow["WorkFlowsType"]))) { //headRow.Table.RejectChanges(); return(0); } if (headRow.RowState == DataRowState.Added)//新增 { if (DataTypeConvert.GetInt(headRow["Enabled"]) == 1) { headRow["EnabledTime"] = nowTime; } else { headRow["EnabledTime"] = DBNull.Value; } //新增保存流程主表 cmd.CommandText = string.Format("Insert into BS_WorkFlows (WorkFlowsText, WorkFlowsType, Enabled, Remark, EnabledTime, IndexNo, NextWorkFlowsType) values ('{0}', {1}, {2}, '{3}', {4}, (select IsNull(Max(IndexNo), 0) + 1 from BS_WorkFlows), {5})", DataTypeConvert.GetString(headRow["WorkFlowsText"]), DataTypeConvert.GetInt(headRow["WorkFlowsType"]), DataTypeConvert.GetInt(headRow["Enabled"]), DataTypeConvert.GetString(headRow["Remark"]), DataTypeConvert.GetInt(headRow["Enabled"]) == 1 ? "'" + nowTime.ToString("yyyy-MM-dd HH:mm:ss") + "'" : "Null", DataTypeConvert.GetInt(headRow["NextWorkFlowsType"])); autoIdInt = cmd.ExecuteNonQuery(); if (autoIdInt != 1) { trans.Rollback(); headRow.Table.RejectChanges(); MessageHandler.ShowMessageBox("保存流程图信息错误,请重新新增操作。"); return(-1); } cmd.CommandText = "select @@IDENTITY"; autoIdInt = DataTypeConvert.GetInt(cmd.ExecuteScalar()); headRow["AutoId"] = autoIdInt; InsertWorkFlowNodeInfo(cmd, autoIdInt, connectorList, shapeList); } else//修改 { if (DataTypeConvert.GetInt(headRow["Enabled", DataRowVersion.Original]) != DataTypeConvert.GetInt(headRow["Enabled", DataRowVersion.Current])) { if (DataTypeConvert.GetInt(headRow["Enabled"]) == 1) { headRow["EnabledTime"] = nowTime; } else { headRow["EnabledTime"] = DBNull.Value; } } //修改保存流程主表 cmd.CommandText = "select * from BS_WorkFlows where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, headRow.Table); autoIdInt = DataTypeConvert.GetInt(headRow["AutoId"]); UpdateWorkFlowNodeInfo(cmd, autoIdInt, connectorList, shapeList); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "流程图信息", headRow, "AutoId"); trans.Commit(); headRow.AcceptChanges(); return(1); } catch (Exception ex) { trans.Rollback(); headRow.Table.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存工位信息 /// </summary> public int SaveStnSummaryList(string autoQuotationNoStr, DataRow headRow, ref int lastNewStnListAutoId) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); DateTime nowTime = BaseSQL.GetServerDateTime(); bool addState = false; if (headRow.RowState == DataRowState.Added)//新增 { if (DataTypeConvert.GetString(headRow["SSNo"]) == "") { string ssNoStr = BaseSQL.GetMaxCodeNo(cmd, "SS"); cmd.CommandText = string.Format("Insert into SA_StnSummary(SSNo, AutoQuotationNo, Creator, PreparedIp, GetTime) values ('{0}', '{1}', {2}, '{3}', '{4}')", ssNoStr, autoQuotationNoStr, SystemInfo.user.AutoId, SystemInfo.HostIpAddress, nowTime.ToString("yyyy-MM-dd HH:mm:ss")); cmd.ExecuteNonQuery(); headRow["SSNo"] = ssNoStr; } headRow["Creator"] = SystemInfo.user.AutoId; headRow["PreparedIp"] = SystemInfo.HostIpAddress; headRow["GetTime"] = nowTime; addState = true; } else//修改 { //int autoIdInt = DataTypeConvert.GetInt(headRow["AutoId"]); //if (CheckStnList_IsModule(cmd, autoIdInt)) //{ // headRow.Table.RejectChanges(); // return -1; //} } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "工位明细信息", headRow, "AutoId"); cmd.CommandText = "select * from SA_StnSummaryList where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, headRow.Table); if (addState) { cmd.CommandText = "Select @@IDENTITY"; lastNewStnListAutoId = DataTypeConvert.GetInt(cmd.ExecuteScalar()); } trans.Commit(); return(1); } catch (Exception ex) { trans.Rollback(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存预算外出库单 /// </summary> /// <param name="swrHeadRow">预算外出库单表头数据表</param> /// <param name="swrListTable">预算外出库单明细数据表</param> public int SaveSpecialWarehouseReceipt(DataRow swrHeadRow, DataTable swrListTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); DateTime serverTime = BaseSQL.GetServerDateTime(); FrmWarehouseCommonDAO whDAO = new FrmWarehouseCommonDAO(); if (!whDAO.IsSaveWarehouseOrder(cmd, swrHeadRow, DataTypeConvert.GetDateTime(swrHeadRow["SpecialWarehouseReceiptDate"]))) { return(0); } //if (DataTypeConvert.GetString(swwHeadRow["SpecialWarehouseReceipt"]) == "")//新增 if (swrHeadRow.RowState == DataRowState.Added)//新增 { string swwNo = BaseSQL.GetMaxCodeNo(cmd, "SR"); swrHeadRow["SpecialWarehouseReceipt"] = swwNo; swrHeadRow["PreparedIp"] = SystemInfo.HostIpAddress; for (int i = 0; i < swrListTable.Rows.Count; i++) { swrListTable.Rows[i]["SpecialWarehouseReceipt"] = swwNo; } } else//修改 { if (!CheckWarehouseState(swrHeadRow.Table, swrListTable, string.Format("'{0}'", DataTypeConvert.GetString(swrHeadRow["SpecialWarehouseReceipt"])), false, true, true, true)) { return(-1); } swrHeadRow["ModifierId"] = SystemInfo.user.AutoId; //swrHeadRow["Modifier"] = SystemInfo.user.EmpName; swrHeadRow["ModifierIp"] = SystemInfo.HostIpAddress; swrHeadRow["ModifierTime"] = serverTime; } string swrNoStr = DataTypeConvert.GetString(swrHeadRow["SpecialWarehouseReceipt"]); DataTable dbListTable = new DataTable(); if (swrHeadRow.RowState != DataRowState.Added) { cmd.CommandText = string.Format("select CodeId, CodeFileName, head.RepertoryId, head.RepertoryLocationId, ProjectNo, list.ShelfId, Sum(Qty) as Qty from INV_SpecialWarehouseReceiptList as list left join INV_SpecialWarehouseReceiptHead as head on list.SpecialWarehouseReceipt = head.SpecialWarehouseReceipt left join BS_ProjectList on list.ProjectName = BS_ProjectList.ProjectName where list.SpecialWarehouseReceipt = '{0}' group by CodeId, CodeFileName, head.RepertoryId, head.RepertoryLocationId, ProjectNo, list.ShelfId", swrNoStr); SqlDataAdapter dbListAdapter = new SqlDataAdapter(cmd); dbListAdapter.Fill(dbListTable); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "预算外出库单", swrHeadRow, "SpecialWarehouseReceipt"); cmd.CommandText = "select * from INV_SpecialWarehouseReceiptHead where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, swrHeadRow.Table.GetChanges()); cmd.CommandText = "select * from INV_SpecialWarehouseReceiptList where 1=2"; SqlDataAdapter adapterList = new SqlDataAdapter(cmd); DataTable tmpListTable = new DataTable(); adapterList.Fill(tmpListTable); BaseSQL.UpdateDataTable(adapterList, swrListTable.GetChanges()); //Set_OrderHead_End(cmd, swwListTable); if (whDAO.SaveUpdate_WarehouseNowInfo(conn, trans, cmd, swrHeadRow, swrListTable.Copy(), swrNoStr, dbListTable, "预算外出库单", "出库", false) != 1) { return(0); } if (SystemInfo.InventorySaveApproval) { //cmd.CommandText = string.Format("Insert into PUR_OrderApprovalInfo(OrderHeadNo, Approver, ApproverTime) values ('{0}', {1}, '{2}')", swrNoStr, SystemInfo.user.AutoId, serverTime.ToString("yyyy-MM-dd HH:mm:ss")); //cmd.ExecuteNonQuery(); //logStr = LogHandler.RecordLog_OperateRow(cmd, "预算外出库单", swrHeadRow, "SpecialWarehouseReceipt", "审批", SystemInfo.user.EmpName, serverTime.ToString("yyyy-MM-dd HH:mm:ss")); new PURDAO.FrmApprovalDAO().InventorySaveApproval(cmd, swrHeadRow, "预算外出库单", "SpecialWarehouseReceipt", swrNoStr, serverTime); cmd.CommandText = string.Format("Update INV_SpecialWarehouseReceiptHead set WarehouseState=2 where SpecialWarehouseReceipt='{0}'", swrNoStr); cmd.ExecuteNonQuery(); swrHeadRow["WarehouseState"] = 2; } trans.Commit(); swrHeadRow.Table.AcceptChanges(); swrListTable.AcceptChanges(); return(1); } catch (Exception ex) { trans.Rollback(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存采购结账单 /// </summary> /// <param name="SettlementHeadRow">结账单表头数据表</param> /// <param name="SettlementListTable">结账单明细数据表</param> public int SaveSettlement(DataRow SettlementHeadRow, DataTable SettlementListTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); if (!CheckWarehouseWarrantApplyBeyondCount(cmd, DataTypeConvert.GetString(SettlementHeadRow["SettlementNo"]), SettlementListTable)) { return(0); } //if (DataTypeConvert.GetString(SettlementHeadRow["SettlementNo"]) == "")//新增 if (SettlementHeadRow.RowState == DataRowState.Added)//新增 { string psNo = BaseSQL.GetMaxCodeNo(cmd, "PS"); SettlementHeadRow["SettlementNo"] = psNo; SettlementHeadRow["PreparedIp"] = SystemInfo.HostIpAddress; for (int i = 0; i < SettlementListTable.Rows.Count; i++) { SettlementListTable.Rows[i]["SettlementNo"] = psNo; } } else//修改 { if (!CheckWarehouseState(SettlementHeadRow.Table, SettlementListTable, string.Format("'{0}'", DataTypeConvert.GetString(SettlementHeadRow["SettlementNo"])), false, true, true, true)) { return(-1); } SettlementHeadRow["ModifierId"] = SystemInfo.user.AutoId; //SettlementHeadRow["Modifier"] = SystemInfo.user.EmpName; SettlementHeadRow["ModifierIp"] = SystemInfo.HostIpAddress; SettlementHeadRow["ModifierTime"] = BaseSQL.GetServerDateTime(); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "采购结账单", SettlementHeadRow, "SettlementNo"); cmd.CommandText = "select * from PUR_SettlementHead where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, SettlementHeadRow.Table.GetChanges()); cmd.CommandText = "select * from PUR_SettlementList where 1=2"; SqlDataAdapter adapterList = new SqlDataAdapter(cmd); DataTable tmpListTable = new DataTable(); adapterList.Fill(tmpListTable); BaseSQL.UpdateDataTable(adapterList, SettlementListTable.GetChanges()); Set_WWHead_End(cmd, SettlementListTable); trans.Commit(); SettlementHeadRow.Table.AcceptChanges(); SettlementListTable.AcceptChanges(); return(1); } catch (Exception ex) { trans.Rollback(); SettlementHeadRow.Table.RejectChanges(); SettlementListTable.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存采购询价单 /// </summary> /// <param name="inquiryHeadRow">采购询价单表头数据表</param> /// <param name="inquiryListTable">采购询价单明细数据表</param> /// <param name="PIPRTable">采购询价单明细和PR明细关系表</param> public int SaveInquiry(DataRow inquiryHeadRow, DataTable inquiryListTable, DataTable PIPRTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); if (!CheckBeyondPrReqCount(cmd, PIPRTable)) { return(0); } if (inquiryHeadRow.RowState == DataRowState.Added)//新增 { string piHeadNo = BaseSQL.GetMaxCodeNo(cmd, "PI"); inquiryHeadRow["PIHeadNo"] = piHeadNo; inquiryHeadRow["CreatorIp"] = SystemInfo.HostIpAddress; inquiryHeadRow["OrderHeadDate"] = BaseSQL.GetServerDateTime(); for (int i = 0; i < inquiryListTable.Rows.Count; i++) { inquiryListTable.Rows[i]["PIHeadNo"] = piHeadNo; } } else//修改 { inquiryHeadRow["Modifier"] = SystemInfo.user.AutoId; inquiryHeadRow["ModifierIp"] = SystemInfo.HostIpAddress; inquiryHeadRow["ModifierTime"] = BaseSQL.GetServerDateTime(); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "询价单", inquiryHeadRow, "PIHeadNo"); cmd.CommandText = "select * from PUR_InquiryHead where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, inquiryHeadRow.Table.GetChanges()); for (int i = 0; i < inquiryListTable.Rows.Count; i++) { DataRow tmpRow = inquiryListTable.Rows[i]; switch (tmpRow.RowState) { case DataRowState.Added: cmd.CommandText = string.Format("INSERT INTO PUR_InquiryList(PIHeadNo, CodeId, Qty, UnitPrice, Amount, Tax, TaxAmount, SumAmount, Remark) VALUES ('{0}', {1}, {2}, {3}, {4}, {5}, {6}, {7}, '{8}')", DataTypeConvert.GetString(tmpRow["PIHeadNo"]), DataTypeConvert.GetInt(tmpRow["CodeId"]), DataTypeConvert.GetDouble(tmpRow["Qty"]), DataTypeConvert.GetDouble(tmpRow["UnitPrice"]), DataTypeConvert.GetDouble(tmpRow["Amount"]), DataTypeConvert.GetDouble(tmpRow["Tax"]), DataTypeConvert.GetDouble(tmpRow["TaxAmount"]), DataTypeConvert.GetDouble(tmpRow["SumAmount"]), DataTypeConvert.GetString(tmpRow["Remark"])); cmd.ExecuteNonQuery(); cmd.CommandText = string.Format("select @@IDENTITY"); int autoId = DataTypeConvert.GetInt(cmd.ExecuteScalar()); DataRow[] drs = PIPRTable.Select(string.Format("PIListId={0}", inquiryListTable.Rows[i]["AutoId"])); foreach (DataRow dr in drs) { dr["PIListId"] = autoId; } break; case DataRowState.Modified: cmd.CommandText = string.Format("UPDATE PUR_InquiryList SET PIHeadNo = '{1}', CodeId = {2}, Qty = {3}, UnitPrice = {4}, Amount = {5}, Tax = {6}, TaxAmount = {7}, SumAmount = {8}, Remark = '{9}' WHERE AutoId = {0}", DataTypeConvert.GetInt(tmpRow["AutoId"]), DataTypeConvert.GetString(tmpRow["PIHeadNo"]), DataTypeConvert.GetInt(tmpRow["CodeId"]), DataTypeConvert.GetDouble(tmpRow["Qty"]), DataTypeConvert.GetDouble(tmpRow["UnitPrice"]), DataTypeConvert.GetDouble(tmpRow["Amount"]), DataTypeConvert.GetDouble(tmpRow["Tax"]), DataTypeConvert.GetDouble(tmpRow["TaxAmount"]), DataTypeConvert.GetDouble(tmpRow["SumAmount"]), DataTypeConvert.GetString(tmpRow["Remark"])); cmd.ExecuteNonQuery(); break; } } cmd.CommandText = "select * from PUR_PIPR where 1=2"; SqlDataAdapter adapterList = new SqlDataAdapter(cmd); DataTable tmpPIPRTable = new DataTable(); adapterList.Fill(tmpPIPRTable); BaseSQL.UpdateDataTable(adapterList, PIPRTable.GetChanges()); for (int i = 0; i < inquiryListTable.Rows.Count; i++) { DataRow tmpRow = inquiryListTable.Rows[i]; switch (tmpRow.RowState) { case DataRowState.Deleted: cmd.CommandText = string.Format("Delete from PUR_InquiryList where AutoId = {0}", DataTypeConvert.GetInt(tmpRow["AutoId", DataRowVersion.Original])); cmd.ExecuteNonQuery(); break; } } //Set_PrReqHead_End(cmd, inquiryListTable); trans.Commit(); inquiryHeadRow.Table.AcceptChanges(); inquiryListTable.AcceptChanges(); PIPRTable.AcceptChanges(); return(1); } catch (Exception ex) { trans.Rollback(); inquiryHeadRow.Table.RejectChanges(); inquiryListTable.RejectChanges(); PIPRTable.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存库存调整单 /// </summary> /// <param name="IAHeadRow">库存调整单表头数据表</param> /// <param name="IAListTable">库存调整单明细数据表</param> public int SaveInventoryAdjustments(DataRow IAHeadRow, DataTable IAListTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); DateTime serverTime = BaseSQL.GetServerDateTime(); FrmWarehouseCommonDAO whDAO = new FrmWarehouseCommonDAO(); if (!whDAO.IsSaveWarehouseOrder(cmd, IAHeadRow, DataTypeConvert.GetDateTime(IAHeadRow["InventoryAdjustmentsDate"]))) { return(0); } for (int i = 0; i < IAListTable.Rows.Count; i++) { if (IAListTable.Rows[i].RowState == DataRowState.Deleted) { continue; } IAListTable.Rows[i]["InventoryAdjustmentsDate"] = IAHeadRow["InventoryAdjustmentsDate"]; IAListTable.Rows[i]["RepertoryId"] = IAHeadRow["RepertoryId"]; IAListTable.Rows[i]["LocationId"] = IAHeadRow["LocationId"]; IAListTable.Rows[i]["ProjectNo"] = IAHeadRow["ProjectNo"]; } ////检查当前库存数是否满足 //if (!SystemInfo.EnableNegativeInventory && !CheckWarehouseNowInfoBeyondCount(cmd, DataTypeConvert.GetString(IAHeadRow["InventoryMoveNo"]), IAListTable)) //{ // return 0; //} //if (DataTypeConvert.GetString(IAHeadRow["InventoryAdjustmentsNo"]) == "")//新增 if (IAHeadRow.RowState == DataRowState.Added)//新增 { string iaNo = BaseSQL.GetMaxCodeNo(cmd, "IA"); IAHeadRow["InventoryAdjustmentsNo"] = iaNo; IAHeadRow["CreatorIp"] = SystemInfo.HostIpAddress; for (int i = 0; i < IAListTable.Rows.Count; i++) { IAListTable.Rows[i]["InventoryAdjustmentsNo"] = iaNo; } } else//修改 { if (!CheckWarehouseState(IAHeadRow.Table, IAListTable, string.Format("'{0}'", DataTypeConvert.GetString(IAHeadRow["InventoryAdjustmentsNo"])), false, true, true, true)) { return(-1); } IAHeadRow["Modifier"] = SystemInfo.user.AutoId; IAHeadRow["ModifierIp"] = SystemInfo.HostIpAddress; IAHeadRow["ModifierTime"] = serverTime; } string iaNoStr = DataTypeConvert.GetString(IAHeadRow["InventoryAdjustmentsNo"]); #region 单独提出为通用方法 //string errorText = ""; //int affectedRowNo = 0; //if (IAHeadRow.RowState != DataRowState.Added) //{ // SqlCommand cmd_proc_cancel = new SqlCommand("", conn, trans); // if (!new FrmWarehouseNowInfoDAO().Update_WarehouseNowInfo(cmd_proc_cancel, iaNoStr, 2, out errorText)) // { // trans.Rollback(); // MessageHandler.ShowMessageBox("库存调整单取消入库错误--" + errorText); // return 0; // } //} //if (IAHeadRow.RowState == DataRowState.Added) //{ //} //else //{ // cmd.CommandText = string.Format("select CodeFileName, head.RepertoryId, head.LocationId, head.ProjectNo, list.ShelfId, Sum(Qty) as Qty from INV_InventoryAdjustmentsList as list left join INV_InventoryAdjustmentsHead as head on list.InventoryAdjustmentsNo = head.InventoryAdjustmentsNo where list.InventoryAdjustmentsNo = '{0}' group by CodeFileName, head.RepertoryId, head.LocationId, head.ProjectNo, list.ShelfId", iaNoStr); // SqlDataAdapter dbListAdapter = new SqlDataAdapter(cmd); // DataTable dbListTable = new DataTable(); // dbListAdapter.Fill(dbListTable); // DataTable copyNewTable = IAListTable.GetChanges(); // copyNewTable.AcceptChanges(); // foreach (DataRow dbRow in dbListTable.Rows) // { // string tmpCodeFileName = DataTypeConvert.GetString(dbRow["CodeFileName"]); // int tmpRepertoryId = DataTypeConvert.GetInt(dbRow["RepertoryId"]); // int tmpLocationId = DataTypeConvert.GetInt(dbRow["LocationId"]); // string tmpProjectNo = DataTypeConvert.GetString(dbRow["ProjectNo"]); // int tmpShelfId = DataTypeConvert.GetInt(dbRow["ShelfId"]); // double tmpQty = DataTypeConvert.GetDouble(dbRow["Qty"]); // double iaSumQty = 0; // if (tmpQty > 0) // { // iaSumQty = DataTypeConvert.GetDouble(copyNewTable.Compute("Sum(Qty)", string.Format("CodeFileName='{0}' and RepertoryId={1} and LocationId={2} and ProjectNo='{3}' and ShelfId={4}", tmpCodeFileName, tmpRepertoryId, tmpLocationId, tmpProjectNo, tmpShelfId))); // } // if (tmpQty == iaSumQty) // { // } // else // { // cmd.CommandText = string.Format("update INV_WarehouseNowInfo set Qty = Qty + ({5}) where CodeFileName='{0}' and RepertoryId={1} and LocationId={2} and ProjectNo='{3}' and ShelfId={4}", tmpCodeFileName, tmpRepertoryId, tmpLocationId, tmpProjectNo, tmpShelfId, iaSumQty - tmpQty); // affectedRowNo = cmd.ExecuteNonQuery(); // if (affectedRowNo == 0) // { // cmd.CommandText = string.Format("insert into INV_WarehouseNowInfo(CodeFileName, RepertoryId, LocationId, ProjectNo, ShelfId, Qty) values ('{0}', {1}, {2}, '{3}', {4}, {5})", tmpCodeFileName, tmpRepertoryId, tmpLocationId, tmpProjectNo, tmpShelfId, iaSumQty - tmpQty); // cmd.ExecuteNonQuery(); // } // } // DataRow[] drs = copyNewTable.Select(string.Format("CodeFileName='{0}' and RepertoryId={1} and LocationId={2} and ProjectNo='{3}' and ShelfId={4}", tmpCodeFileName, tmpRepertoryId, tmpLocationId, tmpProjectNo, tmpShelfId)); // foreach (DataRow dr in drs) // { // copyNewTable.Rows.Remove(dr); // } // } // foreach (DataRow newRow in copyNewTable.Rows) // { // string newCodeFileName = DataTypeConvert.GetString(newRow["CodeFileName"]); // int newRepertoryId = DataTypeConvert.GetInt(newRow["RepertoryId"]); // int newLocationId = DataTypeConvert.GetInt(newRow["LocationId"]); // string newProjectNo = DataTypeConvert.GetString(newRow["ProjectNo"]); // int newShelfId = DataTypeConvert.GetInt(newRow["ShelfId"]); // double newQty = DataTypeConvert.GetDouble(newRow["Qty"]); // cmd.CommandText = string.Format("update INV_WarehouseNowInfo set Qty = Qty + ({5}) where CodeFileName='{0}' and RepertoryId={1} and LocationId={2} and ProjectNo='{3}' and ShelfId={4}", newCodeFileName, newRepertoryId, newLocationId, newProjectNo, newShelfId, newQty); // affectedRowNo = cmd.ExecuteNonQuery(); // if (affectedRowNo == 0) // { // cmd.CommandText = string.Format("insert into INV_WarehouseNowInfo(CodeFileName, RepertoryId, LocationId, ProjectNo, ShelfId, Qty) values ('{0}', {1}, {2}, '{3}', {4}, {5})", newCodeFileName, newRepertoryId, newLocationId, newProjectNo, newShelfId, newQty); // cmd.ExecuteNonQuery(); // } // } //} #endregion DataTable dbListTable = new DataTable(); if (IAHeadRow.RowState != DataRowState.Added) { cmd.CommandText = string.Format("select CodeId, CodeFileName, head.RepertoryId, head.LocationId, head.ProjectNo, list.ShelfId, Sum(Qty) as Qty from INV_InventoryAdjustmentsList as list left join INV_InventoryAdjustmentsHead as head on list.InventoryAdjustmentsNo = head.InventoryAdjustmentsNo where list.InventoryAdjustmentsNo = '{0}' group by CodeId, CodeFileName, head.RepertoryId, head.LocationId, head.ProjectNo, list.ShelfId", iaNoStr); SqlDataAdapter dbListAdapter = new SqlDataAdapter(cmd); dbListAdapter.Fill(dbListTable); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "库存调整单", IAHeadRow, "InventoryAdjustmentsNo"); cmd.CommandText = "select * from INV_InventoryAdjustmentsHead where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, IAHeadRow.Table.GetChanges()); cmd.CommandText = "select * from INV_InventoryAdjustmentsList where 1=2"; SqlDataAdapter adapterList = new SqlDataAdapter(cmd); DataTable tmpListTable = new DataTable(); adapterList.Fill(tmpListTable); BaseSQL.UpdateDataTable(adapterList, IAListTable.GetChanges()); //Set_WWHead_End(cmd, IMListTable); //SqlCommand cmd_proc = new SqlCommand("", conn, trans); //if (!new FrmWarehouseNowInfoDAO().Update_WarehouseNowInfo(cmd_proc, iaNoStr, 1, out errorText)) //{ // trans.Rollback(); // MessageHandler.ShowMessageBox("库存调整单入库错误--" + errorText); // return 0; //} if (whDAO.SaveUpdate_WarehouseNowInfo(conn, trans, cmd, IAHeadRow, IAListTable.Copy(), iaNoStr, dbListTable, "库存调整单", "入库", true) != 1) { return(0); } if (SystemInfo.InventorySaveApproval) { //cmd.CommandText = string.Format("Insert into PUR_OrderApprovalInfo(OrderHeadNo, Approver, ApproverTime) values ('{0}', {1}, '{2}')", iaNoStr, SystemInfo.user.AutoId, serverTime.ToString("yyyy-MM-dd HH:mm:ss")); //cmd.ExecuteNonQuery(); //logStr = LogHandler.RecordLog_OperateRow(cmd, "库存调整单", IAHeadRow, "InventoryAdjustmentsNo", "审批", SystemInfo.user.EmpName, serverTime.ToString("yyyy-MM-dd HH:mm:ss")); new PURDAO.FrmApprovalDAO().InventorySaveApproval(cmd, IAHeadRow, "库存调整单", "InventoryAdjustmentsNo", iaNoStr, serverTime); cmd.CommandText = string.Format("Update INV_InventoryAdjustmentsHead set WarehouseState=2 where InventoryAdjustmentsNo='{0}'", iaNoStr); cmd.ExecuteNonQuery(); IAHeadRow["WarehouseState"] = 2; } trans.Commit(); IAHeadRow.Table.AcceptChanges(); IAListTable.AcceptChanges(); return(1); } catch (Exception ex) { trans.Rollback(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存项目人员信息 /// </summary> public void SaveProjectUser(string projectNoStr, List <int> autoIdList) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); cmd.CommandText = string.Format("select * from BS_ProjectUser where ProjectNo = '{0}'", projectNoStr); DataTable tmpTable = new DataTable(); SqlDataAdapter adpt = new SqlDataAdapter(cmd); adpt.Fill(tmpTable); for (int i = tmpTable.Rows.Count - 1; i >= 0; i--) { int tmpUserId = DataTypeConvert.GetInt(tmpTable.Rows[i]["UserId"]); if (autoIdList.Contains(tmpUserId)) { autoIdList.Remove(tmpUserId); } else { tmpTable.Rows[i].Delete(); } } BaseSQL.UpdateDataTable(adpt, tmpTable); foreach (int autoId in autoIdList) { cmd.CommandText = string.Format("Insert Into BS_ProjectUser (ProjectNo, UserId, IsPlanEdit, IsReplace) values ('{0}', {1}, 1, 1)", projectNoStr, autoId); cmd.ExecuteNonQuery(); } //cmd.CommandText = string.Format("Delete from BS_ProjectUser where ProjectNo = '{0}'", projectNoStr); //cmd.ExecuteNonQuery(); //for (int i = 0; i < autoIdList.Count; i++) //{ // cmd.CommandText = string.Format("Insert Into BS_ProjectUser (ProjectNo, UserId, IsPlanEdit, IsReplace) values ('{0}', {1}, 1, 1)", projectNoStr, autoIdList[i]); // cmd.ExecuteNonQuery(); //} LogHandler.RecordLog(cmd, string.Format("更新项目[{0}]的人员信息。", projectNoStr)); trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存采购结账单 /// </summary> /// <param name="SettleAccountsHeadRow">销售结账单表头数据表</param> /// <param name="SettleAccountsListTable">销售结账单明细数据表</param> public int SaveSettleAccounts(DataRow SettleAccountsHeadRow, DataTable SettleAccountsListTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); for (int i = 0; i < SettleAccountsListTable.Rows.Count; i++) { if (SettleAccountsListTable.Rows[i].RowState == DataRowState.Deleted) { continue; } string autoSalesOrderNoStr = DataTypeConvert.GetString(SettleAccountsListTable.Rows[i]["AutoSalesOrderNo"]); cmd.CommandText = string.Format("select Count(*) from SA_SalesOrder where AutoSalesOrderNo = '{0}'", autoSalesOrderNoStr); if (DataTypeConvert.GetInt(cmd.ExecuteScalar()) < 1) { MessageHandler.ShowMessageBox(string.Format("销售订单[{0}]未查询到,请查询后重新操作。", autoSalesOrderNoStr)); return(0); } } if (!CheckSalesOrderIsEnd(cmd, DataTypeConvert.GetString(SettleAccountsHeadRow["SettleAccountNo"]), SettleAccountsListTable)) { return(0); } if (DataTypeConvert.GetString(SettleAccountsHeadRow["SettleAccountNo"]) == "")//新增 { string saNo = BaseSQL.GetMaxCodeNo(cmd, "SA"); SettleAccountsHeadRow["SettleAccountNo"] = saNo; SettleAccountsHeadRow["PreparedIp"] = SystemInfo.HostIpAddress; for (int i = 0; i < SettleAccountsListTable.Rows.Count; i++) { SettleAccountsListTable.Rows[i]["SettleAccountNo"] = saNo; } } else//修改 { SettleAccountsHeadRow["Modifier"] = SystemInfo.user.EmpName; SettleAccountsHeadRow["ModifierIp"] = SystemInfo.HostIpAddress; SettleAccountsHeadRow["ModifierTime"] = BaseSQL.GetServerDateTime(); } string settleAccountNoStr = DataTypeConvert.GetString(SettleAccountsHeadRow["SettleAccountNo"]); cmd.CommandText = string.Format("Update SA_SalesOrder set IsEnd = 0 where AutoSalesOrderNo in (select AutoSalesOrderNo from SA_SettleAccountsList where SettleAccountNo = '{0}')", settleAccountNoStr); cmd.ExecuteNonQuery(); //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "销售结账单", SettleAccountsHeadRow, "SettleAccountNo"); cmd.CommandText = "select * from SA_SettleAccountsHead where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, SettleAccountsHeadRow.Table); cmd.CommandText = "select * from SA_SettleAccountsList where 1=2"; SqlDataAdapter adapterList = new SqlDataAdapter(cmd); DataTable tmpListTable = new DataTable(); adapterList.Fill(tmpListTable); BaseSQL.UpdateDataTable(adapterList, SettleAccountsListTable); Set_SalesOrder_End(cmd, settleAccountNoStr, SettleAccountsListTable); trans.Commit(); return(1); } catch (Exception ex) { trans.Rollback(); SettleAccountsHeadRow.Table.RejectChanges(); SettleAccountsListTable.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存库存移动单 /// </summary> /// <param name="IMHeadRow">库存移动单表头数据表</param> /// <param name="IMListTable">库存移动单明细数据表</param> public int SaveInventoryMove(DataRow IMHeadRow, DataTable IMListTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); //检查当前库存数是否满足 if (!CheckWarehouseNowInfoBeyondCount(cmd, DataTypeConvert.GetString(IMHeadRow["InventoryMoveNo"]), IMListTable)) { return(0); } if (DataTypeConvert.GetString(IMHeadRow["InventoryMoveNo"]) == "")//新增 { string imNo = BaseSQL.GetMaxCodeNo(cmd, "IM"); IMHeadRow["InventoryMoveNo"] = imNo; IMHeadRow["PreparedIp"] = SystemInfo.HostIpAddress; for (int i = 0; i < IMListTable.Rows.Count; i++) { IMListTable.Rows[i]["InventoryMoveNo"] = imNo; IMListTable.Rows[i]["InventoryMoveDate"] = IMHeadRow["InventoryMoveDate"]; IMListTable.Rows[i]["InRepertoryNo"] = IMHeadRow["InRepertoryNo"]; IMListTable.Rows[i]["OutRepertoryNo"] = IMHeadRow["OutRepertoryNo"]; } } else//修改 { //if (!CheckWarehouseState(IMHeadRow.Table, IMListTable, string.Format("'{0}'", DataTypeConvert.GetString(IMHeadRow["SettlementNo"])), false, true, true, true)) // return -1; IMHeadRow["Modifier"] = SystemInfo.user.EmpName; IMHeadRow["ModifierIp"] = SystemInfo.HostIpAddress; IMHeadRow["ModifierTime"] = BaseSQL.GetServerDateTime(); for (int i = 0; i < IMListTable.Rows.Count; i++) { if (IMListTable.Rows[i].RowState == DataRowState.Deleted) { continue; } IMListTable.Rows[i]["InventoryMoveDate"] = IMHeadRow["InventoryMoveDate"]; IMListTable.Rows[i]["InRepertoryNo"] = IMHeadRow["InRepertoryNo"]; IMListTable.Rows[i]["OutRepertoryNo"] = IMHeadRow["OutRepertoryNo"]; } } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "库存移动单", IMHeadRow, "InventoryMoveNo"); cmd.CommandText = "select * from INV_InventoryMoveHead where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, IMHeadRow.Table); cmd.CommandText = "select * from INV_InventoryMoveList where 1=2"; SqlDataAdapter adapterList = new SqlDataAdapter(cmd); DataTable tmpListTable = new DataTable(); adapterList.Fill(tmpListTable); BaseSQL.UpdateDataTable(adapterList, IMListTable); //Set_WWHead_End(cmd, IMListTable); trans.Commit(); return(1); } catch (Exception ex) { trans.Rollback(); IMHeadRow.Table.RejectChanges(); IMListTable.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存生产计划单 /// </summary> public int SaveProductionSchedule(DataRow headRow) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); //if (!CheckPrReqApplyBeyondCount(cmd, DataTypeConvert.GetString(orderHeadRow["OrderHeadNo"]), orderListTable)) //{ // return 0; //} if (DataTypeConvert.GetString(headRow["PsNo"]) == "")//新增 { string orderHeadNo = BaseSQL.GetMaxCodeNo(cmd, "PN"); headRow["PsNo"] = orderHeadNo; headRow["PreparedIp"] = SystemInfo.HostIpAddress; headRow["GetTime"] = BaseSQL.GetServerDateTime(); } else//修改 { if (!CheckPSState(headRow.Table, string.Format("'{0}'", DataTypeConvert.GetString(headRow["PsNo"])), false, true, true, true)) { return(-1); } headRow["Modifier"] = SystemInfo.user.EmpName; headRow["ModifierIp"] = SystemInfo.HostIpAddress; headRow["ModifierTime"] = BaseSQL.GetServerDateTime(); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "生产计划单", headRow, "PsNo"); cmd.CommandText = "select * from PB_ProductionSchedule where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, headRow.Table); //Set_PrReqHead_End(cmd, orderListTable); trans.Commit(); return(1); } catch (Exception ex) { trans.Rollback(); headRow.Table.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 更新流程图连接线信息 /// </summary> /// <param name="lineIdInt">连接线Id</param> /// <param name="lineTextStr">连接线名称</param> /// <param name="enabledInt">启用条件标志 1启用 0停用</param> /// <param name="lineTypeInt">连接线类型</param> /// <param name="lineConditionTable">连接线条件列表</param> /// <param name="lineHandleTable">连接线处理人员列表</param> /// <param name="lineNoticeTable">连接线通知人员列表</param> /// <param name="conditionListTable">条件具体明细列表</param> public bool SaveWorkFlowsLineSet(int lineIdInt, string lineTextStr, int enabledInt, int lineTypeInt, DataTable lineConditionTable, DataTable lineHandleTable, DataTable lineNoticeTable, DataTable conditionListTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); if (lineIdInt > 0) { cmd.CommandText = string.Format("Select Count(*) from BS_WorkFlowsLine where WorkFlowsId in (select WorkFlowsId from BS_WorkFlowsLine where AutoId = {0}) and LineType = {1} and AutoId != {0}", lineIdInt, lineTypeInt); if (DataTypeConvert.GetInt(cmd.ExecuteScalar()) > 0) { trans.Rollback(); MessageHandler.ShowMessageBox(string.Format("流程图连接线的类型【{0}】有重复,不可以保存。", (WorkFlowsHandleDAO.LineType)lineTypeInt)); return(false); } cmd.CommandText = string.Format("Update BS_WorkFlowsLine set LineText = '{1}', Enabled = {2}, LineType = {3} where AutoId = {0}", lineIdInt, lineTextStr, enabledInt, lineTypeInt); cmd.ExecuteNonQuery(); string logStr = string.Format("修改流程图连接线信息:[AutoId]的值为[{0}],[连接线名称]的值改为[{1}],[启用标志]的值改为[{2}],[连接线类型]的值改为[{3}]", lineIdInt, lineTextStr, enabledInt, lineTypeInt); LogHandler.RecordLog(cmd, logStr); } for (int i = 0; i < lineConditionTable.Rows.Count; i++) { DataRow tmpRow = lineConditionTable.Rows[i]; switch (tmpRow.RowState) { case DataRowState.Added: string lineIdStr = DataTypeConvert.GetInt(tmpRow["LineId"]) <= 0 ? "null" : DataTypeConvert.GetString(tmpRow["LineId"]); int autoId = InsertWorkFlowsLineCondition(cmd, lineIdStr, DataTypeConvert.GetString(tmpRow["ConditionText"]), DataTypeConvert.GetString(tmpRow["Condition"]), DataTypeConvert.GetInt(tmpRow["WorkFlowsId"])); DataRow[] handleRows = lineHandleTable.Select(string.Format("ConditionId={0}", lineConditionTable.Rows[i]["AutoId"])); foreach (DataRow dr in handleRows) { dr["ConditionId"] = autoId; } DataRow[] noticeRows = lineNoticeTable.Select(string.Format("ConditionId={0}", lineConditionTable.Rows[i]["AutoId"])); foreach (DataRow dr in noticeRows) { dr["ConditionId"] = autoId; } DataRow[] listRows = conditionListTable.Select(string.Format("ConditionId={0}", lineConditionTable.Rows[i]["AutoId"])); foreach (DataRow dr in listRows) { dr["ConditionId"] = autoId; } break; case DataRowState.Modified: cmd.CommandText = string.Format("UPDATE BS_WorkFlowsLineCondition SET ConditionText = '{1}', Condition = '{2}' where AutoId = {0}", DataTypeConvert.GetInt(tmpRow["AutoId"]), DataTypeConvert.GetString(tmpRow["ConditionText"]), DataTypeConvert.GetString(tmpRow["Condition"])); cmd.ExecuteNonQuery(); break; } } cmd.CommandText = "select * from BS_WorkFlowsLineHandle where 1=2"; SqlDataAdapter adapterHandle = new SqlDataAdapter(cmd); DataTable tmpHandleTable = new DataTable(); adapterHandle.Fill(tmpHandleTable); BaseSQL.UpdateDataTable(adapterHandle, lineHandleTable.GetChanges()); cmd.CommandText = "select * from BS_WorkFlowsLineNotice where 1=2"; SqlDataAdapter adapterNotice = new SqlDataAdapter(cmd); DataTable tmpNoticeTable = new DataTable(); adapterNotice.Fill(tmpNoticeTable); BaseSQL.UpdateDataTable(adapterNotice, lineNoticeTable.GetChanges()); cmd.CommandText = "select * from BS_WorkFlowsLineConditionList where 1=2"; SqlDataAdapter adapterList = new SqlDataAdapter(cmd); DataTable tmpListTable = new DataTable(); adapterList.Fill(tmpListTable); BaseSQL.UpdateDataTable(adapterList, conditionListTable.GetChanges()); for (int i = 0; i < lineConditionTable.Rows.Count; i++) { DataRow tmpRow = lineConditionTable.Rows[i]; switch (tmpRow.RowState) { case DataRowState.Deleted: cmd.CommandText = string.Format("Delete from BS_WorkFlowsLineConditionList where ConditionId = {0}", DataTypeConvert.GetInt(tmpRow["AutoId", DataRowVersion.Original])); cmd.ExecuteNonQuery(); cmd.CommandText = string.Format("Delete from BS_WorkFlowsLineCondition where AutoId = {0}", DataTypeConvert.GetInt(tmpRow["AutoId", DataRowVersion.Original])); cmd.ExecuteNonQuery(); string logStr = string.Format("删除连接线设定条件:[AutoId]的值[{0}],[条件名称]的值[{1}],[条件SQL]的值[{2}]", DataTypeConvert.GetInt(tmpRow["AutoId", DataRowVersion.Original]), DataTypeConvert.GetString(tmpRow["ConditionText", DataRowVersion.Original]), DataTypeConvert.GetString(tmpRow["Condition", DataRowVersion.Original])); LogHandler.RecordLog(cmd, logStr); break; } } LogHandler.RecordLog_DataTable(cmd, "连接线处理人员", lineHandleTable, "AutoId"); LogHandler.RecordLog_DataTable(cmd, "连接线通知人员", lineNoticeTable, "AutoId"); trans.Commit(); lineConditionTable.AcceptChanges(); lineHandleTable.AcceptChanges(); lineNoticeTable.AcceptChanges(); conditionListTable.AcceptChanges(); return(true); } catch (Exception ex) { trans.Rollback(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存报价信息 /// </summary> public int SaveProductionSchedule_Drag(DataRow headRow) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); DateTime nowTime = BaseSQL.GetServerDateTime(); if (headRow.RowState == DataRowState.Added)//新增 { headRow["PsNo"] = BaseSQL.GetMaxCodeNo(cmd, "PN"); headRow["PreparedIp"] = SystemInfo.HostIpAddress; headRow["CurrentDate"] = nowTime; headRow["GetTime"] = nowTime; } else//修改 { string psNoStr = DataTypeConvert.GetString(headRow["PsNo"]); if (!CheckState(headRow.Table, psNoStr, false, true)) { return(-1); } //if (CheckQuotationInfo_IsSalesOrder(cmd, psNoStr)) //{ // headRow.Table.RejectChanges(); // listTable.RejectChanges(); // return -1; //} //for (int i = 0; i < listTable.Rows.Count; i++) //{ // if (listTable.Rows[i].RowState == DataRowState.Deleted) // continue; // else if (listTable.Rows[i].RowState == DataRowState.Added) // { // listTable.Rows[i]["AutoQuotationNo"] = headRow["AutoQuotationNo"]; // listTable.Rows[i]["QuotationDate"] = nowTime; // } //} headRow["Modifier"] = SystemInfo.user.EmpName; headRow["ModifierIp"] = SystemInfo.HostIpAddress; headRow["ModifierTime"] = BaseSQL.GetServerDateTime(); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "生产计划单", headRow, "PsNo"); cmd.CommandText = "select * from PB_ProductionSchedule where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, headRow.Table); trans.Commit(); return(1); } catch (Exception ex) { trans.Rollback(); headRow.Table.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存供货明细信息 /// </summary> public int SaveDeliveryDetail(DataRow headRow, DataTable listTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); DateTime nowTime = BaseSQL.GetServerDateTime(); if (headRow.RowState == DataRowState.Added)//新增 { cmd.CommandText = string.Format("Insert into SA_DeliveryDetail (SMNo, DeliveryText, FunctionDesc, DeliveryQty, Unit, Amount, Creator, PreparedIp, GetTime) values ('{0}', '{1}', '{2}', {6}, {7}, {8}, {3}, '{4}', '{5}')", DataTypeConvert.GetString(headRow["SMNo"]), DataTypeConvert.GetString(headRow["DeliveryText"]), DataTypeConvert.GetString(headRow["FunctionDesc"]), SystemInfo.user.AutoId, SystemInfo.HostIpAddress, nowTime.ToString("yyyy-MM-dd HH:mm:ss"), DataTypeConvert.GetDouble(headRow["DeliveryQty"]), DataTypeConvert.GetDouble(headRow["Unit"]), DataTypeConvert.GetDouble(headRow["Amount"])); int ret = cmd.ExecuteNonQuery(); if (ret != 1) { trans.Rollback(); headRow.Table.RejectChanges(); listTable.RejectChanges(); MessageHandler.ShowMessageBox("保存供货明细信息错误,请重新新增操作。"); return(-1); } cmd.CommandText = "select @@IDENTITY"; ret = DataTypeConvert.GetInt(cmd.ExecuteScalar()); if (ret == 0) { trans.Rollback(); headRow.Table.RejectChanges(); listTable.RejectChanges(); return(-1); } for (int i = 0; i < listTable.Rows.Count; i++) { listTable.Rows[i]["DeliveryDetailNO"] = ret; listTable.Rows[i]["PreparedIp"] = SystemInfo.HostIpAddress; listTable.Rows[i]["GetTime"] = nowTime; } } else//修改 { for (int i = 0; i < listTable.Rows.Count; i++) { if (listTable.Rows[i].RowState == DataRowState.Added) { listTable.Rows[i]["PreparedIp"] = SystemInfo.HostIpAddress; listTable.Rows[i]["GetTime"] = nowTime; } } cmd.CommandText = "select * from SA_DeliveryDetail where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, headRow.Table); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "供货明细信息", headRow, "AutoId"); cmd.CommandText = "select * from SA_MaterialDetail where 1=2"; SqlDataAdapter adapterList = new SqlDataAdapter(cmd); DataTable tmpListTable = new DataTable(); adapterList.Fill(tmpListTable); BaseSQL.UpdateDataTable(adapterList, listTable); trans.Commit(); headRow.AcceptChanges(); listTable.AcceptChanges(); return(1); } catch (Exception ex) { trans.Rollback(); headRow.Table.RejectChanges(); listTable.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存销售订单 /// </summary> public int SaveSalesOrder(DataRow headRow) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); string oldAutoQuotationNoStr = ""; string autoQuotationNoStr = DataTypeConvert.GetString(headRow["AutoQuotationNo"]); string oldVersions = ""; string versions = DataTypeConvert.GetString(headRow["QuotationVersions"]); cmd.CommandText = string.Format("select AutoQuotationNo, QuotationState from SA_QuotationBaseInfo where AutoQuotationNo = '{0}'", autoQuotationNoStr); SqlDataAdapter quoadapter = new SqlDataAdapter(cmd); DataTable quotable = new DataTable(); quoadapter.Fill(quotable); if (quotable.Rows.Count < 1) { MessageHandler.ShowMessageBox(string.Format("报价单[{0}]未查询到,请查询后重新操作。", autoQuotationNoStr)); return(0); } if (DataTypeConvert.GetInt(quotable.Rows[0]["QuotationState"]) != 0) { MessageHandler.ShowMessageBox(string.Format("报价单[{0}]非正常状态,请查询后重新操作。", autoQuotationNoStr)); return(0); } ////判断当前报价单版本的金额是否被多张销售订单的合计金额超过 //string versionsStr = DataTypeConvert.GetString(headRow["QuotationVersions"]); //cmd.CommandText = string.Format("select Amount from SA_QuotationPriceInfo where AutoQuotationNo = '{0}' and Versions = '{1}'", autoQuotationNoStr, versionsStr); //decimal versionAmount = DataTypeConvert.GetDecimal(cmd.ExecuteScalar()); //cmd.CommandText = string.Format("select IsNull(Sum(Amount), 0) from SA_SalesOrder where AutoQuotationNo = '{0}' and AutoSalesOrderNo != '{1}' and QuotationVersions = '{2}'", autoQuotationNoStr, DataTypeConvert.GetString(headRow["AutoSalesOrderNo"]), versionsStr); //decimal otherSOAmount = DataTypeConvert.GetDecimal(cmd.ExecuteScalar()); //decimal soAmount = DataTypeConvert.GetDecimal(headRow["Amount"]); //if (versionAmount < soAmount + otherSOAmount) //{ // MessageHandler.ShowMessageBox(string.Format("多张销售订单的合计金额[{0}]大于报价单版本的金额[{1}],请重新操作。", soAmount + otherSOAmount, versionAmount)); // return 0; //} //DateTime nowTime = BaseSQL.GetServerDateTime(); if (headRow.RowState == DataRowState.Added)//新增 { cmd.CommandText = string.Format("select COUNT(*) from SA_QuotationPriceInfo where AutoQuotationNo = '{0}' and IsNull(IsPoUse, 0) = 1", autoQuotationNoStr); if (DataTypeConvert.GetInt(cmd.ExecuteScalar()) > 0) { MessageHandler.ShowMessageBox(string.Format("报价单[{0}]已经生成销售订单,一张报价单只能生成一张销售订单,请重新操作。", autoQuotationNoStr)); return(0); } headRow["AutoSalesOrderNo"] = BaseSQL.GetMaxCodeNo(cmd, "SO"); headRow["PreparedIp"] = SystemInfo.HostIpAddress; } else//修改 { oldAutoQuotationNoStr = DataTypeConvert.GetString(headRow["AutoQuotationNo", DataRowVersion.Original]); oldVersions = DataTypeConvert.GetString(headRow["QuotationVersions", DataRowVersion.Original]); if (autoQuotationNoStr != oldAutoQuotationNoStr) { cmd.CommandText = string.Format("select COUNT(*) from SA_QuotationPriceInfo where AutoQuotationNo = '{0}' and IsNull(IsPoUse, 0) = 1", autoQuotationNoStr); if (DataTypeConvert.GetInt(cmd.ExecuteScalar()) > 0) { MessageHandler.ShowMessageBox(string.Format("报价单[{0}]已经生成销售订单,一张报价单只能生成一张销售订单,请重新操作。", autoQuotationNoStr)); return(0); } } string autoSalesOrderNoStr = DataTypeConvert.GetString(headRow["AutoSalesOrderNo"]); if (CheckSalesOrder_IsSettleAccounts(cmd, autoSalesOrderNoStr)) { headRow.Table.RejectChanges(); return(1); } headRow["Modifier"] = SystemInfo.user.EmpName; headRow["ModifierIp"] = SystemInfo.HostIpAddress; headRow["ModifierTime"] = BaseSQL.GetServerDateTime(); } if (oldAutoQuotationNoStr != autoQuotationNoStr) { if (oldAutoQuotationNoStr != "") { cmd.CommandText = string.Format("Update SA_QuotationPriceInfo set IsPoUse = 0 where AutoQuotationNo = '{0}'", oldAutoQuotationNoStr); cmd.ExecuteNonQuery(); cmd.CommandText = string.Format("Update SA_QuotationPriceInfo set IsPoUse = 1 where AutoQuotationNo = '{0}' and Versions = '{1}'", autoQuotationNoStr, versions); cmd.ExecuteNonQuery(); } else { cmd.CommandText = string.Format("Update SA_QuotationPriceInfo set IsPoUse = 0 where AutoQuotationNo = '{0}'", autoQuotationNoStr); cmd.ExecuteNonQuery(); cmd.CommandText = string.Format("Update SA_QuotationPriceInfo set IsPoUse = 1 where AutoQuotationNo = '{0}' and Versions = '{1}'", autoQuotationNoStr, versions); cmd.ExecuteNonQuery(); } } else { if (oldVersions != versions) { cmd.CommandText = string.Format("Update SA_QuotationPriceInfo set IsPoUse = 0 where AutoQuotationNo = '{0}'", autoQuotationNoStr); cmd.ExecuteNonQuery(); cmd.CommandText = string.Format("Update SA_QuotationPriceInfo set IsPoUse = 1 where AutoQuotationNo = '{0}' and Versions = '{1}'", autoQuotationNoStr, versions); cmd.ExecuteNonQuery(); } } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "销售订单信息", headRow, "AutoSalesOrderNo"); cmd.CommandText = "select * from SA_SalesOrder where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, headRow.Table); trans.Commit(); return(1); } catch (Exception ex) { trans.Rollback(); headRow.Table.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存出库单 /// </summary> /// <param name="wrHeadRow">出库单表头数据表</param> /// <param name="wrListTable">出库单明细数据表</param> public int SaveWarehouseReceipt(DataRow wrHeadRow, DataTable wrListTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); //if (!CheckOrderApplyBeyondCount(cmd, DataTypeConvert.GetString(wrHeadRow["WarehouseReceipt"]), wrListTable)) //{ // return 0; //} if (DataTypeConvert.GetString(wrHeadRow["WarehouseReceipt"]) == "")//新增 { string wrNo = BaseSQL.GetMaxCodeNo(cmd, "WR"); wrHeadRow["WarehouseReceipt"] = wrNo; wrHeadRow["PreparedIp"] = SystemInfo.HostIpAddress; for (int i = 0; i < wrListTable.Rows.Count; i++) { wrListTable.Rows[i]["WarehouseReceipt"] = wrNo; } } else//修改 { if (!CheckWarehouseState(wrHeadRow.Table, wrListTable, string.Format("'{0}'", DataTypeConvert.GetString(wrHeadRow["WarehouseReceipt"])), false, true, true, true)) { return(-1); } wrHeadRow["Modifier"] = SystemInfo.user.EmpName; wrHeadRow["ModifierIp"] = SystemInfo.HostIpAddress; wrHeadRow["ModifierTime"] = BaseSQL.GetServerDateTime(); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "出库单", wrHeadRow, "WarehouseReceipt"); cmd.CommandText = "select * from INV_WarehouseReceiptHead where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, wrHeadRow.Table); cmd.CommandText = "select * from INV_WarehouseReceiptList where 1=2"; SqlDataAdapter adapterList = new SqlDataAdapter(cmd); DataTable tmpListTable = new DataTable(); adapterList.Fill(tmpListTable); BaseSQL.UpdateDataTable(adapterList, wrListTable); //Set_PrReqHead_End(cmd, wwListTable); trans.Commit(); return(1); } catch (Exception ex) { trans.Rollback(); wrHeadRow.Table.RejectChanges(); wrListTable.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存任务计划登记信息 /// </summary> public bool SaveTaskScheduleRegister(DataTable updateTable) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); DateTime nowTime = BaseSQL.GetServerDateTime(); for (int i = 0; i < updateTable.Rows.Count; i++) { DataRow dr = updateTable.Rows[i]; if (dr.RowState == DataRowState.Modified) { dr["Modifierint"] = SystemInfo.user.AutoId; dr["ModifyTime"] = nowTime; string actualStartDate = DataTypeConvert.GetString(dr["ActualStartDate"]); string actualEndDate = DataTypeConvert.GetString(dr["ActualEndDate"]); int schedule = DataTypeConvert.GetInt(dr["Schedule"]); if (actualStartDate == "" && actualEndDate == "") { dr["ActualTotalDays"] = DBNull.Value; } int planTaskStatus = 2; if (actualStartDate == "") { planTaskStatus = 1; } if (actualStartDate != "" && actualEndDate != "" && schedule == 100) { planTaskStatus = 3; } dr["PlanTaskStatus"] = planTaskStatus; } } cmd.CommandText = "select * from PM_ProjectPlanTask where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, updateTable); ////保存日志到日志表中 //DataRow[] headRows = imHeadTable.Select("select=1"); //for (int i = 0; i < headRows.Length; i++) //{ // string logStr = LogHandler.RecordLog_DeleteRow(cmd, "库存移动单", headRows[i], "InventoryMoveNo"); //} trans.Commit(); return(true); } catch (Exception ex) { trans.Rollback(); throw ex; } finally { conn.Close(); } } } }
/// <summary> /// 保存功能模块信息 /// </summary> public int SaveStnModule(DataRow headRow, string copySMNoStr, int StnSummaryListModule_AutoIdInt) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); DateTime nowTime = BaseSQL.GetServerDateTime(); if (headRow.RowState == DataRowState.Added)//新增 { headRow["SMNo"] = BaseSQL.GetMaxCodeNo(cmd, "SM"); headRow["PreparedIp"] = SystemInfo.HostIpAddress; headRow["GetTime"] = nowTime; } else//修改 { } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "功能模块信息", headRow, "SMNo"); cmd.CommandText = "select * from SA_StnModule where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, headRow.Table); if (copySMNoStr != "") { if (StnSummaryListModule_AutoIdInt > 0) { cmd.CommandText = string.Format("Update SA_StnSummaryListModule set StnModuleId = '{1}' where AutoId = {0}", StnSummaryListModule_AutoIdInt, DataTypeConvert.GetString(headRow["SMNo"])); cmd.ExecuteNonQuery(); } int resultInt = 0; string errorText = ""; string smNoStr = DataTypeConvert.GetString(headRow["SMNo"]); SqlCommand cmd_proc = new SqlCommand("", conn, trans); SqlParameter p1 = new SqlParameter("@CopySMNo", SqlDbType.VarChar); p1.Value = copySMNoStr; SqlParameter p2 = new SqlParameter("@NewSMNo", SqlDbType.VarChar); p2.Value = smNoStr; SqlParameter p3 = new SqlParameter("@Creator", SqlDbType.Int); p3.Value = SystemInfo.user.AutoId; SqlParameter p4 = new SqlParameter("@PreparedIp", SqlDbType.VarChar); p4.Value = SystemInfo.HostIpAddress; IDataParameter[] parameters = new IDataParameter[] { p1, p2, p3, p4 }; BaseSQL.RunProcedure(cmd_proc, "P_DeliveryDetail_Copy", parameters, out resultInt, out errorText); if (resultInt != 1) { trans.Rollback(); MessageHandler.ShowMessageBox("复制供货明细信息错误--" + errorText); return(-1); } } trans.Commit(); return(1); } catch (Exception ex) { trans.Rollback(); headRow.Table.RejectChanges(); throw ex; } finally { conn.Close(); } } } }
///// <summary> ///// 查询流程表中的文件信息 ///// </summary> //public string QueryWorkFlow_Document(int autoIdInt, string workFlowTextStr, string tempFilePath) //{ // string sqlStr = string.Format("select AutoId, FileByte from BS_WorkFlow where AutoId = {0}", autoIdInt); // DataTable docTable = BaseSQL.GetTableBySql(sqlStr); // if (docTable.Rows.Count == 0) // return ""; // Byte[] fileByte = (byte[])docTable.Rows[0]["FileByte"]; // FileHandler fileHandler = new FileHandler(); // fileHandler.ByteArrayToFile(fileByte, tempFilePath); // return tempFilePath; //} ///// <summary> ///// 更新某个单据模板 ///// </summary> //public bool UpdateWorkFlow(SqlCommand cmd, int autoIdInt, string iniPath) //{ // long streamLength = 0; // Byte[] buffer = new FileHandler().FileToByteArray(iniPath, ref streamLength); // SqlParameter p1 = new SqlParameter("@filebyte", SqlDbType.Image); // p1.Value = buffer; // SqlParameter p2 = new SqlParameter("@AutoId", SqlDbType.Int); // p2.Value = autoIdInt; // cmd.Parameters.Add(p1); // cmd.Parameters.Add(p2); // cmd.CommandText = "Update BS_WorkFlow Set FileByte = @filebyte where AutoId = @AutoId"; // cmd.ExecuteNonQuery(); // return true; //} /// <summary> /// 保存流程表 /// </summary> public int SaveWorkFlow(DataRow headRow, List <DiagramConnector> connectorList, List <DiagramShape> shapeList) { using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { SqlCommand cmd = new SqlCommand("", conn, trans); DateTime nowTime = BaseSQL.GetServerDateTime(); int autoIdInt = 0; if (CheckWorkFlowType(cmd, DataTypeConvert.GetInt(headRow["AutoId"]), DataTypeConvert.GetInt(headRow["WorkFlowTypeAutoId"]))) { return(0); } if (headRow.RowState == DataRowState.Added)//新增 { headRow["GetTime"] = nowTime; //新增保存流程主表 cmd.CommandText = string.Format("Insert into BS_WorkFlow (WorkFlowText, Remark, GetTime) values ('{0}', '{1}', '{2}')", DataTypeConvert.GetString(headRow["WorkFlowText"]), DataTypeConvert.GetString(headRow["Remark"]), nowTime.ToString("yyyy-MM-dd HH:mm:ss")); autoIdInt = cmd.ExecuteNonQuery(); if (autoIdInt != 1) { trans.Rollback(); headRow.Table.RejectChanges(); MessageHandler.ShowMessageBox("保存流程表信息错误,请重新新增操作。"); return(-1); } cmd.CommandText = "select @@IDENTITY"; autoIdInt = DataTypeConvert.GetInt(cmd.ExecuteScalar()); headRow["AutoId"] = autoIdInt; InsertWorkFlowNodeInfo(cmd, autoIdInt, connectorList, shapeList); } else//修改 { if (!CheckCurrentData(cmd, DataTypeConvert.GetInt(headRow["AutoId"]))) { return(0); } //修改保存流程主表 cmd.CommandText = "select * from BS_WorkFlow where 1=2"; SqlDataAdapter adapterHead = new SqlDataAdapter(cmd); DataTable tmpHeadTable = new DataTable(); adapterHead.Fill(tmpHeadTable); BaseSQL.UpdateDataTable(adapterHead, headRow.Table); autoIdInt = DataTypeConvert.GetInt(headRow["AutoId"]); UpdateWorkFlowNodeInfo(cmd, autoIdInt, connectorList, shapeList); } //保存日志到日志表中 string logStr = LogHandler.RecordLog_DataRow(cmd, "流程表信息", headRow, "AutoId"); //UpdateWorkFlow(cmd, autoIdInt, tempFilePath); trans.Commit(); headRow.AcceptChanges(); return(1); } catch (Exception ex) { trans.Rollback(); headRow.Table.RejectChanges(); throw ex; } finally { conn.Close(); } } } }