public static int SaveUserImage(Ctx ctx, byte[] buffer, string imageName, bool isSaveInDB, int userID) { MUser user = new MUser(ctx, userID, null); int imageID = Util.GetValueOfInt(user.GetAD_Image_ID()); MImage mimg = new MImage(ctx, imageID, null); mimg.ByteArray = buffer; mimg.ImageFormat = imageName.Substring(imageName.LastIndexOf('.')); mimg.SetName(imageName); if (isSaveInDB) { mimg.SetBinaryData(buffer); mimg.SetImageURL(string.Empty); } else { //mimg.SetImageURL(HostingEnvironment.MapPath(@"~/Images/100by100"));//Image Saved in File System so instead of byteArray image Url will be set mimg.SetImageURL("Images/Thumb100x100");//Image Saved in File System so instead of byteArray image Url will be set mimg.SetBinaryData(new byte[0]); } if (!mimg.Save()) { return(0); } user.SetAD_Image_ID(mimg.GetAD_Image_ID()); if (!user.Save()) { return(0); } return(mimg.GetAD_Image_ID()); }
/// <summary> /// Add Or Update Business Partner /// </summary> /// <param name="searchKey"></param> /// <param name="name"></param> /// <param name="name2"></param> /// <param name="greeting"></param> /// <param name="bpGroup"></param> /// <param name="bpRelation"></param> /// <param name="bpLocation"></param> /// <param name="contact"></param> /// <param name="greeting1"></param> /// <param name="title"></param> /// <param name="email"></param> /// <param name="address"></param> /// <param name="phoneNo"></param> /// <param name="phoneNo2"></param> /// <param name="fax"></param> /// <param name="ctx"></param> /// <param name="_windowNo"></param> /// <param name="BPtype"></param> /// <param name="C_BPartner_ID"></param> /// <returns></returns> public string AddBPartner(string searchKey, string name, string name2, string greeting, string bpGroup, string bpRelation, string bpLocation, string contact, string greeting1, string title, string email, string address, string phoneNo, string phoneNo2, string fax, Ctx ctx, int _windowNo, string BPtype, int C_BPartner_ID, bool isCustomer, bool isVendor, bool isProspect, string fileUrl, string umobile, string webUrl, bool isEmployee) { StringBuilder strError = new StringBuilder(); int AD_Client_ID = ctx.GetAD_Client_ID(); if (C_BPartner_ID > 0) { _partner = new MBPartner(ctx, C_BPartner_ID, null); } else { _partner = MBPartner.GetTemplate(ctx, AD_Client_ID); } bool isSOTrx = ctx.IsSOTrx(_windowNo); _partner.SetIsCustomer(isSOTrx); _partner.SetIsVendor(!isSOTrx); // JID_1197 IN Business partner updating Createdby,Updatedby,Created,Updated fields as per changed date _partner.Set_ValueNoCheck("CreatedBy", ctx.GetAD_User_ID()); _partner.Set_ValueNoCheck("Created", DateTime.Now); _partner.Set_ValueNoCheck("Updated", DateTime.Now); _partner.Set_ValueNoCheck("UpdatedBy", ctx.GetAD_User_ID()); if (BPtype != null && (!isCustomer && !isVendor)) { if (BPtype.Contains("Customer")) { _partner.SetIsCustomer(true); } if (BPtype.Contains("Employee")) { _partner.SetIsEmployee(true); } if (BPtype.Contains("Vendor")) { _partner.SetIsVendor(true); } if (BPtype.Contains("Prospect")) { _partner.SetIsProspect(true); } /* * if (BPtype == "Customer") * { * _partner.SetIsCustomer(true); * } * else if (BPtype == "Employee") * { * _partner.SetIsEmployee(true); * } * else if (BPtype == "Vendor") * { * _partner.SetIsVendor(true); * } * else if (BPtype == "Prospect") * { * _partner.SetIsProspect(true); * }*/ } if (isCustomer) { _partner.SetIsCustomer(true); } else { _partner.SetIsCustomer(false); } if (isVendor) { _partner.SetIsVendor(true); } else { _partner.SetIsVendor(false); } if (isProspect) { _partner.SetIsProspect(true); } else { _partner.SetIsProspect(false); } if (isEmployee) { _partner.SetIsEmployee(true); } else { _partner.SetIsEmployee(false); } if (searchKey == null || searchKey.Length == 0) { // get Table Documet No searchKey = MSequence.GetDocumentNo(ctx.GetAD_Client_ID(), "C_BPartner", null, ctx); //Dispatcher.BeginInvoke(() => { txtValue.Text = value; }); } _partner.SetValue(searchKey); // _partner.SetName(name); _partner.SetURL(webUrl); // _partner.SetName2(name2); //KeyNamePair p = (KeyNamePair)cmbGreetingBP.SelectedItem; //if (greeting >0) //{ // _partner.SetC_Greeting_ID(greeting); //} //else //{ // _partner.SetC_Greeting_ID(0); //} if (greeting != string.Empty) { _partner.SetC_Greeting_ID(Convert.ToInt32(greeting)); } else { _partner.SetC_Greeting_ID(0); } /***************************************************/ _partner.SetC_BP_Group_ID(Util.GetValueOfInt(bpGroup)); /***************************************************/ if (_partner.Save()) { log.Fine("C_BPartner_ID=" + _partner.GetC_BPartner_ID()); } else { // Classes.ShowMessage.Error("SearchKeyExist", null); strError.Append("SearchKeyExist"); //this.Cursor = Cursors.Arrow; return(strError.ToString()); } // ***** Business Partner - Location ***** if (_pLocation == null) { if (C_BPartner_ID > 0) { _pLocation = new MBPartnerLocation(ctx, GetBPartnerLocationID(_partner.Get_ID()), null); if (_pLocation.Get_ID() <= 0) { _pLocation = new MBPartnerLocation(_partner); } } else { _pLocation = new MBPartnerLocation(_partner); } } if (address != string.Empty) { _pLocation.SetC_Location_ID(Convert.ToInt32(address)); } // _pLocation.SetPhone(phoneNo); // _pLocation.SetPhone2(phoneNo2); _pLocation.SetFax(fax); if (_pLocation.Save()) { log.Fine("C_BPartner_Location_ID=" + _pLocation.GetC_BPartner_Location_ID()); } else { // ADialog.error(m_WindowNo, this, "BPartnerNotSaved", Msg.translate(Env.getCtx(), "C_BPartner_Location_ID")); // Classes.ShowMessage.Error("BPartnerNotSaved", null); //this.Cursor = Cursors.Arrow; strError.Append("BPartnerNotSaved"); return(strError.ToString()); } // ***** Business Partner - User ***** //String contact = txtContact.Text; //String email = txtEMail.Text; if (_user == null && (contact.Length > 0 || email.Length > 0)) { if (C_BPartner_ID > 0) { _user = new MUser(ctx, GetUserID(_partner.Get_ID()), null); } else { _user = new MUser(_partner); } } if (_user != null) { if (contact.Length == 0) { contact = name; } _user.SetName(contact); _user.SetEMail(email); _user.SetTitle(title); _user.SetC_Location_ID(Convert.ToInt32(address)); // = (KeyNamePair)cmbGreetingC.SelectedItem; //if (greeting1 >0) // _user.SetC_Greeting_ID(greeting1); if (greeting1 != string.Empty) { _user.SetC_Greeting_ID(Convert.ToInt32(greeting1)); } else { _user.SetC_Greeting_ID(0); } // _user.SetPhone(phoneNo); // _user.SetPhone2(phoneNo2); _user.SetMobile(umobile); _user.SetFax(fax); _user.SetC_BPartner_Location_ID(_pLocation.GetC_BPartner_Location_ID()); if (_user.Save()) { if (fileUrl != null && fileUrl != string.Empty) { _user.SetAD_Image_ID(SaveUserImage(ctx, fileUrl, _user.GetAD_User_ID())); } if (_user.Save()) { log.Fine("AD_User_ID(AD_Image_ID)=" + _user.GetAD_User_ID() + "(" + _user.GetAD_Image_ID() + ")"); } log.Fine("AD_User_ID=" + _user.GetAD_User_ID()); } else { //Classes.ShowMessage.Error("BPartnerNotSaved", null); //this.Cursor = Cursors.Arrow; strError.Append("BPartnerNotSaved"); return(strError.ToString()); } /*************************************************/ if ((bpRelation != null && bpLocation != null) && (bpRelation != string.Empty && bpLocation != string.Empty)) { if (bpRelation.ToString().Trim() == "" || bpLocation.ToString().Trim() == "") { int dele = DB.ExecuteQuery("DELETE from C_BP_Relation where c_bpartner_id=" + _partner.GetC_BPartner_ID(), null, null); if (dele == -1) { log.SaveError("C_BP_RelationNotDeleted", "c_bpartner_id=" + _partner.GetC_BPartner_ID()); } } else { //Business Partner Relation if (C_BPartner_ID > 0) { _bprelation = new X_C_BP_Relation(ctx, GetBPRelationID(_partner.Get_ID()), null); } else { _bprelation = new X_C_BP_Relation(ctx, 0, null); } _bprelation.SetAD_Client_ID(_partner.GetAD_Client_ID()); _bprelation.SetAD_Org_ID(_partner.GetAD_Org_ID()); _bprelation.SetName(_partner.GetName()); _bprelation.SetDescription(_partner.GetDescription()); _bprelation.SetC_BPartner_ID(_partner.GetC_BPartner_ID()); _bprelation.SetC_BPartner_Location_ID(_pLocation.GetC_BPartner_Location_ID()); _bprelation.SetC_BP_Relation_ID(Util.GetValueOfInt(bpRelation)); _bprelation.SetC_BPartnerRelation_ID(Util.GetValueOfInt(bpRelation)); _bprelation.SetC_BPartnerRelation_Location_ID(Util.GetValueOfInt(bpLocation)); _bprelation.SetIsBillTo(true); if (_bprelation.Save()) { log.Fine("C_BP_Relation_ID=" + _bprelation.GetC_BP_Relation_ID()); } else { //Classes.ShowMessage.Error("BPRelationNotSaved", null); //this.Cursor = Cursors.Arrow; strError.Append("BPRelationNotSaved"); return(strError.ToString()); } } } /*************************************************/ } return(strError.ToString()); }