private void TableCreation()
        {
            try
            {
                ____bobCompany.StartTransaction();

                AddTables("AW_B1CZHDR", "B1 Customize Header", SAPbobsCOM.BoUTBTableType.bott_MasterData);
                AddTables("AW_B1CZDTL", "B1 Customize Rows", SAPbobsCOM.BoUTBTableType.bott_MasterDataLines);
                AddFields("@AW_B1CZHDR", "DocEntry", "DocEntry", SAPbobsCOM.BoFieldTypes.db_Numeric, SAPbobsCOM.BoFldSubTypes.st_None, 11, null, null, false, null);

                AddFields("@AW_B1CZDTL", "DocEntry", "DocEntry", SAPbobsCOM.BoFieldTypes.db_Numeric, SAPbobsCOM.BoFldSubTypes.st_None, 11, null, null, false, null);
                AddFields("@AW_B1CZDTL", "AsColNotes", "Collection Notes", SAPbobsCOM.BoFieldTypes.db_Memo, SAPbobsCOM.BoFldSubTypes.st_None, 254, null, null, false, null);
                AddFields("@AW_B1CZDTL", "UpdateDate", "Update Date", SAPbobsCOM.BoFieldTypes.db_Date, SAPbobsCOM.BoFldSubTypes.st_None, 12, null, null, false, null);

                if (-1 == RegisterObject("UDOB1CZHDR", "B1 Customize", "MD", "AW_B1CZHDR", "AW_B1CZDTL", false, false, false, true, true, false, false, "DocEntry", false, "", true))
                {
                    __app.StatusBar.SetText("Object Registration failed.....", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); return;
                }

                if (____bobCompany.InTransaction == true)
                {
                    ____bobCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                }
            }
            catch (Exception ex)
            {
                __app.SetStatusBarMessage(ex.Message.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, true);
            }
        }
