Example #1
0
        private string Copy_Project(int pProjectNo)
        {
            string New_ProjectNo = "-1";
            //Get Project Info through DI API
            Recordset oR_Project_Info = (Recordset)oCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            string    str_sql         = string.Format("Select * from OPMG where AbsEntry={0}", pProjectNo.ToString());

            oR_Project_Info.DoQuery(str_sql);
            if (oR_Project_Info.RecordCount == 1)
            {
                //Use UI API to create Project
                oApp.ActivateMenuItem("48897");
                var oform1 = oApp.Forms.ActiveForm;
                //Project Type
                string ptype = oR_Project_Info.Fields.Item("TYP").Value.ToString();
                if (ptype == "E")
                {
                    var orad_extype = oform1.Items.Item("234000010").Specific;
                    ((SAPbouiCOM.OptionBtn)orad_extype).Selected = true;
                }
                else
                {
                    var orad_intype = oform1.Items.Item("234000011").Specific;
                    ((SAPbouiCOM.OptionBtn)orad_intype).Selected = true;
                }
                //BPCode
                string bpcode = oR_Project_Info.Fields.Item("CARDCODE").Value.ToString();
                if (!String.IsNullOrEmpty(bpcode))
                {
                    var txt_bpcode = oform1.Items.Item("234000013").Specific;
                    ((SAPbouiCOM.EditText)txt_bpcode).Value = bpcode;
                }
                //BPName
                string bpname = oR_Project_Info.Fields.Item("CARDNAME").Value.ToString();
                if (!String.IsNullOrEmpty(bpname))
                {
                    var txt_bpname = oform1.Items.Item("234000016").Specific;
                    ((SAPbouiCOM.EditText)txt_bpname).Value = bpname;
                }
                //Contact Person
                string contact = oR_Project_Info.Fields.Item("CONTACT").Value.ToString();
                if (!String.IsNullOrEmpty(contact))
                {
                    var cbo_contactperson = oform1.Items.Item("234000018").Specific;
                    ((SAPbouiCOM.ComboBox)cbo_contactperson).Select(contact);
                }
                //Territory
                string territory = oR_Project_Info.Fields.Item("TERRITORY").Value.ToString();
                if (!String.IsNullOrEmpty(territory) && territory != "0")
                {
                    var txt_territory = oform1.Items.Item("234000020").Specific;
                    ((SAPbouiCOM.EditText)txt_territory).Value = territory;
                }
                //Sale Employee
                string employee = oR_Project_Info.Fields.Item("EMPLOYEE").Value.ToString();
                if (!String.IsNullOrEmpty(employee) && employee != "-1")
                {
                    var cbo_employee = oform1.Items.Item("234000023").Specific;
                    ((SAPbouiCOM.ComboBox)cbo_employee).Select(employee);
                }
                //Owner
                string owner = oR_Project_Info.Fields.Item("OWNER").Value.ToString();
                if (!String.IsNullOrEmpty(owner) && owner != "0")
                {
                    var txt_owner = oform1.Items.Item("234000025").Specific;
                    ((SAPbouiCOM.EditText)txt_owner).Value = owner;
                }
                //Bo phan thuc hien
                string u_bpth = oR_Project_Info.Fields.Item("U_BPTH").Value.ToString();
                if (!String.IsNullOrEmpty(u_bpth))
                {
                    var cbo_u_bpth = oform1.Items.Item("U_BPTH").Specific;
                    ((SAPbouiCOM.ComboBox)cbo_u_bpth).Select(u_bpth);
                }
                //Project with Subproject
                string withpahse = oR_Project_Info.Fields.Item("WithPhases").Value.ToString();
                if (withpahse == "Y")
                {
                    var chb_withpahse = oform1.Items.Item("234000027").Specific;
                    ((SAPbouiCOM.CheckBox)chb_withpahse).Checked = true;
                }
                //Project Name
                string pname = oR_Project_Info.Fields.Item("NAME").Value.ToString();
                if (!String.IsNullOrEmpty(pname))
                {
                    var txt_pname = oform1.Items.Item("234000029").Specific;
                    ((SAPbouiCOM.EditText)txt_pname).Value = pname + "_Clone_" + DateTime.Now.ToString("ddMMyyyy HHmmss");
                }
                //Series
                string series = oR_Project_Info.Fields.Item("Series").Value.ToString();
                if (!String.IsNullOrEmpty(series))
                {
                    var cbo_series = oform1.Items.Item("234000031").Specific;
                    ((SAPbouiCOM.ComboBox)cbo_series).Select(series);
                }
                //Status
                string status = oR_Project_Info.Fields.Item("STATUS").Value.ToString();
                if (!String.IsNullOrEmpty(status))
                {
                    var cbo_status = oform1.Items.Item("234000034").Specific;
                    ((SAPbouiCOM.ComboBox)cbo_status).Select(status);
                }
                //Start Date
                string strdate = oR_Project_Info.Fields.Item("START").Value.ToString();
                if (!String.IsNullOrEmpty(strdate))
                {
                    if (DateTime.Parse(strdate).Year > 1900)
                    {
                        var txt_strdate = oform1.Items.Item("234000036").Specific;
                        ((SAPbouiCOM.EditText)txt_strdate).Value = DateTime.Parse(strdate).ToString("yyyyMMdd");
                    }
                }
                //Due Date
                string duedate = oR_Project_Info.Fields.Item("DUEDATE").Value.ToString();
                if (!String.IsNullOrEmpty(duedate))
                {
                    if (DateTime.Parse(duedate).Year > 1900)
                    {
                        var txt_duedate = oform1.Items.Item("234000038").Specific;
                        ((SAPbouiCOM.EditText)txt_duedate).Value = DateTime.Parse(duedate).ToString("yyyyMMdd");
                    }
                }
                //Closing Date
                string closedate = oR_Project_Info.Fields.Item("CLOSING").Value.ToString();
                if (!String.IsNullOrEmpty(closedate))
                {
                    if (DateTime.Parse(closedate).Year > 1900)
                    {
                        var txt_closedate = oform1.Items.Item("234000040").Specific;
                        ((SAPbouiCOM.EditText)txt_closedate).Value = DateTime.Parse(closedate).ToString("yyyyMMdd");
                    }
                }
                //Financial Project
                string finan_project = oR_Project_Info.Fields.Item("FIPROJECT").Value.ToString();
                if (!String.IsNullOrEmpty(finan_project))
                {
                    //var txt_finan_project = oform1.Items.Item("234000049").Specific;
                    //((SAPbouiCOM.EditText)txt_finan_project).Value = finan_project;
                }
                //Overview Panel - Risk Level
                //string risk = oR_Project_Info.Fields.Item("RISK").Value.ToString();
                //if (!String.IsNullOrEmpty(risk))
                //{
                //    oform1.Freeze(true);
                //    oform1.PaneLevel = oform1.Items.Item("234000056").FromPane;//oForm.Items.Item("148").FromPane
                //    var cbo_risk = oform1.Items.Item("234000056").Specific;
                //    ((SAPbouiCOM.ComboBox)cbo_risk).Select(risk);
                //    oform1.Freeze(false);
                //}
                //Overview Panel - Industry
                //string industry = oR_Project_Info.Fields.Item("INDUSTRY").Value.ToString();
                //if (!String.IsNullOrEmpty(industry))
                //{
                //    oform1.Freeze(true);
                //    oform1.PaneLevel = oform1.Items.Item("234000058").FromPane;//oForm.Items.Item("148").FromPane
                //    var cbo_industry = oform1.Items.Item("234000058").Specific;
                //    ((SAPbouiCOM.ComboBox)cbo_industry).Select(industry);
                //    oform1.Freeze(false);
                //}
                //Overview Panel - Comments
                //string comments = oR_Project_Info.Fields.Item("REASON").Value.ToString();
                //if (!String.IsNullOrEmpty(comments))
                //{
                //    var txt_comments = oform1.Items.Item("234000060").Specific;
                //    ((SAPbouiCOM.EditText)txt_comments).Value = comments;
                //}

                //Remark Panel - Free Text
                string freetext = oR_Project_Info.Fields.Item("Free_Text").Value.ToString();
                if (!String.IsNullOrEmpty(freetext))
                {
                    oform1.Freeze(true);
                    oform1.PaneLevel = oform1.Items.Item("234000167").FromPane;//oForm.Items.Item("148").FromPane
                    var txt_freetext = oform1.Items.Item("234000167").Specific;
                    ((SAPbouiCOM.EditText)txt_freetext).Value = freetext;
                    oform1.Freeze(false);
                }
                //U Project Type
                string u_ptype = oR_Project_Info.Fields.Item("U_PRJTYPE").Value.ToString();
                if (!String.IsNullOrEmpty(u_ptype))
                {
                    var cbo_u_ptype = oform1.Items.Item("U_PRJTYPE").Specific;
                    ((SAPbouiCOM.ComboBox)cbo_u_ptype).Select(u_ptype);
                }
                //U Project Group
                string u_pgrp = oR_Project_Info.Fields.Item("U_PRJGROUP").Value.ToString();
                if (!String.IsNullOrEmpty(u_pgrp))
                {
                    var cbo_u_ptype = oform1.Items.Item("U_PRJGROUP").Specific;
                    ((SAPbouiCOM.ComboBox)cbo_u_ptype).Select(u_pgrp);
                }
                //Overview Panel - U_CPHT1
                string u_cpht1 = oR_Project_Info.Fields.Item("U_CPHT1").Value.ToString();
                if (!String.IsNullOrEmpty(u_cpht1))
                {
                    oform1.Freeze(true);
                    oform1.PaneLevel = oform1.Items.Item("U_CPHT1").FromPane;
                    var txt_u_cpht1 = oform1.Items.Item("U_CPHT1").Specific;
                    ((SAPbouiCOM.EditText)txt_u_cpht1).Value = u_cpht1;
                    oform1.Freeze(false);
                }
                //Overview Panel - U_CPHT2
                string u_cpht2 = oR_Project_Info.Fields.Item("U_CPHT2").Value.ToString();
                if (!String.IsNullOrEmpty(u_cpht2))
                {
                    oform1.Freeze(true);
                    oform1.PaneLevel = oform1.Items.Item("U_CPHT2").FromPane;
                    var txt_u_cpht2 = oform1.Items.Item("U_CPHT2").Specific;
                    ((SAPbouiCOM.EditText)txt_u_cpht2).Value = u_cpht2;
                    oform1.Freeze(false);
                }
                //Overview Panel - U_DPBH
                string u_dpbh = oR_Project_Info.Fields.Item("U_DPBH").Value.ToString();
                if (!String.IsNullOrEmpty(u_dpbh))
                {
                    oform1.Freeze(true);
                    oform1.PaneLevel = oform1.Items.Item("U_DPBH").FromPane;
                    var txt_u_dpbh = oform1.Items.Item("U_DPBH").Specific;
                    ((SAPbouiCOM.EditText)txt_u_dpbh).Value = u_dpbh;
                    oform1.Freeze(false);
                }
                //Overview Panel - U_DPCP
                string u_dpcp = oR_Project_Info.Fields.Item("U_DPCP").Value.ToString();
                if (!String.IsNullOrEmpty(u_dpcp))
                {
                    oform1.Freeze(true);
                    oform1.PaneLevel = oform1.Items.Item("U_DPCP").FromPane;
                    var txt_u_dpcp = oform1.Items.Item("U_DPCP").Specific;
                    ((SAPbouiCOM.EditText)txt_u_dpcp).Value = u_dpcp;
                    oform1.Freeze(false);
                }
                //Get New Project No
                var txt_projectno_new = oform1.Items.Item("234000032").Specific;
                New_ProjectNo = ((SAPbouiCOM.EditText)txt_projectno_new).Value;
                //Click Add Button
                oform1.Items.Item("1").Click();
                //Check Add Project Complete ?
                if (((SAPbouiCOM.EditText)oform1.Items.Item("234000032").Specific).Value != New_ProjectNo)
                {
                    oform1.Close();
                }
                else
                {
                    New_ProjectNo = "-1";
                    oApp.MessageBox("Can't copy project !");
                }
            }
            else
            {
                oApp.MessageBox("Không tìm thấy ProjectNo hoặc Trùng ProjectNo");
            }
            return(New_ProjectNo);
        }