Ejemplo n.º 1
0
        /// <summary>
        /// 根据选择删除多条预算外出库单
        /// </summary>
        public bool DeleteSWR_Multi(DataTable swwHeadTable)
        {
            string swwHeadNoListStr = "";

            for (int i = 0; i < swwHeadTable.Rows.Count; i++)
            {
                if (DataTypeConvert.GetBoolean(swwHeadTable.Rows[i]["Select"]))
                {
                    swwHeadNoListStr += string.Format("'{0}',", DataTypeConvert.GetString(swwHeadTable.Rows[i]["SpecialWarehouseReceipt"]));
                }
            }
            swwHeadNoListStr = swwHeadNoListStr.Substring(0, swwHeadNoListStr.Length - 1);
            if (!CheckWarehouseState(swwHeadTable, null, swwHeadNoListStr, false, true, true, true))
            {
                return(false);
            }
            using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        SqlCommand cmd       = new SqlCommand("", conn, trans);
                        string     errorText = "";
                        cmd.CommandText = string.Format("select * from INV_SpecialWarehouseReceiptList where SpecialWarehouseReceipt in ({0})", swwHeadNoListStr);
                        DataTable      tmpTable = new DataTable();
                        SqlDataAdapter adpt     = new SqlDataAdapter(cmd);
                        adpt.Fill(tmpTable);

                        //保存日志到日志表中
                        DataRow[]             swwHeadRows = swwHeadTable.Select("select=1");
                        FrmWarehouseCommonDAO whDAO       = new FrmWarehouseCommonDAO();

                        for (int i = 0; i < swwHeadRows.Length; i++)
                        {
                            string logStr = LogHandler.RecordLog_DeleteRow(cmd, "预算外出库单", swwHeadRows[i], "SpecialWarehouseReceipt");

                            if (!whDAO.IsDeleteWarehouseOrder(cmd, DataTypeConvert.GetDateTime(swwHeadRows[i]["SpecialWarehouseReceiptDate"])))
                            {
                                return(false);
                            }

                            SqlCommand cmd_proc_cancel = new SqlCommand("", conn, trans);
                            if (!whDAO.Update_WarehouseNowInfo(cmd_proc_cancel, DataTypeConvert.GetString(swwHeadRows[i]["SpecialWarehouseReceipt"]), 2, out errorText))
                            {
                                trans.Rollback();
                                MessageHandler.ShowMessageBox("预算外出库单删除出库错误--" + errorText);
                                return(false);
                            }
                        }

                        cmd.CommandText = string.Format("Delete from INV_SpecialWarehouseReceiptList where SpecialWarehouseReceipt in ({0})", swwHeadNoListStr);
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = string.Format("Delete from INV_SpecialWarehouseReceiptHead where SpecialWarehouseReceipt in ({0})", swwHeadNoListStr);
                        cmd.ExecuteNonQuery();

                        //Set_OrderHead_End(cmd, tmpTable);

                        trans.Commit();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据选择删除多条库存调整单
        /// </summary>
        public bool DeleteInventoryAdjustments_Multi(DataTable iaHeadTable)
        {
            string iaHeadNoListStr = "";

            for (int i = 0; i < iaHeadTable.Rows.Count; i++)
            {
                if (DataTypeConvert.GetBoolean(iaHeadTable.Rows[i]["Select"]))
                {
                    iaHeadNoListStr += string.Format("'{0}',", DataTypeConvert.GetString(iaHeadTable.Rows[i]["InventoryAdjustmentsNo"]));
                }
            }
            iaHeadNoListStr = iaHeadNoListStr.Substring(0, iaHeadNoListStr.Length - 1);
            if (!CheckWarehouseState(iaHeadTable, null, iaHeadNoListStr, false, true, true, true))
            {
                return(false);
            }
            using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        SqlCommand cmd       = new SqlCommand("", conn, trans);
                        string     errorText = "";
                        //cmd.CommandText = string.Format("select * from INV_InventoryAdjustmentsList where InventoryAdjustmentsNo in ({0})", iaHeadNoListStr);
                        //DataTable tmpTable = new DataTable();
                        //SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                        //adpt.Fill(tmpTable);

                        //保存日志到日志表中
                        DataRow[]             headRows = iaHeadTable.Select("select=1");
                        FrmWarehouseCommonDAO whDAO    = new FrmWarehouseCommonDAO();

                        for (int i = 0; i < headRows.Length; i++)
                        {
                            string logStr = LogHandler.RecordLog_DeleteRow(cmd, "库存调整单", headRows[i], "InventoryAdjustmentsNo");

                            if (!whDAO.IsDeleteWarehouseOrder(cmd, DataTypeConvert.GetDateTime(headRows[i]["InventoryAdjustmentsDate"])))
                            {
                                return(false);
                            }

                            SqlCommand cmd_proc_cancel = new SqlCommand("", conn, trans);
                            if (!whDAO.Update_WarehouseNowInfo(cmd_proc_cancel, DataTypeConvert.GetString(headRows[i]["InventoryAdjustmentsNo"]), 2, out errorText))
                            {
                                trans.Rollback();
                                MessageHandler.ShowMessageBox("库存调整单删除入库错误--" + errorText);
                                return(false);
                            }
                        }

                        //cmd.CommandText = string.Format("Delete from INV_WarehouseNowInfo where Qty = 0 and exists (select * from INV_InventoryAdjustmentsList as list where list.CodeId = INV_WarehouseNowInfo.CodeId and list.CodeFileName = INV_WarehouseNowInfo.CodeFileName and list.RepertoryId = INV_WarehouseNowInfo.RepertoryId and list.LocationId = INV_WarehouseNowInfo.LocationId and list.ProjectNo = INV_WarehouseNowInfo.ProjectNo and list.ShelfId = INV_WarehouseNowInfo.ShelfId and InventoryAdjustmentsNo in ({0}))", iaHeadNoListStr);
                        //cmd.ExecuteNonQuery();

                        cmd.CommandText = string.Format("Delete from INV_InventoryAdjustmentsList where InventoryAdjustmentsNo in ({0})", iaHeadNoListStr);
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = string.Format("Delete from INV_InventoryAdjustmentsHead where InventoryAdjustmentsNo in ({0})", iaHeadNoListStr);
                        cmd.ExecuteNonQuery();

                        //Set_WWHead_End(cmd, tmpTable);

                        trans.Commit();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }