Example #1
0
        /// <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();
                    }
                }
            }
        }
Example #2
0
        /// <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();
                    }
                }
            }
        }
Example #3
0
        /// <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();
                    }
                }
            }
        }
Example #4
0
        /// <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();
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// 保存生产计划生成请购单
        /// </summary>
        public bool Save_PSBomToPrReq(string salesOrderNoStr, string pbBomNoStr, int bomListAutoIdInt, string projectNoStr, string stnNoStr, string departmentNoStr, string purCategoryStr, string approvalTypeStr)
        {
            using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("", conn, trans);

                        int    resultInt = 0;
                        string errorText = "";

                        string prReqNoStr = BaseSQL.GetMaxCodeNo(cmd, "PR");

                        SqlCommand   cmd_proc = new SqlCommand("", conn, trans);
                        SqlParameter p1       = new SqlParameter("@PbBomNo", SqlDbType.VarChar);
                        p1.Value = pbBomNoStr;
                        SqlParameter p2 = new SqlParameter("@BomListAutoId", SqlDbType.Int);
                        p2.Value = bomListAutoIdInt;
                        SqlParameter p3 = new SqlParameter("@PrReqNo", SqlDbType.VarChar);
                        p3.Value = prReqNoStr;
                        SqlParameter p4 = new SqlParameter("@ProjectNo", SqlDbType.VarChar);
                        p4.Value = projectNoStr;
                        SqlParameter p5 = new SqlParameter("@StnNo", SqlDbType.VarChar);
                        p5.Value = stnNoStr;

                        SqlParameter p6 = new SqlParameter("@DepartmentNo", SqlDbType.VarChar);
                        p6.Value = departmentNoStr;
                        SqlParameter p7 = new SqlParameter("@PurCategory", SqlDbType.VarChar);
                        p7.Value = purCategoryStr;
                        SqlParameter p8 = new SqlParameter("@ApprovalType", SqlDbType.VarChar);
                        p8.Value = approvalTypeStr;
                        SqlParameter p9 = new SqlParameter("@Creator", SqlDbType.Int);
                        p9.Value = SystemInfo.user.AutoId;
                        SqlParameter p10 = new SqlParameter("@PreparedIp", SqlDbType.VarChar);
                        p10.Value = SystemInfo.HostIpAddress;

                        IDataParameter[] parameters = new IDataParameter[] { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 };
                        BaseSQL.RunProcedure(cmd_proc, "P_PSBomToPrReq", parameters, out resultInt, out errorText);
                        if (resultInt != 1)
                        {
                            trans.Rollback();
                            MessageHandler.ShowMessageBox("生产计划生成请购单错误--" + errorText);
                            return(false);
                        }

                        string logStr = string.Format("制作Bom [{0}] 的生产计划生成请购单 [{1}]。", pbBomNoStr, prReqNoStr);
                        LogHandler.RecordLog(cmd, logStr);

                        trans.Commit();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }
Example #6
0
        /// <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();
                    }
                }
            }
        }
Example #7
0
        /// <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();
                    }
                }
            }
        }
Example #8
0
        /// <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();
                    }
                }
            }
        }
Example #9
0
        /// <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();
                    }
                }
            }
        }