Пример #2
0
        //This Method is for the SAP BP Master Creation;
        //public string SPA_AddCase(DataTable dtDatatable)
        //{
        //    DataSet oDataset = new DataSet();
        //    string sFuncName = string.Empty;
        //    string sProcName = string.Empty;
        //    DataView oDTView = new DataView();
        //    string sResult = string.Empty;
        //    string sCardCode = string.Empty;
        //    string sDocEntry = string.Empty;
        //    try
        //    {
        //        sFuncName = "SPA_AddCase()";
        //        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName);
        //        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Before calling the Method SPA_AddCase_CheckStatus", sFuncName);
        //        DataSet dsResult = SPA_AddCase_CheckStatus();
        //        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("After calling the Method SPA_AddCase_CheckStatus", sFuncName);
        //        if (dsResult != null && dsResult.Tables.Count > 0)
        //        {
        //            if (dsResult.Tables[0].Rows[0]["CaseStatus"].ToString() != string.Empty)
        //            {
        //                sCardCode = dsResult.Tables[0].Rows[0]["CardCode"].ToString();
        //                sDocEntry = dsResult.Tables[0].Rows[0]["DocEntry"].ToString();
        //                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Connecting to target company ", sFuncName);
        //                oDICompany = oLogin.ConnectToTargetCompany(ConnectionString);
        //                SAPbobsCOM.BusinessPartners oBP = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
        //                oBP.GetByKey("SSS");
        //                oBP.UserFields.Fields.Item("").Value = "";
        //                //CUFD Table - For Listing the UDF's
        //                //SAPbobsCOM.GeneralService oGeneralService = null;
        //                //SAPbobsCOM.GeneralData oGeneralData;
        //                //SAPbobsCOM.CompanyService oCompanyService = oDICompany.GetCompanyService();
        //                //SAPbobsCOM.GeneralDataParams oGeneralParams = null;
        //                //oGeneralService = oCompanyService.GetGeneralService("OCRD");
        //                //oGeneralParams = (SAPbobsCOM.GeneralDataParams)oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams);
        //                //oGeneralParams.SetProperty("DocEntry", sDocEntry);
        //                //oGeneralData = oGeneralService.GetByParams(oGeneralParams);
        //                //oGeneralData.SetProperty("QryGroup3", dsResult.Tables[0].Rows[0]["QryGroup3"].ToString());
        //                //oGeneralService.Update(oGeneralData);
        //                //sResult = "Document Updated Successfully for the CardCode = " + sCardCode + " and DocEntry = " + sDocEntry;
        //            }
        //            else
        //            {
        //                string sUserName = dtDatatable.Rows[0]["UserName"].ToString();
        //                string sPassword = dtDatatable.Rows[0]["Password"].ToString();
        //                string sCategory = dtDatatable.Rows[0]["Category"].ToString();
        //                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Before calling the Method SPA_AddCase_CheckStatus", sFuncName);
        //                DataSet dsCardCode = SPA_AddCase_GetCardCode(sUserName, sPassword, sCategory);
        //                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("After calling the Method SPA_AddCase_CheckStatus", sFuncName);
        //                sCardCode = dsCardCode.Tables[0].Rows[0]["CardCode"].ToString();
        //                sResult = "Add Document for the CardCode = " + sCardCode;
        //            }
        //        }
        //    }
        //    catch (Exception Ex)
        //    {
        //        sErrDesc = Ex.Message.ToString();
        //        oLog.WriteToErrorLogFile(sErrDesc, sFuncName);
        //        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR  ", sFuncName);
        //        throw Ex;
        //    }
        //    return sResult;
        //}
        public string SPA_AddCase(DataTable dtDatatable, string sUserName)
        {
            DataSet oDataset = new DataSet();
            DataTable dtAssignCase = new DataTable();
            string sFuncName = string.Empty;
            string sProcName = string.Empty;
            DataView oDTView = new DataView();
            string sResult = string.Empty;
            string sCardCode = string.Empty;
            string sDocEntry = string.Empty;
            bool isExists = false;
            try
            {
                sFuncName = "SPA_AddCase()";
                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName);

                if (dtDatatable != null && dtDatatable.Rows.Count > 0)
                {
                    //sCardCode = dsResult.Tables[0].Rows[0]["CardCode"].ToString();
                    //sDocEntry = dsResult.Tables[0].Rows[0]["DocEntry"].ToString();

                    DataRow dr = dtDatatable.Rows[0];

                    if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Connecting to target company ", sFuncName);
                    oDICompany = oLogin.ConnectToTargetCompany(ConnectionString);

                    SAPbobsCOM.BusinessPartners oBP = (SAPbobsCOM.BusinessPartners)(oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners));

                    if (oBP.GetByKey(dr["CardCode"].ToString()))
                    {
                        //exists
                        isExists = true;
                    }
                    else
                    {
                        //not exists
                        oBP.CardCode = dr["CardCode"].ToString();
                    }

                    //  oBP.CardCode = dr["CardCode"].ToString();
                    oBP.CardName = dr["CardName"].ToString();
                    oBP.CardForeignName = dr["CardFName"].ToString();
                    oBP.CardType = SAPbobsCOM.BoCardTypes.cCustomer;
                    oBP.GroupCode = Convert.ToInt32(dr["GroupCode"]);
                    oBP.PayTermsGrpCode = -1;

                    oBP.Currency = dr["Currency"].ToString();
                    oBP.AdditionalID = dr["AddID"].ToString();

                    if (dr["QryGroup3"].ToString() == "Y")
                    {
                        oBP.set_Properties(3, SAPbobsCOM.BoYesNoEnum.tYES);
                    }
                    if (dr["QryGroup4"].ToString() == "Y")
                    {
                        oBP.set_Properties(4, SAPbobsCOM.BoYesNoEnum.tYES);
                    } if (dr["QryGroup5"].ToString() == "Y")
                    {
                        oBP.set_Properties(5, SAPbobsCOM.BoYesNoEnum.tYES);
                    } if (dr["QryGroup6"].ToString() == "Y")
                    {
                        oBP.set_Properties(6, SAPbobsCOM.BoYesNoEnum.tYES);
                    } if (dr["QryGroup7"].ToString() == "Y")
                    {
                        oBP.set_Properties(7, SAPbobsCOM.BoYesNoEnum.tYES);
                    } if (dr["QryGroup8"].ToString() == "Y")
                    {
                        oBP.set_Properties(8, SAPbobsCOM.BoYesNoEnum.tYES);
                    } if (dr["QryGroup9"].ToString() == "Y")
                    {
                        oBP.set_Properties(9, SAPbobsCOM.BoYesNoEnum.tYES);
                    } if (dr["QryGroup10"].ToString() == "Y")
                    {
                        oBP.set_Properties(10, SAPbobsCOM.BoYesNoEnum.tYES);
                    } if (dr["QryGroup11"].ToString() == "Y")
                    {
                        oBP.set_Properties(11, SAPbobsCOM.BoYesNoEnum.tYES);
                    } if (dr["QryGroup17"].ToString() == "Y")
                    {
                        oBP.set_Properties(17, SAPbobsCOM.BoYesNoEnum.tYES);
                    } if (dr["QryGroup21"].ToString() == "Y")
                    {
                        oBP.set_Properties(21, SAPbobsCOM.BoYesNoEnum.tYES);
                    }
                    if (dr["U_PROPERTY_CHARGED"].ToString() == "Y")
                    {
                        oBP.set_Properties(12, SAPbobsCOM.BoYesNoEnum.tYES);
                        oBP.set_Properties(13, SAPbobsCOM.BoYesNoEnum.tNO);
                    }
                    if (dr["U_PROPERTY_FREE"].ToString() == "Y")
                    {
                        oBP.set_Properties(12, SAPbobsCOM.BoYesNoEnum.tNO);
                        oBP.set_Properties(13, SAPbobsCOM.BoYesNoEnum.tYES);
                    }

                    oBP.DebitorAccount = dr["DebPayAcct"].ToString(); //if cardCode without 'C', then its DebPayAcct else SalesDebPayAcct
                    oBP.ProjectCode = dr["ProjectCod"].ToString();
                    oBP.OwnerIDNumber = dr["U_CASE_BRANCH"].ToString();

                    oBP.UserFields.Fields.Item("U_CASESTATUS").Value = dr["U_CASESTATUS"].ToString();
                    oBP.UserFields.Fields.Item("U_FILEOPENDATE").Value = dr["U_FILEOPENDATE"].ToString();

                    //oBP.UserFields.Fields.Item("U_PARTNER_EMPID").Value = dr["U_PARTNER_EMPID"].ToString();
                    //oBP.UserFields.Fields.Item("U_LA_EMPID").Value = dr["U_LA_EMPID"].ToString();
                    //oBP.UserFields.Fields.Item("U_MANAGER_EMPID").Value = dr["U_MANAGER_EMPID"].ToString();
                    //oBP.UserFields.Fields.Item("U_IC_EMPID").Value = dr["U_IC_EMPID"].ToString();
                    //oBP.UserFields.Fields.Item("U_CS_EMPID").Value = dr["U_CS_EMPID"].ToString();

                    oBP.UserFields.Fields.Item("U_PURCH_RP_ID1").Value = dr["U_PURCH_RP_ID1"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_NAME1").Value = dr["U_PURCH_RP_NAME1"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_CODE1").Value = dr["U_PURCH_RP_CODE1"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_TAX1").Value = dr["U_PURCH_RP_TAX1"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_CONTACT1").Value = dr["U_PURCH_CONTACT1"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_IDTYPE1").Value = dr["U_PURCH_IDTYPE1"].ToString();

                    oBP.UserFields.Fields.Item("U_PURCH_RP_ID2").Value = dr["U_PURCH_RP_ID2"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_NAME2").Value = dr["U_PURCH_RP_NAME2"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_CODE2").Value = dr["U_PURCH_RP_CODE2"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_TAX2").Value = dr["U_PURCH_RP_TAX2"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_CONTACT2").Value = dr["U_PURCH_CONTACT2"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_IDTYPE2").Value = dr["U_PURCH_IDTYPE2"].ToString();

                    oBP.UserFields.Fields.Item("U_PURCH_RP_ID3").Value = dr["U_PURCH_RP_ID3"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_NAME3").Value = dr["U_PURCH_RP_NAME3"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_CODE3").Value = dr["U_PURCH_RP_CODE3"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_TAX3").Value = dr["U_PURCH_RP_TAX3"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_CONTACT3").Value = dr["U_PURCH_CONTACT3"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_IDTYPE3").Value = dr["U_PURCH_IDTYPE3"].ToString();

                    oBP.UserFields.Fields.Item("U_PURCH_RP_ID4").Value = dr["U_PURCH_RP_ID4"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_NAME4").Value = dr["U_PURCH_RP_NAME4"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_CODE4").Value = dr["U_PURCH_RP_CODE4"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_TAX4").Value = dr["U_PURCH_RP_TAX4"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_CONTACT4").Value = dr["U_PURCH_CONTACT4"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_IDTYPE4").Value = dr["U_PURCH_IDTYPE4"].ToString();

                    oBP.UserFields.Fields.Item("U_VNDR_RP_ID1").Value = dr["U_VNDR_RP_ID1"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_NAME1").Value = dr["U_VNDR_RP_NAME1"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_CODE1").Value = dr["U_VNDR_RP_CODE1"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_TAX1").Value = dr["U_VNDR_RP_TAX1"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_CONTACT1").Value = dr["U_VNDR_CONTACT1"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_IDTYPE1").Value = dr["U_VNDR_IDTYPE1"].ToString();

                    oBP.UserFields.Fields.Item("U_VNDR_RP_ID2").Value = dr["U_VNDR_RP_ID2"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_NAME2").Value = dr["U_VNDR_RP_NAME2"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_CODE2").Value = dr["U_VNDR_RP_CODE2"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_TAX2").Value = dr["U_VNDR_RP_TAX2"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_CONTACT2").Value = dr["U_VNDR_CONTACT2"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_IDTYPE2").Value = dr["U_VNDR_IDTYPE2"].ToString();

                    oBP.UserFields.Fields.Item("U_VNDR_RP_ID3").Value = dr["U_VNDR_RP_ID3"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_NAME3").Value = dr["U_VNDR_RP_NAME3"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_CODE3").Value = dr["U_VNDR_RP_CODE3"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_TAX3").Value = dr["U_VNDR_RP_TAX3"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_CONTACT3").Value = dr["U_VNDR_CONTACT3"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_IDTYPE3").Value = dr["U_VNDR_IDTYPE3"].ToString();

                    oBP.UserFields.Fields.Item("U_VNDR_RP_ID4").Value = dr["U_VNDR_RP_ID4"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_NAME4").Value = dr["U_VNDR_RP_NAME4"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_CODE4").Value = dr["U_VNDR_RP_CODE4"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_TAX4").Value = dr["U_VNDR_RP_TAX4"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_CONTACT4").Value = dr["U_VNDR_CONTACT4"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_IDTYPE4").Value = dr["U_VNDR_IDTYPE4"].ToString();

                    oBP.UserFields.Fields.Item("U_PROPERTY_CODE").Value = dr["U_PROPERTY_CODE"].ToString();
                    oBP.UserFields.Fields.Item("U_CHRG_BANK_CODE").Value = dr["U_CHRG_BANK_CODE"].ToString();
                    oBP.UserFields.Fields.Item("U_CHRG_BANK_BRANCH").Value = dr["U_CHRG_BANK_BRANCH"].ToString();
                    oBP.UserFields.Fields.Item("U_CHRG_BANK_PA_NAME").Value = dr["U_CHRG_BANK_PA_NAME"].ToString();
                    oBP.UserFields.Fields.Item("U_CHRG_BANK_PRSNTNO").Value = dr["U_CHRG_BANK_PRSNTNO"].ToString();

                    oBP.UserFields.Fields.Item("U_TITLETYPE").Value = dr["U_TITLETYPE"].ToString();
                    oBP.UserFields.Fields.Item("U_TITLENO").Value = dr["U_TITLENO"].ToString();
                    oBP.UserFields.Fields.Item("U_LOTNO").Value = dr["U_LOTNO"].ToString();
                    oBP.UserFields.Fields.Item("U_LOTTYPE").Value = dr["U_LOTTYPE"].ToString();
                    oBP.UserFields.Fields.Item("U_FORMERLY_KNOWN_AS").Value = dr["U_FORMERLY_KNOWN_AS"].ToString();
                    oBP.UserFields.Fields.Item("U_STATE").Value = dr["U_STATE"].ToString();
                    oBP.UserFields.Fields.Item("U_AREA").Value = dr["U_AREA"].ToString();
                    oBP.UserFields.Fields.Item("U_BPM").Value = dr["U_BPM"].ToString();
                    oBP.UserFields.Fields.Item("U_LOTAREA").Value = dr["U_LOTAREA"].ToString();
                    oBP.UserFields.Fields.Item("U_PROPERTY_PURPRC").Value = dr["PurchasePrice"].ToString();

                    //oBP.UserFields.Fields.Item("U_PARTNER_FST_NAME").Value = dr["U_PARTNER_FST_NAME"].ToString();
                    //oBP.UserFields.Fields.Item("U_LA_FST_NAME").Value = dr["U_LA_FST_NAME"].ToString();
                    //oBP.UserFields.Fields.Item("U_MANAGER_FST_NAME").Value = dr["U_MANAGER_FST_NAME"].ToString();
                    //oBP.UserFields.Fields.Item("U_IC_FST_NAME").Value = dr["U_IC_FST_NAME"].ToString();
                    //oBP.UserFields.Fields.Item("U_CS_FST_NAME").Value = dr["U_CS_FST_NAME"].ToString();

                    oBP.UserFields.Fields.Item("U_PROJECT_NAME").Value = dr["U_PROJECT_NAME"].ToString();
                    oBP.UserFields.Fields.Item("U_CASE_BRANCH").Value = dr["U_CASE_BRANCH"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_FIRM").Value = dr["U_PURCH_RP_FIRM"].ToString();
                    oBP.UserFields.Fields.Item("U_PURCH_RP_LWYR").Value = dr["U_PURCH_RP_LWYR"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_FIRM").Value = dr["U_VNDR_RP_FIRM"].ToString();
                    oBP.UserFields.Fields.Item("U_VNDR_RP_LWYR").Value = dr["U_VNDR_RP_LWYR"].ToString();

                    if (!oDICompany.InTransaction) oDICompany.StartTransaction();

                    double lRetCode;
                    if (isExists == true)
                    {
                        lRetCode = oBP.Update();
                    }
                    else
                    {
                        lRetCode = oBP.Add();
                    }
                    if (lRetCode == 0)
                    {
                        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("BP Record Created Successfully ", sFuncName);
                        oBP.GetByKey(dr["CardCode"].ToString());
                        oBP.CardCode = dr["SalesCardCode"].ToString();
                        oBP.CardName = dr["SalesCardName"].ToString();
                        oBP.CardForeignName = dr["SalesCardFName"].ToString();

                        lRetCode = oBP.Add();
                        if (lRetCode == 0)
                        {
                            if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("BP Record Duplicated Successfully ", sFuncName);
                            oBP.GetByKey(dr["SalesCardCode"].ToString());
                            oBP.DebitorAccount = dr["SalesDebPayAcct"].ToString();
                            lRetCode = oBP.Update();
                            if (lRetCode == 0)
                            {
                                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("BP Record DebitorAccount Updated Successfully ", sFuncName);
                            }
                            sResult = "Customer Added/ successfully for the CardName = " + dr["CardName"].ToString();
                        }
                        else
                        {
                            if (oDICompany.InTransaction) oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            sResult = oDICompany.GetLastErrorDescription(); throw new ArgumentException(sResult);
                        }

                        //Assign the Case

                        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting to assign the case ", sFuncName);
                        if (dr["SubRole"].ToString() == "CS")
                        {
                            oDataset = SqlHelper.ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, "assignCase",
                                               Data.CreateParameter("@apptype", dr["Category"].ToString()), Data.CreateParameter("@caseno", dr["CardCode"].ToString()));
                            if (oDataset != null && oDataset.Tables.Count > 0)
                            {
                                if (oDataset.Tables[0].Rows.Count > 0)
                                {
                                    oBP.GetByKey(dr["CardCode"].ToString());
                                    oBP.UserFields.Fields.Item("U_PARTNER_EMPID").Value = oDataset.Tables[0].Rows[0]["PTEmpId"].ToString();
                                    oBP.UserFields.Fields.Item("U_LA_EMPID").Value = oDataset.Tables[0].Rows[0]["LAEmpId"].ToString();
                                    oBP.UserFields.Fields.Item("U_MANAGER_EMPID").Value = oDataset.Tables[0].Rows[0]["MGEmpId"].ToString();
                                    oBP.UserFields.Fields.Item("U_IC_EMPID").Value = oDataset.Tables[0].Rows[0]["ICEmpId"].ToString();
                                    oBP.UserFields.Fields.Item("U_CS_EMPID").Value = dr["EmpId"].ToString();

                                    oBP.UserFields.Fields.Item("U_PARTNER_FST_NAME").Value = oDataset.Tables[0].Rows[0]["PTEmpName"].ToString();
                                    oBP.UserFields.Fields.Item("U_LA_FST_NAME").Value = oDataset.Tables[0].Rows[0]["LAEmpName"].ToString();
                                    oBP.UserFields.Fields.Item("U_MANAGER_FST_NAME").Value = oDataset.Tables[0].Rows[0]["MGEmpName"].ToString();
                                    oBP.UserFields.Fields.Item("U_IC_FST_NAME").Value = oDataset.Tables[0].Rows[0]["ICEmpName"].ToString();
                                    oBP.UserFields.Fields.Item("U_CS_FST_NAME").Value = dr["EmpName"].ToString();

                                    lRetCode = oBP.Update();
                                    if (lRetCode == 0)
                                    {
                                        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Case assigned successfully for CS ", sFuncName);
                                    }
                                    else
                                    {
                                        if (oDICompany.InTransaction) oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                        sResult = oDICompany.GetLastErrorDescription(); throw new ArgumentException(sResult);
                                    }
                                }
                            }
                        }
                        else if (dr["SubRole"].ToString() == "IC")
                        {
                            oDataset = SqlHelper.ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, "assigncase_ICuser",
                                               Data.CreateParameter("@apptype", dr["Category"].ToString()), Data.CreateParameter("@usercode", sUserName.ToString()));
                            if (oDataset != null && oDataset.Tables.Count > 0)
                            {
                                if (oDataset.Tables[0].Rows.Count > 0)
                                {
                                    oBP.GetByKey(dr["CardCode"].ToString());
                                    oBP.UserFields.Fields.Item("U_PARTNER_EMPID").Value = oDataset.Tables[0].Rows[0]["PTEmpId"].ToString();
                                    oBP.UserFields.Fields.Item("U_LA_EMPID").Value = oDataset.Tables[0].Rows[0]["LAEmpId"].ToString();
                                    oBP.UserFields.Fields.Item("U_MANAGER_EMPID").Value = oDataset.Tables[0].Rows[0]["MGEmpId"].ToString();
                                    oBP.UserFields.Fields.Item("U_IC_EMPID").Value = oDataset.Tables[0].Rows[0]["ICEmpId"].ToString();

                                    oBP.UserFields.Fields.Item("U_PARTNER_FST_NAME").Value = oDataset.Tables[0].Rows[0]["PTEmpName"].ToString();
                                    oBP.UserFields.Fields.Item("U_LA_FST_NAME").Value = oDataset.Tables[0].Rows[0]["LAEmpName"].ToString();
                                    oBP.UserFields.Fields.Item("U_MANAGER_FST_NAME").Value = oDataset.Tables[0].Rows[0]["MGEmpName"].ToString();
                                    oBP.UserFields.Fields.Item("U_IC_FST_NAME").Value = oDataset.Tables[0].Rows[0]["ICEmpName"].ToString();

                                    lRetCode = oBP.Update();
                                    if (lRetCode == 0)
                                    {
                                        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Case assigned successfully for IC ", sFuncName);
                                    }
                                    else
                                    {
                                        if (oDICompany.InTransaction) oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                        sResult = oDICompany.GetLastErrorDescription(); throw new ArgumentException(sResult);
                                    }
                                }
                            }
                        }

                        // Create sales Quotation
                        //ItemCode -

                        if (oDICompany.InTransaction) oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);

                        DataTable dt = new DataTable();
                        DataSet ds = SPA_AddCase_GetSalesQuotationItems(dr["CardCode"].ToString());
                        if (ds != null && ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                dt = ds.Tables[0];

                                if (dt.Rows.Count > 0)
                                {

                                    if (Add_SalesQuotation(dt, oDICompany, dr["CardCode"].ToString(), sErrDesc) != "SUCCESS")
                                        throw new ArgumentException(sErrDesc);
                                }

                            }
                        }

                        // After Customer added in BP Master, Update the BPCode in the TempOCRD Table
                        SqlConnection con = new SqlConnection(ConnectionString);
                        SqlCommand command = con.CreateCommand();
                        command.CommandText = "Update [AE_OCRD] set U_BPCode ='" + dr["CardCode"].ToString() + "' where Code ='" + dr["TempCardCode"].ToString() + "'";
                        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Executing the Query : " + command.CommandText, sFuncName);

                        con.Open();
                        command.ExecuteNonQuery();
                        con.Close();

                        sResult = "SUCCESS" + dr["CardCode"].ToString();
                    }
                    else
                    {
                        if (oDICompany.InTransaction) oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                        sResult = oDICompany.GetLastErrorDescription(); throw new ArgumentException(sResult);
                    }
                }
            }
            catch (Exception Ex)
            {
                //if (oDICompany.InTransaction) oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                sErrDesc = Ex.Message.ToString();
                oLog.WriteToErrorLogFile(sErrDesc, sFuncName);
                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR  ", sFuncName);
                sResult = Ex.Message.ToString();
                throw Ex;
            }
            return sResult;
        }
Пример #3
0
        private static void CriarEstruturaDeDados()
        {
            Dialogs.Info(":: " + _addonName + " :: Criando tabelas e estruturas de dados ...");

            try
            {
                _company.StartTransaction();

                var tabela_detalhe_item = new Tabela("U_UPD_CCD1", "Detalhes do item Previsto"
                                                     , SAPbobsCOM.BoUTBTableType.bott_DocumentLines
                                                     , new List <Coluna>()
                {
                    new ColunaVarchar("ItemCode", "Código do Item", 30, true),
                    new ColunaVarchar("ItemName", "Descrição do Item", 120, true),
                    new ColunaPercent("PercItem", "Percentagem Classe", true),
                    new ColunaInt("teste", "teste", true),
                });

                var tabela_contratos = new TabelaUDO("U_UPD_OCCD", "Definições Gerais do Contrato"
                                                     , SAPbobsCOM.BoUTBTableType.bott_Document
                                                     , new List <Coluna>()
                {
                    new ColunaVarchar("CardCode", "Código Fornecedor", 15, true, ""),
                    new ColunaVarchar("CardName", "Descrição Fornecedor", 100, true, ""),
                    new ColunaVarchar("CtName", "Pessoa de Contato", 50, true, ""),
                    new ColunaVarchar("Tel1", "Pessoa de Contato", 15, true, ""),
                    new ColunaVarchar("EMail", "E-mail", 50, true, ""),
                    new ColunaDate("DtPrEnt", "Data Previsão Entrega", true),
                    new ColunaDate("DtPrPgt", "Data Programa Entrega", true),
                    new ColunaInt("ModCtto", "Modalidade Contrato", true),
                    new ColunaInt("teste", "teste", true),
                }
                                                     , new UDOParams()
                {
                    CanDelete = SAPbobsCOM.BoYesNoEnum.tNO
                }
                                                     , new List <Tabela>()
                {
                    tabela_detalhe_item
                }
                                                     );

                //Database.ExcluirColuna(tabela_contratos.NomeComArroba, "teste");


                //var coluna_teste = new ColunaInt("testex", "xtestex", true);
                //Database.CriarColuna(tabela_contratos.NomeComArroba, coluna_teste);
                //Database.DefinirColunasComoUDO(tabela_contratos.NomeComArroba, new List<Coluna>() { coluna_teste });

                //Database.ExcluirTabela(tabela_contratos.NomeSemArroba);

                _company.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
            }
            catch (DatabaseException e)
            {
                Dialogs.PopupError(e.Message);
            }
            catch (Exception e)
            {
                _company.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                Dialogs.PopupError("Erro interno.\nErro: " + e.Message);
            }
        }
Пример #4
0
        public static void GenearLeadSAP2(string agente, string solicitud, string codigoAsistente, string nombreAsistente, int dia, int mes, int year, string telefono, string nombre, string apellidoP, string apellidoM,
                                          string direccion, string entreCalles, string municipio, string colonia, string observaciones, string nvoIngreso, string codigoPostal, string rfc, string esquema,
                                          ref string msgError, ref string CodigoActivacion)
        {
            SAPbobsCOM.BusinessPartners oSocioNegocio = null;
            string cardCodeGenerate = null;
            string nombreCompleto   = null;

            Conexiones.ConexionSAP _oConnection = new Conexiones.ConexionSAP();
            try
            {
                _oConnection = new Conexiones.ConexionSAP();
                if (_oConnection.ConectarSAP(ref msgError))
                {
                    oCompany = _oConnection._oCompany;
                    oCompany.StartTransaction();
                    nombreCompleto = nombre.TrimEnd(' ') + ' ' + apellidoP.TrimEnd(' ') + ' ' + apellidoM.TrimEnd(' ');
                    oSocioNegocio  = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
                    ObtenerDatosSolicitudValidacion(solicitud);
                    oSocioNegocio.Series         = DatosSolicitud.ElementAt(0).serieLead;
                    oSocioNegocio.CardType       = SAPbobsCOM.BoCardTypes.cLid;
                    oSocioNegocio.GroupCode      = ObtenerGrupoLead();
                    oSocioNegocio.CardName       = nombreCompleto;
                    oSocioNegocio.FederalTaxID   = rfc;
                    oSocioNegocio.DebitorAccount = Extensor.Configuracion.VENTANA.CuentaLead;
                    oSocioNegocio.UserFields.Fields.Item("U_QCapturaContrato").Value = agente;
                    oSocioNegocio.UserFields.Fields.Item("U_SolicitudInt").Value     = solicitud;
                    oSocioNegocio.UserFields.Fields.Item("U_CodigoPromotor").Value   = codigoAsistente;
                    oSocioNegocio.UserFields.Fields.Item("U_NomProm").Value          = nombreAsistente;
                    oSocioNegocio.UserFields.Fields.Item("U_Dia").Value  = dia.ToString();
                    oSocioNegocio.UserFields.Fields.Item("U_Mes").Value  = mes.ToString();
                    oSocioNegocio.UserFields.Fields.Item("U_Year").Value = year.ToString();
                    oSocioNegocio.UserFields.Fields.Item("U_ComentarioContrato").Value = observaciones;
                    oSocioNegocio.UserFields.Fields.Item("U_PersonaNvoIngreso").Value  = nvoIngreso;
                    oSocioNegocio.UserFields.Fields.Item("U_NumArt_").Value            = DatosSolicitud.ElementAt(0).plan;
                    oSocioNegocio.UserFields.Fields.Item("U_Dsciption").Value          = DatosSolicitud.ElementAt(0).nombrePlan;
                    oSocioNegocio.UserFields.Fields.Item("U_PrefijoPlan").Value        = DatosSolicitud.ElementAt(0).prefijoPlan;
                    oSocioNegocio.UserFields.Fields.Item("U_FechaCaptura").Value       = DateTime.Now.ToShortDateString();
                    oSocioNegocio.UserFields.Fields.Item("U_HoraCaptura").Value        = DateTime.Now.ToString("HH:mm:ss");
                    oSocioNegocio.UserFields.Fields.Item("U_Esquema_pago").Value       = esquema;

                    if (nombreCompleto.Length > 70)
                    {
                        oSocioNegocio.UserFields.Fields.Item("U_BeneficiarioPagoRe").Value = nombreCompleto.ToString().Substring(1, 70);
                    }
                    else
                    {
                        oSocioNegocio.UserFields.Fields.Item("U_BeneficiarioPagoRe").Value = nombreCompleto;
                    }
                    oSocioNegocio.Addresses.AddressType       = SAPbobsCOM.BoAddressType.bo_BillTo;
                    oSocioNegocio.Addresses.AddressName       = "DIRECCION 1";
                    oSocioNegocio.Addresses.AddressName2      = telefono;
                    oSocioNegocio.Addresses.Street            = direccion;
                    oSocioNegocio.Addresses.BuildingFloorRoom = entreCalles;
                    oSocioNegocio.Addresses.City    = municipio;
                    oSocioNegocio.Addresses.Block   = colonia;
                    oSocioNegocio.Addresses.ZipCode = codigoPostal;
                    oSocioNegocio.Addresses.State   = "JAL";

                    if (oSocioNegocio.Add() != 0)
                    {
                        msgError = "Error: " + oCompany.GetLastErrorDescription();
                    }
                    else
                    {
                        //oCompany.GetNewObjectCode(out cardCodeGenerate);
                        msgError = "";
                    }
                }
                else
                {
                    msgError = "Error: " + msgError;
                }
            }
            catch (Exception ex)
            {
                msgError = "Error: " + msgError + " : " + ex.Message;
            }
            finally
            {
                if (!msgError.Contains("Error"))
                {
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                    //CodigoActivacion = ObtenerCodigoActivacionGenerado(cardCodeGenerate);
                    //msgError = "El código de activación es: " + CodigoActivacion;
                }
                else
                {
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                }
                if (oSocioNegocio != null)
                {
                    GC.SuppressFinalize(oSocioNegocio);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oSocioNegocio);
                    oSocioNegocio = null;
                }
                GC.Collect();
                ClearMemory();
                oCompany.Disconnect();
            }
        }
        public string InsertarRegistroInspeccion()
        {
            bool   resultado = TransferirStock("DISP PRO", "CUART MP", "21019908", "MP117060263", 50);
            string numTrans;

            if (resultado == true)
            {
                numTrans = oCompany.GetNewObjectKey();
            }
            else
            {
                return("Error " + oCompany.GetLastErrorCode() + "-" + oCompany.GetLastErrorDescription());
            }

            SAPbobsCOM.GeneralService oGeneralService;

            SAPbobsCOM.GeneralData oGeneralData;

            SAPbobsCOM.GeneralData oChild;

            SAPbobsCOM.GeneralDataCollection oChildren;

            //SAPbobsCOM.GeneralDataParams oGeneralParams;

            SAPbobsCOM.CompanyService oCompService;

            oCompService = oCompany.GetCompanyService();

            oCompany.StartTransaction();

            oGeneralService = oCompService.GetGeneralService("VID_CONTROLCH");

            oGeneralData = (SAPbobsCOM.GeneralData)oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData);

            //Setting Data to Master Data Table Fields
            oGeneralData.SetProperty("U_FecIngr", "2017-06-30");

            oGeneralData.SetProperty("U_FecContr", "2017-07-03");

            oGeneralData.SetProperty("U_FecIni", "2017-07-03");

            oGeneralData.SetProperty("U_FecFin", "2017-07-03");


            oGeneralData.SetProperty("DocNum", 1);

            oGeneralData.SetProperty("U_ItemCode", "73200004");

            oGeneralData.SetProperty("U_NumTras", numTrans);

            oGeneralData.SetProperty("U_ItemName", "CAJA P/EMB Nº3 200X135X225 mm DULZERO 500ml");

            oGeneralData.SetProperty("U_WhsCode", "CUART MP");

            oGeneralData.SetProperty("U_WhsDest", "DISP PRO");

            oGeneralData.SetProperty("U_NoLote", "MEC217060012");

            oGeneralData.SetProperty("U_CorrLote", 0);

            oGeneralData.SetProperty("U_Cantidad", 3880);

            oGeneralData.SetProperty("U_Bultos", 10);

            oGeneralData.SetProperty("U_BultosMu", 4);

            oGeneralData.SetProperty("U_ContraMu", "Y");

            oGeneralData.SetProperty("U_MuestDes", "Y");

            oGeneralData.SetProperty("U_Traslado", "Y");

            oGeneralData.SetProperty("U_Reanalis", "N");

            oGeneralData.SetProperty("U_CorrAnal", 0);

            oGeneralData.SetProperty("U_FecUltIn", "2017-03-05");

            oGeneralData.SetProperty("U_UM", "UNIDAD");

            oGeneralData.SetProperty("U_CtaCalid", "6010301036");

            oGeneralData.SetProperty("U_CCCode", "CC");

            oGeneralData.SetProperty("U_Estado", "A");

            oGeneralData.SetProperty("U_TipResul", "A100");

            oGeneralData.SetProperty("U_PrjCode", "");

            oGeneralData.SetProperty("U_Comment", "Cumple con todos analisis requeridos.admision:3.358");

            oGeneralData.SetProperty("U_NumTras", numTrans);


            oChildren = oGeneralData.Child("VID_CONTROLCD");

            oChild = oChildren.Add();

            oChild.SetProperty("U_CodAtr", "The_Code");

            oChild.SetProperty("U_NameAtr", "Attribute name");

            oChild.SetProperty("U_Cualitat", "Y");

            oChild.SetProperty("U_Critico", "Y");

            oChild.SetProperty("U_TipoMues", "69");

            oChild.SetProperty("U_CodEquip", "E");

            oChild.SetProperty("U_Estado", "A");

            oChild.SetProperty("U_TipoDef", "D");

            oChild.SetProperty("U_AQL", "aql");

            oChild.SetProperty("U_Rango", "1 - 1");

            oChild.SetProperty("U_TiempoDu", "4");

            //Agregar el registro
            oGeneralService.Add(oGeneralData);

            if (oCompany.InTransaction)
            {
                oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
            }

            return("Record " + oCompany.GetNewObjectKey() + " added.");
        }
    public static void CreatePriceList(string _Code, string _Name)
    {
        SAPbobsCOM.GeneralService        oDocGeneralService;
        SAPbobsCOM.GeneralData           oDocGeneralData;
        SAPbobsCOM.GeneralDataCollection oDocLinesCollection;
        SAPbobsCOM.GeneralData           oDocLineGeneralData;

        SAPbobsCOM.CompanyService oCompService;
        oCompService = oCompany.GetCompanyService();

        // Retrieve the relevant service
        oDocGeneralService = oCompService.GetGeneralService("OCRP");
        // Point to the Header of the Doc UDO
        oDocGeneralData = (SAPbobsCOM.GeneralData)oDocGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData);

        // Insert values to the Header properties
        oDocGeneralData.SetProperty("Code", _Code);
        oDocGeneralData.SetProperty("Name", _Name);

        string    _sqlPriceList;
        DataTable _tblPriceList = new DataTable();

        _sqlPriceList = @"
                                    SELECT A.ItmsGrpCod, A.ItmsGrpNam
                                    , 0.00 AS [VISMIN DISC %]
                                    , 0.00 AS [GMA DISC %]
                                    FROM OITB A
                                    ";
        _tblPriceList = clsSQLClientFunctions.DataList(clsDeclaration.sSAPConnection, _sqlPriceList);


        foreach (DataRow row in _tblPriceList.Rows)
        {
            string _ItmsGrpNam = row["ItmsGrpNam"].ToString();
            string _VisMinDisc = row["VISMIN DISC %"].ToString();
            string _GMADisc    = row["GMA DISC %"].ToString();

            oDocLinesCollection = oDocGeneralData.Child("OCPL");
            oDocLineGeneralData = oDocLinesCollection.Add();
            oDocLineGeneralData.SetProperty("U_Category", _ItmsGrpNam);
            oDocLineGeneralData.SetProperty("U_VisMinDisc", _VisMinDisc);
            oDocLineGeneralData.SetProperty("U_GMADisc", _GMADisc);
        }


        _sqlPriceList = @"
                                        SELECT A.ItemCode, A.ItemName FROM OITM A 
                                    ";
        _tblPriceList = clsSQLClientFunctions.DataList(clsDeclaration.sSAPConnection, _sqlPriceList);


        foreach (DataRow row in _tblPriceList.Rows)
        {
            string _ItemCode = row["ItemCode"].ToString();
            string _ItemName = row["ItemName"].ToString();
            string _Value    = "0.00";

            oDocLinesCollection = oDocGeneralData.Child("OIPL");
            oDocLineGeneralData = oDocLinesCollection.Add();
            oDocLineGeneralData.SetProperty("U_ItemCode", _ItemCode);
            oDocLineGeneralData.SetProperty("U_ItemName", _ItemName);
            oDocLineGeneralData.SetProperty("U_VisMinPrice", _Value);
            oDocLineGeneralData.SetProperty("U_GMAPrice", _Value);
            oDocLineGeneralData.SetProperty("U_VisMinDisc", _Value);
            oDocLineGeneralData.SetProperty("U_GMADisc", _Value);
            oDocLineGeneralData.SetProperty("U_VisMinNet", _Value);
            oDocLineGeneralData.SetProperty("U_GMANet", _Value);
        }



        // Insert Values to the Lines properties try
        try
        {
            oDocGeneralService.Add(oDocGeneralData);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            //oDocGeneralService.Update(oDocGeneralData);
        }

        if (oCompany.InTransaction)
        {
            oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
            //SBO_Application.MessageBox("Add Doc UDO Header and Lines successfully", 1, "", "", "");
        }
        else
        {
            //SBO_Application.MessageBox("Error adding object", 1, "", "", "");
        }
    }
Пример #7
0
        public Backup()
        {
            logs.Clear();
            WriteLog("[Log]", "--------------------------------------------------------------------------------");
            WriteLog("[Log]", "Integration Begin:[" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]");


            #region Connect to SAP
            SAPbobsCOM.Company oCom         = new SAPbobsCOM.Company();
            string             dbServerType = ConfigurationManager.AppSettings.Get("dbServerType");
            if (dbServerType == "MSSQL2005")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005;
            }
            else if (dbServerType == "MSSQL2008")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008;
            }
            else if (dbServerType == "MSSQL2012")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
            }
            else if (dbServerType == "MSSQL2014")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
            }
            else if (dbServerType == "HANADB")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
            }
            else if (dbServerType == "DB_2")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_DB_2;
            }
            oCom.Server        = ConfigurationManager.AppSettings.Get("Server");
            oCom.DbUserName    = ConfigurationManager.AppSettings.Get("dbuser");
            oCom.DbPassword    = ConfigurationManager.AppSettings.Get("dbpass");
            oCom.LicenseServer = ConfigurationManager.AppSettings.Get("LicenseServer");
            oCom.CompanyDB     = ConfigurationManager.AppSettings.Get("CompanyDB");
            oCom.UserName      = ConfigurationManager.AppSettings.Get("UserName");
            oCom.Password      = ConfigurationManager.AppSettings.Get("Password");
            oCom.language      = SAPbobsCOM.BoSuppLangs.ln_English;
            if (oCom.Connect() != 0)
            {
                WriteLog("[Error]", "Connection:[" + oCom.CompanyDB + "] Message:[" + oCom.GetLastErrorDescription() + "] Time:[" + DateTime.Now.ToString("hh: mm:ss tt") + "]");
                goto EndApplication;
            }

            WriteLog("[Log]", "Connected to:[" + oCom.CompanyName + "] Time:[" + DateTime.Now.ToString("hh:mm:ss tt") + "]");
            #endregion


            #region Connect to Data Source
            SqlConnection conn = new SqlConnection(conString);
            SqlCommand    cmd  = new SqlCommand("", conn);
            conn.Close();
            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                WriteLog("[Error]", "Data Source Connection : " + DateTime.Now.ToString() + " : " + ex.Message);
                goto EndApplication;
            }

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(conString);
            string server   = builder.DataSource;
            string database = builder.InitialCatalog;
            WriteLog("[Log]", "Connected to Data Source:[" + database + "] Time:[" + DateTime.Now.ToString("hh:mm:ss tt") + "]");


            cmd.CommandText = "SELECT ROW_NUMBER() over (Partition by BaseEntry Order by BaseEntry )-1 as [Line], * " +
                              "FROM [dbo].[ProductionReceipt] T0 Where IsNull(T0.Posted,'N') <> 'Y'";
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable      dt = new DataTable();
            da.Fill(dt);

            int nGR = dt.Rows.Count;
            if (nGR == 0)
            {
                WriteLog("[Log]", "No production receipt to import!");
                conn.Close();
                da.Dispose();
                goto EndApplication;
            }

            List <int> idList = new List <int>();
            Dictionary <int, DataTable> doc = new Dictionary <int, DataTable>();

            //Parsing data into header and details
            foreach (DataRow row in dt.Rows)
            {
                int baseEntry = int.Parse(row["BaseEntry"].ToString());
                if (doc.ContainsKey(baseEntry))
                {
                    DataTable dtDoc = doc[baseEntry];
                    dtDoc.ImportRow(row);
                    doc[baseEntry] = dtDoc;
                }
                else
                {
                    DataTable dtDoc = dt.Clone();
                    dtDoc.ImportRow(row);
                    doc.Add(baseEntry, dtDoc);
                }
            }

            WriteLog("[Log]", "Record found:[" + doc.Keys.Count + "] Total Rows:[" + dt.Rows.Count + "]");


            oCom.StartTransaction();

            int n = 0;
            foreach (var item in doc)
            {
                try
                {
                    SAPbobsCOM.Documents        oDocReceipt          = (SAPbobsCOM.Documents)oCom.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry);
                    SAPbobsCOM.ProductionOrders oDocProductionOrders = (SAPbobsCOM.ProductionOrders)oCom.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders);
                    SAPbobsCOM.Items            oItem = oCom.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);

                    DataTable dtDoc = doc[item.Key];
                    DataRow   hRow  = dtDoc.Rows[0];

                    int retcode = 0;
                    idList = new List <int>();

                    string itemCode = hRow["ItemCode"].ToString();
                    oItem.GetByKey(itemCode);
                    SAPbobsCOM.BoYesNoEnum isManageBatchNumbers = oItem.ManageBatchNumbers;


                    WriteLog("[Log]", "No:[" + (++n) + "] H:Production Order[" + hRow["DocNum"].ToString() + "] Base:[" + item.Key + "] TotalRows:[" + dtDoc.Rows.Count + "]" + " PlannedQty:" + hRow["Quantity"].ToString());
                    // Add Header -----------------------------------
                    string proNo     = hRow["DocNum"].ToString();
                    int    baseEntry = int.Parse(hRow["BaseEntry"].ToString());
                    oDocReceipt.Series      = 53;
                    oDocReceipt.DocDate     = DateTime.Parse(hRow["DocDate"].ToString());
                    oDocReceipt.DocDueDate  = DateTime.Parse(hRow["DocDueDate"].ToString());
                    oDocReceipt.Comments    = hRow["Comments"].ToString();
                    oDocReceipt.JournalMemo = hRow["JournalMemo"].ToString();
                    // Add Details start ----------------------------
                    for (int i = 0; i < dtDoc.Rows.Count; i++)
                    {
                        DataRow row = dtDoc.Rows[i];
                        int     id  = int.Parse(row["Id"].ToString());

                        WriteLog("[Log]", "Id:[" + row["Id"].ToString() + "] R:[" + i + "] ItemCode:" + itemCode + "] BatchNo:" + row["DistNumber"].ToString() + " " + row["status"].ToString() + " Qty:" + row["BatchQuantity"].ToString());

                        idList.Add(id);
                        oDocReceipt.Lines.Add();
                        oDocReceipt.Lines.SetCurrentLine(i);
                        oDocReceipt.Lines.BaseType  = (int)SAPbobsCOM.BoObjectTypes.oProductionOrders;
                        oDocReceipt.Lines.BaseEntry = int.Parse(row["BaseEntry"].ToString());
                        //oDocReceipt.Lines.BaseLine = 0;
                        oDocReceipt.Lines.Quantity      = Double.Parse(row["BatchQuantity"].ToString()); //Batch Quantity = Receipt Quantity
                        oDocReceipt.Lines.WarehouseCode = "KH010";
                        oDocReceipt.Lines.FreeText      = row["Notes"].ToString();

                        //oDocReceipt.Lines.WarehouseCode = row["WarehouseCode"].ToString();
                        string status = row["Status"].ToString().Trim();
                        oDocReceipt.Lines.TransactionType = (status == "AC") ? SAPbobsCOM.BoTransactionTypeEnum.botrntComplete : SAPbobsCOM.BoTransactionTypeEnum.botrntReject;

                        if (isManageBatchNumbers.Equals("tYES"))
                        {
                            oDocReceipt.Lines.BatchNumbers.BatchNumber = row["DistNumber"].ToString();
                            oDocReceipt.Lines.BatchNumbers.Quantity    = Double.Parse(row["BatchQuantity"].ToString());
                            if (!String.IsNullOrEmpty(row["ExpiryDate"].ToString()))
                            {
                                oDocReceipt.Lines.BatchNumbers.ExpiryDate = DateTime.Parse(row["ExpiryDate"].ToString());
                            }
                            if (!String.IsNullOrEmpty(row["MnfDate"].ToString()))
                            {
                                oDocReceipt.Lines.BatchNumbers.ManufacturingDate = DateTime.Parse(row["MnfDate"].ToString());
                            }
                            if (!String.IsNullOrEmpty(row["InDate"].ToString()))
                            {
                                oDocReceipt.Lines.BatchNumbers.AddmisionDate = DateTime.Parse(row["InDate"].ToString());
                            }
                            oDocReceipt.Lines.BatchNumbers.Notes = row["Notes"].ToString();
                            oDocReceipt.Lines.BatchNumbers.Add();
                        }

                        // add line end --------------------
                    }

                    retcode = oDocReceipt.Add();
                    if (retcode == 0)
                    {
                        // Success
                        string docEntry = "";
                        string docNum   = "";

                        oCom.GetNewObjectCode(out docEntry);
                        if (docEntry == "")
                        {
                            errMsg = "Unknown Error! Please try again!";
                            if (oCom.InTransaction)
                            {
                                oCom.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }
                            WriteLog("[Error]", "Production Receipt:" + errMsg);
                            continue;
                        }
                        SAPbobsCOM.Documents sapDoc = (SAPbobsCOM.Documents)oCom.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry);
                        if (sapDoc.GetByKey(int.Parse(docEntry)))
                        {
                            docNum = sapDoc.DocNum.ToString();
                        }

                        foreach (int id in idList)
                        {
                            string     str     = "exec sp_FT_UpdateProductionOrder '" + id + "','Y','" + "" + "','" + docNum + "'";
                            SqlCommand cmdExec = new SqlCommand(str, conn);
                            cmdExec.ExecuteNonQuery();
                            WriteLog("[Success]", "Production Receipt:[" + docNum + "] has been added!");
                        }

                        if (oCom.InTransaction)
                        {
                            oCom.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                        }

                        cmd.CommandText = "SELECT CASE WHEN Sum(isNull(BatchQuantity,0.00)) >= MAX(T0.Quantity) Then 1 else 0 END " +
                                          "FROM[dbo].[ProductionReceipt] T0 " +
                                          "Where ISNULL(T0.Posted,'N') = 'Y' AND T0.BaseEntry=" + baseEntry + " GROUP BY T0.BaseEntry";

                        Int32 totalReceived = (Int32)cmd.ExecuteScalar();

                        // Closed Production
                        if (oDocProductionOrders.GetByKey(baseEntry) && totalReceived == 1)
                        {
                            string msg = "Production Order:[" + oDocProductionOrders.DocumentNumber.ToString() + "] has been closed!";
                            string rmk = oDocProductionOrders.Remarks;
                            oDocProductionOrders.ProductionOrderStatus = SAPbobsCOM.BoProductionOrderStatusEnum.boposClosed;
                            oDocProductionOrders.Remarks = rmk + " :closed by integration";
                            //oDocProductionOrders.ProductionOrderStatus = SAPbobsCOM.BoProductionOrderStatusEnum.boposCancelled;
                            oDocProductionOrders.Update();
                            WriteLog("[Success]", msg);
                            foreach (int id in idList)
                            {
                                string     str     = "exec sp_FT_UpdateProductionOrder '" + id + "','Y','" + msg + "','" + docNum + "'";
                                SqlCommand cmdExec = new SqlCommand(str, conn);
                                cmdExec.ExecuteNonQuery();
                            }
                        }
                    }
                    else
                    {  // Error
                        oCom.GetLastError(out errCode, out errMsg);
                        foreach (int id in idList)
                        {
                            string     str     = "exec sp_FT_UpdateProductionOrder '" + id + "','N','" + errMsg.Replace("'", "") + "',''";
                            SqlCommand cmdExec = new SqlCommand(str, conn);
                            cmdExec.ExecuteNonQuery();
                        }
                        WriteLog("[Error]", "Production Order:[" + proNo + "] Error Msg:" + oCom.GetLastErrorDescription());
                        if (oCom.InTransaction)
                        {
                            oCom.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                        }
                    }
                }
                catch (Exception ex)
                {
                    oCom.GetLastError(out errCode, out errMsg);
                    string msg = (ex.Message + " SAP msg:" + errMsg).Replace("'", "");
                    foreach (int id in idList)
                    {
                        string     str     = "exec sp_FT_UpdateProductionOrder '" + id + "','N','" + msg + "','" + "" + "'";
                        SqlCommand cmdExec = new SqlCommand(str, conn);
                        cmdExec.ExecuteNonQuery();
                    }
                    WriteLog("[Error]", "Production Receipt:" + msg);
                }
            }
            #endregion