Example #10
0
        /// <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();
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// 保存设计Bom信息处理Bom方法
        /// </summary>
        private bool SaveDesignBom_Bom(string salesOrderNoStr, string codeFileNameStr, float qty)
        {
            using (SqlConnection conn = new SqlConnection(BaseSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("", conn, trans);

                        int    resultInt = 0;
                        string errorText = "";

                        string pbBomNo = "";

                        string logStr = string.Format("设计Bom信息增加Bom[{0}],数量为[{1}]。", codeFileNameStr, qty);
                        LogHandler.RecordLog(cmd, logStr);

                        cmd.CommandText = string.Format("select * from PB_DesignBomList where SalesOrderNo = '{0}' and MaterielNo = '{1}' and RemainQty > 0 and ParentId = 0", salesOrderNoStr, codeFileNameStr);
                        DataTable bomMagTable = BaseSQL.GetTableBySql(cmd);
                        if (bomMagTable.Rows.Count > 0)//更新数量
                        {
                            if (qty < 0)
                            {
                                if (DataTypeConvert.GetDouble(bomMagTable.Rows[0]["RemainQty"]) + qty < 0)
                                {
                                    MessageHandler.ShowMessageBox("Bom修改后的数量必须大于等于0。");
                                    return(false);
                                }
                            }
                            pbBomNo = DataTypeConvert.GetString(bomMagTable.Rows[0]["PbBomNo"]);

                            SqlCommand   cmd_proc = new SqlCommand("", conn, trans);
                            SqlParameter p1       = new SqlParameter("@PbBomNo", SqlDbType.VarChar);
                            p1.Value = pbBomNo;
                            SqlParameter p2 = new SqlParameter("@Qty", SqlDbType.Float);
                            p2.Value = qty;
                            IDataParameter[] updateParas = new IDataParameter[] { p1, p2 };
                            BaseSQL.RunProcedure(cmd_proc, "P_DesignBom_Bom_UpdateQty", updateParas, out resultInt, out errorText);
                            if (resultInt != 1)
                            {
                                trans.Rollback();
                                MessageHandler.ShowMessageBox("设计Bom更新Bom信息错误--" + errorText);
                                return(false);
                            }
                        }
                        else//新增记录
                        {
                            pbBomNo = BaseSQL.GetMaxCodeNo(cmd, "PB");

                            SqlCommand   cmd_proc = new SqlCommand("", conn, trans);
                            SqlParameter p1       = new SqlParameter("@SalesOrderNo", SqlDbType.VarChar);
                            p1.Value = salesOrderNoStr;
                            SqlParameter p2 = new SqlParameter("@PbBomNo", SqlDbType.VarChar);
                            p2.Value = pbBomNo;
                            SqlParameter p3 = new SqlParameter("@CodeFileName", SqlDbType.VarChar);
                            p3.Value = codeFileNameStr;
                            SqlParameter p4 = new SqlParameter("@Qty", SqlDbType.Float);
                            p4.Value = qty;
                            SqlParameter p5 = new SqlParameter("@Creator", SqlDbType.Int);
                            p5.Value = SystemInfo.user.AutoId;
                            SqlParameter p6 = new SqlParameter("@PreparedIp", SqlDbType.VarChar);
                            p6.Value = SystemInfo.HostIpAddress;
                            IDataParameter[] insertParas = new IDataParameter[] { p1, p2, p3, p4, p5, p6 };
                            BaseSQL.RunProcedure(cmd_proc, "P_DesignBom_Bom_Insert", insertParas, out resultInt, out errorText);
                            if (resultInt != 1)
                            {
                                trans.Rollback();
                                MessageHandler.ShowMessageBox("设计Bom新增Bom信息错误--" + errorText);
                                return(false);
                            }
                        }

                        //进行吸收其他Bom和零件
                        SqlCommand   cmd_Absorb = new SqlCommand("", conn, trans);
                        SqlParameter p1_Absorb  = new SqlParameter("@SalesOrderNo", SqlDbType.VarChar);
                        p1_Absorb.Value = salesOrderNoStr;
                        SqlParameter p2_Absorb = new SqlParameter("@PbBomNo", SqlDbType.VarChar);
                        p2_Absorb.Value = pbBomNo;
                        SqlParameter p3_Absorb = new SqlParameter("@MainBomAutoId", SqlDbType.Int);
                        p3_Absorb.Value = 0;
                        SqlParameter p4_Absorb = new SqlParameter("@ParentId", SqlDbType.Int);
                        p4_Absorb.Value = 0;
                        SqlParameter p5_Absorb = new SqlParameter("@OpQty", SqlDbType.Float);
                        p5_Absorb.Value = qty;
                        IDataParameter[] parameters = new IDataParameter[] { p1_Absorb, p2_Absorb, p3_Absorb, p4_Absorb, p5_Absorb };
                        BaseSQL.RunProcedure(cmd_Absorb, "P_DesignBom_Bom_Absorbed", parameters, out resultInt, out errorText);
                        if (resultInt != 1)
                        {
                            trans.Rollback();
                            MessageHandler.ShowMessageBox("设计Bom吸收Bom和零件数量错误--" + errorText);
                            return(false);
                        }
                        //没有被动吸收 被其他Bom吸收

                        trans.Commit();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }
Example #12
0
        /// <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="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();
                    }
                }
            }
        }
Example #14
0
        /// <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();
                    }
                }
            }
        }