EndApplication:

            bool sendEmail = false;
            foreach (KeyValuePair <string, List <string> > kvp in logs)
            {
                string        status = kvp.Key;
                List <string> msgs   = kvp.Value;
                if (status == "[Error]")
                {
                    sendEmail = true;
                }
            }
            if (sendEmail)
            {
                WriteLog("[Log]", " ➜ Send E-Mail");
                SendEmail();
            }
            ;
            WriteLog("", "Integration End");
            //Thread.Sleep(3000);
        }
Пример #8
0
        public void Add(string strKey, SAPbobsCOM.Company oCompany_S, SAPbobsCOM.Company oCompany_D, string strLogger, string strFromWare, string strToWare, string[] strValues)
        {
            DataTable oHeader        = null;
            DataTable oDetails       = null;
            int       intTStatus     = 0;
            int       intExitStatus  = 0;
            int       intEntryStatus = 0;

            SAPbobsCOM.StockTransfer oStockTransfer  = (SAPbobsCOM.StockTransfer)oCompany_S.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer);
            SAPbobsCOM.Documents     oInventoryExit  = (SAPbobsCOM.Documents)oCompany_S.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenExit);
            SAPbobsCOM.Documents     oInventoryEntry = (SAPbobsCOM.Documents)oCompany_D.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry);

            try
            {
                string str_S_OWTR = "Exec Armada_Service_S_OWTR_s '" + strKey + "'";
                oDataSet = Singleton.objSqlDataAccess.ExecuteDataSet(str_S_OWTR, strLogger);

                if (oDataSet == null && oDataSet.Tables.Count == 0)
                {
                    return;
                }
                else
                {
                    Singleton.traceService("Has Record");

                    oHeader  = oDataSet.Tables[0];
                    oDetails = oDataSet.Tables[1];

                    if (oHeader != null && oHeader.Rows.Count > 0)
                    {
                        if (oCompany_S.CompanyDB == oCompany_D.CompanyDB)
                        {
                            Singleton.traceService("Same Company...So Transfer");
                            oStockTransfer.DocDate       = Convert.ToDateTime(oHeader.Rows[0]["TrnDate"].ToString());
                            oStockTransfer.TaxDate       = Convert.ToDateTime(oHeader.Rows[0]["TrnDate"].ToString());
                            oStockTransfer.FromWarehouse = strFromWare;
                            oStockTransfer.Comments      = oHeader.Rows[0]["Remarks"].ToString();
                            oStockTransfer.UserFields.Fields.Item("U_Z_TrnNum").Value = oHeader.Rows[0]["TrnNum"].ToString();

                            Singleton.traceService("Set Header");
                            Singleton.traceService(strFromWare);
                            Singleton.traceService(strToWare);
                            if (oDetails.Rows.Count > 0)
                            {
                                foreach (DataRow dr in oDetails.Rows)
                                {
                                    oStockTransfer.Lines.ItemCode = dr["ItemCode"].ToString().Trim();
                                    oStockTransfer.Lines.Quantity = Convert.ToDouble(dr["Qty"].ToString());
                                    //oStockTransfer.Lines.FromWarehouseCode = strFromWare;
                                    oStockTransfer.Lines.WarehouseCode = strToWare;
                                    oStockTransfer.Lines.Add();
                                }
                                Singleton.traceService("Set Details");
                            }
                            Singleton.traceService("Adding");
                            intTStatus = oStockTransfer.Add();
                            Singleton.traceService(intTStatus.ToString());
                            if (intTStatus != 0)
                            {
                                Singleton.objSqlDataAccess.UpdateLog(strKey, TransScenerio.InventoryTransfer.ToString(), "0", "0", 0, oCompany_S.GetLastErrorCode().ToString(), oCompany_S.GetLastErrorDescription().Replace("'", ""), strLogger);
                            }
                            else
                            {
                                string strDkey;
                                int    intDocNum = 0;
                                oCompany_S.GetNewObjectCode(out strDkey);
                                if (oStockTransfer.GetByKey(Convert.ToInt32(strDkey)))
                                {
                                    intDocNum = oStockTransfer.DocNum;
                                }
                                Singleton.objSqlDataAccess.UpdateLog(strKey, TransScenerio.InventoryTransfer.ToString(), strDkey, intDocNum.ToString(), 1, "", "Armada_Sync Completed Sucessfully", strLogger);
                            }
                        }
                        else
                        {
                            //Singleton.traceService("Inventory Exit Started" + oCompany_S.CompanyDB.ToString());
                            //Singleton.traceService(strFromWare);
                            //Singleton.traceService(strToWare);

                            oInventoryExit.DocDate    = Convert.ToDateTime(oHeader.Rows[0]["TrnDate"].ToString());
                            oInventoryExit.DocDueDate = Convert.ToDateTime(oHeader.Rows[0]["TrnDate"].ToString());
                            oInventoryExit.Comments   = oHeader.Rows[0]["Remarks"].ToString();
                            oInventoryExit.UserFields.Fields.Item("U_Z_TrnNum").Value = oHeader.Rows[0]["TrnNum"].ToString();
                            //oInventoryExit.Reference2 = oHeader.Rows[0]["Ref2"].ToString();
                            //Singleton.traceService("Set Header");
                            if (oDetails.Rows.Count > 0)
                            {
                                foreach (DataRow dr in oDetails.Rows)
                                {
                                    oInventoryExit.Lines.ItemCode        = dr["ItemCode"].ToString();
                                    oInventoryExit.Lines.ItemDescription = dr["ItemDsc"].ToString();
                                    oInventoryExit.Lines.Quantity        = Convert.ToDouble(dr["Qty"].ToString());
                                    //oInventoryExit.Lines.ShipDate = Convert.ToDateTime(dr["ShipDate"].ToString());
                                    //oInventoryExit.Lines.UnitPrice = 0;
                                    oInventoryExit.Lines.WarehouseCode = strFromWare;
                                    oInventoryExit.Lines.AccountCode   = strValues[1];
                                    oInventoryExit.Lines.Add();
                                }
                            }
                            //Singleton.traceService("Set Details");

                            oCompany_S.StartTransaction();
                            //Singleton.traceService("Adding");
                            intExitStatus = oInventoryExit.Add();
                            //Singleton.traceService("Added");
                            if (intExitStatus != 0)
                            {
                                //Singleton.traceService(intExitStatus.ToString());
                                Singleton.objSqlDataAccess.UpdateLog(strKey, TransScenerio.InventoryTransfer.ToString(), "0", "0", 0, intExitStatus.ToString(), oCompany_S.GetLastErrorDescription().Replace("'", ""), strLogger);
                                if (oCompany_S.InTransaction)
                                {
                                    oCompany_S.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                }
                            }
                            else
                            {
                                string strDkey;
                                int    intDocNum = 0;
                                oCompany_S.GetNewObjectCode(out strDkey);
                                if (oInventoryExit.GetByKey(Convert.ToInt32(strDkey)))
                                {
                                    intDocNum = oInventoryExit.DocNum;
                                }


                                //Singleton.traceService("Exit Success");
                                //Singleton.traceService(intDocNum.ToString());
                                //Singleton.traceService("Setting Entry Header");
                                oInventoryEntry.DocDate    = Convert.ToDateTime(oHeader.Rows[0]["TrnDate"].ToString());
                                oInventoryEntry.DocDueDate = Convert.ToDateTime(oHeader.Rows[0]["TrnDate"].ToString());
                                oInventoryEntry.Comments   = oHeader.Rows[0]["Remarks"].ToString();
                                //oInventoryEntry.PaymentGroupCode = Convert.ToInt16(strValues[0]);
                                // oInventoryEntry.Reference2 = oHeader.Rows[0]["Ref2"].ToString();
                                oInventoryEntry.UserFields.Fields.Item("U_Z_TrnNum").Value = oHeader.Rows[0]["TrnNum"].ToString();

                                if (oDetails.Rows.Count > 0)
                                {
                                    //Singleton.traceService("Setting Entry Detials");
                                    foreach (DataRow dr in oDetails.Rows)
                                    {
                                        oInventoryEntry.Lines.ItemCode        = dr["ItemCode"].ToString();
                                        oInventoryEntry.Lines.ItemDescription = dr["ItemDsc"].ToString();
                                        oInventoryEntry.Lines.Quantity        = Convert.ToDouble(dr["Qty"].ToString());
                                        // oInventoryEntry.Lines.ShipDate = Convert.ToDateTime(dr["ShipDate"].ToString());
                                        oInventoryEntry.Lines.UnitPrice     = Convert.ToDouble(dr["LCPrice"].ToString());;
                                        oInventoryEntry.Lines.WarehouseCode = strToWare;
                                        oInventoryEntry.Lines.AccountCode   = strValues[2];
                                        oInventoryEntry.Lines.Add();
                                    }
                                }

                                oCompany_D.StartTransaction();
                                //Singleton.traceService("Adding Entry");
                                intEntryStatus = oInventoryEntry.Add();

                                if (intEntryStatus != 0)
                                {
                                    //Singleton.traceService(intEntryStatus.ToString());
                                    Singleton.objSqlDataAccess.UpdateLog(strKey, TransScenerio.InventoryTransfer.ToString(), "0", "0", 0, intEntryStatus.ToString(), oCompany_D.GetLastErrorDescription().Replace("'", ""), strLogger);
                                    if (oCompany_S.InTransaction)
                                    {
                                        oCompany_S.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                    if (oCompany_D.InTransaction)
                                    {
                                        oCompany_D.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                }
                                else
                                {
                                    if (oCompany_S.InTransaction)
                                    {
                                        oCompany_S.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                                    }
                                    if (oCompany_D.InTransaction)
                                    {
                                        oCompany_D.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                                    }

                                    Singleton.objSqlDataAccess.UpdateLog(strKey, TransScenerio.InventoryTransfer.ToString(), strDkey, intDocNum.ToString(), 1, "", "Armada_Sync Completed Sucessfully", strLogger);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (oCompany_S.InTransaction)
                {
                    oCompany_S.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                }
                if (oCompany_D.InTransaction)
                {
                    oCompany_D.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                }
                //Singleton.objSqlDataAccess.UpdateLog(strKey, TransScenerio.InventoryTransfer.ToString(), "0", "0", 0, "0", ex.Message.ToString(), strLogger);
                throw ex;
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oStockTransfer);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oInventoryExit);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oInventoryEntry);
            }
        }
Пример #9
0
        // Written by Jeeva
        public string SPA_ProcessCase_CreateBilling(DataTable dt)
        {
            DataSet oDataset = new DataSet();
            string sFuncName = string.Empty;
            string sProcName = string.Empty;
            DataView oDTView = new DataView();
            string sResult = string.Empty;
            string sCardCode = string.Empty;
            string sQuoteEntry = string.Empty;
            string sSalesEntry = string.Empty;
            string sPurchaseEntry = string.Empty;
            string sApInvEntry = string.Empty;
            string sDocType = string.Empty;
            string sItemLine = string.Empty;
            string sCaseNo = string.Empty;

            try
            {
                sFuncName = "SPA_ProcessCase_CreateBilling()";
                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName);

                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Connecting to target company ", sFuncName);
                oDICompany = oLogin.ConnectToTargetCompany(ConnectionString);

                foreach (DataRow iRow in dt.Rows)
                {
                    sDocType = Convert.ToString(iRow["TrnspName"]);
                    sQuoteEntry = Convert.ToString(iRow["DocEntry"]);
                    sItemLine = Convert.ToString(iRow["LineNum"]);
                    sCaseNo = Convert.ToString(iRow["CaseNo"]);

                    if (sDocType == "ADD-PO-D")
                    {
                        oDICompany.StartTransaction();
                        sSalesEntry = AddDocuments(dt, oDICompany, sDocType);
                        if (sSalesEntry == string.Empty)
                        {
                            if (oDICompany.InTransaction == true)
                            {
                                oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }
                            else
                            {
                                oDICompany.StartTransaction();
                                oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }
                            throw new ArgumentException(sErrDesc);
                        }
                        else if (sSalesEntry != string.Empty)
                        {
                            sPurchaseEntry = CreatePO(sSalesEntry, oDICompany, dt);
                            if (sPurchaseEntry == string.Empty)
                            {
                                if (oDICompany.InTransaction == true)
                                {
                                    oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                }
                                else
                                {
                                    oDICompany.StartTransaction();
                                    oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                }
                                throw new ArgumentException(sErrDesc);
                            }
                            else if (sPurchaseEntry != string.Empty)
                            {
                                sApInvEntry = CreateAPInv(sPurchaseEntry, oDICompany, sCaseNo);
                                if (sApInvEntry == string.Empty)
                                {
                                    if (oDICompany.InTransaction == true)
                                    {
                                        oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                    else
                                    {
                                        oDICompany.StartTransaction();
                                        oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                    throw new ArgumentException(sErrDesc);
                                }
                            }
                        }
                        if (sQuoteEntry != string.Empty)
                        {
                            SAPbobsCOM.Documents oSalesQuote;
                            oSalesQuote = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oQuotations);

                            if (oSalesQuote.GetByKey(Convert.ToInt16(sQuoteEntry)))
                            {
                                oSalesQuote.Lines.SetCurrentLine(Convert.ToInt16(sItemLine));
                                oSalesQuote.Lines.UserFields.Fields.Item("U_NEXT_ACTION_BY").Value = "FN";
                                oSalesQuote.Lines.UserFields.Fields.Item("U_PROCESS_LAST_UPDAT").Value = DateTime.Now.Date;

                                if (oSalesQuote.Update() != 0)
                                {
                                    sErrDesc = oDICompany.GetLastErrorDescription(); throw new ArgumentException(sErrDesc);
                                }
                            }
                        }

                        oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                    }
                    else if (sDocType == "ADD-PO")
                    {
                        oDICompany.StartTransaction();
                        sSalesEntry = AddDocuments(dt, oDICompany, sDocType);
                        if (sSalesEntry == string.Empty)
                        {
                            if (oDICompany.InTransaction == true)
                            {
                                oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }
                            else
                            {
                                oDICompany.StartTransaction();
                                oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }
                            throw new ArgumentException(sErrDesc);
                        }
                        else if (sSalesEntry != string.Empty)
                        {
                            sPurchaseEntry = CreatePO(sSalesEntry, oDICompany, dt);
                            if (sPurchaseEntry == string.Empty)
                            {
                                if (oDICompany.InTransaction == true)
                                {
                                    oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                }
                                else
                                {
                                    oDICompany.StartTransaction();
                                    oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                }
                                throw new ArgumentException(sErrDesc);
                            }
                            else if (sPurchaseEntry != string.Empty)
                            {
                                sApInvEntry = CreateAPInv(sPurchaseEntry, oDICompany, sCaseNo);
                                if (sApInvEntry == string.Empty)
                                {
                                    if (oDICompany.InTransaction == true)
                                    {
                                        oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                    else
                                    {
                                        oDICompany.StartTransaction();
                                        oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                    throw new ArgumentException(sErrDesc);
                                }
                            }
                        }
                        if (sQuoteEntry != string.Empty)
                        {
                            SAPbobsCOM.Documents oSalesQuote;
                            oSalesQuote = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oQuotations);

                            if (oSalesQuote.GetByKey(Convert.ToInt16(sQuoteEntry)))
                            {
                                oSalesQuote.Lines.SetCurrentLine(Convert.ToInt16(sItemLine));
                                oSalesQuote.Lines.UserFields.Fields.Item("U_NEXT_ACTION_BY").Value = "FN";
                                oSalesQuote.Lines.UserFields.Fields.Item("U_PROCESS_LAST_UPDAT").Value = DateTime.Now.Date;

                                if (oSalesQuote.Update() != 0)
                                {
                                    sErrDesc = oDICompany.GetLastErrorDescription(); throw new ArgumentException(sErrDesc);
                                }
                            }
                        }
                        oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                    }
                    else if (sDocType == "FEES")
                    {
                        oDICompany.StartTransaction();
                        sSalesEntry = AddDocuments(dt, oDICompany, sDocType);
                        if (sSalesEntry == string.Empty)
                        {
                            if (oDICompany.InTransaction == true)
                            {
                                oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }
                            else
                            {
                                oDICompany.StartTransaction();
                                oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }
                            throw new ArgumentException(sErrDesc);
                        }
                        if (sQuoteEntry != string.Empty)
                        {
                            SAPbobsCOM.Documents oSalesQuote;
                            oSalesQuote = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oQuotations);

                            if (oSalesQuote.GetByKey(Convert.ToInt16(sQuoteEntry)))
                            {
                                oSalesQuote.Lines.SetCurrentLine(Convert.ToInt16(sItemLine));
                                oSalesQuote.Lines.UserFields.Fields.Item("U_STATUS").Value = "ACCEPT";
                                oSalesQuote.Lines.UserFields.Fields.Item("U_PROCESS_LAST_UPDAT").Value = DateTime.Now.Date;
                                oSalesQuote.Lines.UserFields.Fields.Item("U_PROCESS_ACCEPT_DAT").Value = DateTime.Now.Date;
                                oSalesQuote.Lines.UserFields.Fields.Item("U_PROCESS_ACCEPTBY").Value = Convert.ToString(iRow["UserName"]);

                                if (oSalesQuote.Update() != 0)
                                {
                                    sErrDesc = oDICompany.GetLastErrorDescription(); throw new ArgumentException(sErrDesc);
                                }
                            }
                        }
                        oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                    }
                }

                // Note : Write the comments while doing the
                sResult = "SUCCESS";
                return sResult;
            }
            catch (Exception Ex)
            {
                sErrDesc = Ex.Message.ToString();
                oLog.WriteToErrorLogFile(sErrDesc, sFuncName);
                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR  ", sFuncName);
                sResult = Ex.Message.ToString();
                if (oDICompany.InTransaction) oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                throw Ex;
            }
        }
Пример #10
0
        //public DataSet SPA_ProcessCase_GetNextSection(string sCaseNo)
        //{
        //    DataSet oDataset = new DataSet();
        //    DataSet oDataset1 = new DataSet();
        //    string sFuncName = string.Empty;
        //    string sProcName = string.Empty;
        //    string sProcName1 = string.Empty;
        //    DataView oDTView = new DataView();
        //    string sCanClose = string.Empty;
        //    try
        //    {
        //        sFuncName = "SPA_ProcessCase_GetNextSection()";
        //        sProcName = "getNextSection";
        //        sProcName1 = "canCloseCurrentSection";
        //        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName);
        //        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Calling Run_StoredProcedure() " + sProcName1, sFuncName);
        //        oDataset1 = SqlHelper.ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, sProcName1,
        //            Data.CreateParameter("@caseNo", sCaseNo));
        //        if (oDataset1 != null && oDataset1.Tables.Count > 0)
        //        {
        //            if (oDataset1.Tables[0].Rows.Count > 0)
        //            {
        //                sCanClose = oDataset1.Tables[0].Rows[0][0].ToString();
        //            }
        //        }
        //        if (sCanClose == "Y")
        //        {
        //        }
        //        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Calling Run_StoredProcedure() " + sProcName, sFuncName);
        //        oDataset = SqlHelper.ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, sProcName,
        //            Data.CreateParameter("@caseNo", sCaseNo));
        //        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS  ", sFuncName);
        //        if (oDataset.Tables.Count > 0 && oDataset != null)
        //        {
        //            if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("There is a set of data from the SP :" + sProcName, sFuncName);
        //            return oDataset;
        //        }
        //        else
        //        {
        //            if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("There is no data from the SP :" + sProcName, sFuncName);
        //            return oDataset;
        //        }
        //    }
        //    catch (Exception Ex)
        //    {
        //        sErrDesc = Ex.Message.ToString();
        //        oLog.WriteToErrorLogFile(sErrDesc, sFuncName);
        //        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR  ", sFuncName);
        //        throw Ex;
        //    }
        //}
        public DataSet SPA_ProcessCase_GetNextSection(string sCaseNo)
        {
            DataSet oDataset = new DataSet();
            DataSet oDataset1 = new DataSet();
            DataSet oDataset2 = new DataSet();
            string sFuncName = string.Empty;
            string sProcName = string.Empty;
            string sProcName1 = string.Empty;
            DataView oDTView = new DataView();
            string sCanClose = string.Empty;
            string sProcName2 = string.Empty;

            try
            {
                sFuncName = "SPA_ProcessCase_GetNextSection()";
                sProcName = "getNextSection";
                sProcName1 = "canCloseCurrentSection";
                sProcName2 = "getOpenSection";

                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName);

                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Calling Run_StoredProcedure() " + sProcName1, sFuncName);
                oDataset1 = SqlHelper.ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, sProcName1,
                    Data.CreateParameter("@caseNo", sCaseNo));
                if (oDataset1 != null && oDataset1.Tables.Count > 0)
                {
                    if (oDataset1.Tables[0].Rows.Count > 0)
                    {
                        sCanClose = oDataset1.Tables[0].Rows[0][0].ToString();
                    }
                }
                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Connecting to target company ", sFuncName);
                oDICompany = oLogin.ConnectToTargetCompany(ConnectionString);

                if (sCanClose == "Y")
                {
                    SAPbobsCOM.Documents oSalesQuote;
                    SAPbobsCOM.Recordset oRecSet;
                    string sSql;
                    int iSalQuoteEntry;
                    int iItemLine;

                    oSalesQuote = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oQuotations);
                    oRecSet = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

                    oDICompany.StartTransaction();

                    sSql = "SELECT A.DocEntry,B.VisOrder FROM OQUT A WITH (NOLOCK) INNER JOIN QUT1 B WITH (NOLOCK) ON B.DocEntry = A.DocEntry WHERE CardCode = '" + sCaseNo + "' AND B.ItemCode <> '" + strItemCode + "' AND DocStatus = 'O'";
                    oRecSet.DoQuery(sSql);
                    if (oRecSet.RecordCount > 0)
                    {
                        while (!oRecSet.EoF)
                        {
                            iSalQuoteEntry = Convert.ToInt16(oRecSet.Fields.Item("DocEntry").Value);
                            iItemLine = Convert.ToInt16(oRecSet.Fields.Item("VisOrder").Value);

                            if (oSalesQuote.GetByKey(Convert.ToInt16(iSalQuoteEntry)))
                            {
                                oSalesQuote.Lines.SetCurrentLine(Convert.ToInt16(iItemLine));
                                oSalesQuote.Lines.LineStatus = SAPbobsCOM.BoStatus.bost_Close;
                                if (oSalesQuote.Update() != 0)
                                {
                                    if (oDICompany.InTransaction == true)
                                    {
                                        oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                    else
                                    {
                                        oDICompany.StartTransaction();
                                        oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                                    }
                                    sErrDesc = oDICompany.GetLastErrorDescription(); throw new ArgumentException(sErrDesc);
                                }
                            }
                            oRecSet.MoveNext();
                        }
                    }
                    oDICompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);

                    if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Calling Run_StoredProcedure() " + sProcName, sFuncName);
                    oDataset = SqlHelper.ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, sProcName,
                        Data.CreateParameter("@caseNo", sCaseNo));

                    if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS  ", sFuncName);
                    if (oDataset.Tables.Count > 0 && oDataset != null)
                    {
                        if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("There is a set of data from the SP :" + sProcName, sFuncName);
                        if (CreateSalesQuote(oDataset.Tables[0], oDICompany) == "SUCCESS")
                        {
                            if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Calling Run_StoredProcedure() " + sProcName2, sFuncName);
                            oDataset2 = SqlHelper.ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, sProcName2,
                                Data.CreateParameter("@caseNo", sCaseNo));
                        }
                        oDataset = oDataset2;
                    }
                }
                else
                {
                    if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("There is no data from the SP :" + sProcName, sFuncName);
                }
                return oDataset;
            }
            catch (Exception Ex)
            {
                sErrDesc = Ex.Message.ToString();
                oLog.WriteToErrorLogFile(sErrDesc, sFuncName);
                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR  ", sFuncName);
                throw Ex;
            }
        }