protected void popManufacturerEdit_WindowCallback(object source, DevExpress.Web.ASPxPopupControl.PopupWindowCallbackArgs e) { string[] args = e.Parameter.Split('|'); switch (args[0]) { case "new": ManufacturerOrg tempManufacturerOrg = ManufacturerOrg.InitNewRow(session); PrivateSession.Instance.ManufacturerOrgId = tempManufacturerOrg.OrganizationId; frmManufacturerEdit.DataSourceID = "dsManufacturer"; dsManufacturer.CriteriaParameters["ManufacturerOrgId"].DefaultValue = PrivateSession.Instance.ManufacturerOrgId.ToString(); ClearForm(); //Get object id //Bind data to gridview #region add manufacturer session.BeginTransaction(); try { //ObjectType ObjectType objectType = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER); // object NAS.BO.CMS.ObjectDocument.ObjectBO objectBO = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsobject = objectBO.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER); // OrganizationObject OrganizationObject organizatoinObject = new OrganizationObject(session) { ObjectId = cmsobject, OrganizationId = tempManufacturerOrg }; organizatoinObject.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType = new OrganizationCustomType(session) { ObjectTypeId = objectType, OrganizationId = tempManufacturerOrg }; organizationCustomType.Save(); session.CommitTransaction(); } catch { session.RollbackTransaction(); } OrganizationObject organizationObject = tempManufacturerOrg.OrganizationObjects.FirstOrDefault(); grid_of_Manufacturer.CMSObjectId = organizationObject.ObjectId.ObjectId; grid_of_Manufacturer.DataBind(); #endregion //2013-11-22 Khoa.Truong DEL START //gridviewCustomFields.CMSObjectId = CurrentManufacturerOrg.ObjectId.ObjectId; //gridviewCustomFields.DataBind(); //2013-11-22 Khoa.Truong DEL END break; case "edit": ClearForm(); frmManufacturerEdit.DataSourceID = "dsManufacturer"; if (args.Length > 1) { PrivateSession.Instance.ManufacturerOrgId = Guid.Parse(args[1]); dsManufacturer.CriteriaParameters["ManufacturerOrgId"].DefaultValue = PrivateSession.Instance.ManufacturerOrgId.ToString(); txtCode.Text = CurrentManufacturerOrg.Code; //Get object id //Bind data to gridview #region edit manufacturer if (CurrentManufacturerOrg.OrganizationObjects.FirstOrDefault() == null) { session.BeginTransaction(); try { ObjectType objectType1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER); // object NAS.BO.CMS.ObjectDocument.ObjectBO objectBO1 = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsobject1 = objectBO1.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER); OrganizationObject organizatoinObject1 = new OrganizationObject(session) { ObjectId = cmsobject1, OrganizationId = CurrentManufacturerOrg }; organizatoinObject1.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType1 = new OrganizationCustomType(session) { ObjectTypeId = objectType1, OrganizationId = CurrentManufacturerOrg }; organizationCustomType1.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } OrganizationObject organizationObject1 = CurrentManufacturerOrg.OrganizationObjects.FirstOrDefault(); grid_of_Manufacturer.CMSObjectId = organizationObject1.ObjectId.ObjectId; grid_of_Manufacturer.DataBind(); } else { OrganizationObject organizationObject1 = CurrentManufacturerOrg.OrganizationObjects.FirstOrDefault(); grid_of_Manufacturer.CMSObjectId = organizationObject1.ObjectId.ObjectId; grid_of_Manufacturer.DataBind(); } #endregion //2013-11-22 Khoa.Truong DEL START //gridviewCustomFields.CMSObjectId = CurrentManufacturerOrg.ObjectId.ObjectId; //gridviewCustomFields.DataBind(); //2013-11-22 Khoa.Truong DEL END } break; case "save": bool isSuccess = true; string recordIdStr = null; try { //Check validation if (!ASPxEdit.AreEditorsValid(pagMunufacturer, true)) { popManufacturerEdit.JSProperties.Add("cpInvalid", true); pagMunufacturer.ActiveTabIndex = 0; return; } //Logic to save data if (args.Length > 1) { //Update mode //Update general information recordIdStr = args[1]; Guid recordId = Guid.Parse(recordIdStr); ManufacturerOrg editManufacturerOrg = session.GetObjectByKey <ManufacturerOrg>(PrivateSession.Instance.ManufacturerOrgId); editManufacturerOrg.Code = txtCode.Text; editManufacturerOrg.Name = txtName.Text; editManufacturerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString()); editManufacturerOrg.Save(); } else { //Insert mode ManufacturerOrg newManufacturerOrg = session.GetObjectByKey <ManufacturerOrg>(PrivateSession.Instance.ManufacturerOrgId); newManufacturerOrg.Code = txtCode.Text; newManufacturerOrg.Name = txtName.Text; newManufacturerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString()); newManufacturerOrg.Save(); } } catch (Exception ex) { isSuccess = false; throw; } finally { popManufacturerEdit.JSProperties.Add("cpCallbackArgs", String.Format("{{ \"recordId\": \"{0}\", \"isSuccess\": {1} }}", recordIdStr, isSuccess.ToString().ToLower())); } break; default: break; } }
protected void popCustomerEdit_WindowCallback(object source, DevExpress.Web.ASPxPopupControl.PopupWindowCallbackArgs e) { string[] args = e.Parameter.Split('|'); switch (args[0]) { case "new": CustomerOrg tempCustomerOrg = CustomerOrg.InitNewRow(session); PrivateSession.Instance.CustomerOrgId = tempCustomerOrg.OrganizationId; dsCustomer.CriteriaParameters["CustomerOrgId"].DefaultValue = PrivateSession.Instance.CustomerOrgId.ToString(); ClearForm(); initLbCustomerTypeForAdding(); #region customer session.BeginTransaction(); try { ObjectType objectType_cus = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_cus = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsObject_cus = objectBO_cus.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); // OrganizationObject OrganizationObject organizatoinObject_cus = new OrganizationObject(session) { ObjectId = cmsObject_cus, OrganizationId = tempCustomerOrg }; organizatoinObject_cus.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType_cus = new OrganizationCustomType(session) { ObjectTypeId = objectType_cus, OrganizationId = tempCustomerOrg }; organizationCustomType_cus.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } if (lbCustomerType.Items[0].Selected == true) { xCallbackPanel_customer.Visible = true; ObjectType objectType_cus1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); OrganizationObject organizationObject_sup = tempCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_cus1).FirstOrDefault(); grid_customer.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_customer.DataBind(); //grid_customer.CMSObjectId = cmsObject_cus.ObjectId; //grid_customer.DataBind(); } else { xCallbackPanel_customer.Visible = false; } #endregion #region supplier session.BeginTransaction(); try { ObjectType objectType_sup = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_sup = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsObject_sup = objectBO_sup.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); // OrganizationObject OrganizationObject organizatoinObject_sup = new OrganizationObject(session) { ObjectId = cmsObject_sup, OrganizationId = tempCustomerOrg }; organizatoinObject_sup.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType_sup = new OrganizationCustomType(session) { ObjectTypeId = objectType_sup, OrganizationId = tempCustomerOrg }; organizationCustomType_sup.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } if (lbCustomerType.Items[1].Selected == true) { xCallbackPanel_supplier.Visible = true; ObjectType objectType_sup1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); OrganizationObject organizationObject_sup = tempCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_sup1).FirstOrDefault(); grid_supplier.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_supplier.DataBind(); //grid_supplier.CMSObjectId = cmsObject_sup.ObjectId; //grid_supplier.DataBind(); } else { xCallbackPanel_supplier.Visible = false; } #endregion break; case "edit": ClearForm(); if (args.Length > 1) { PrivateSession.Instance.CustomerOrgId = Guid.Parse(args[1]); dsCustomer.CriteriaParameters["CustomerOrgId"].DefaultValue = PrivateSession.Instance.CustomerOrgId.ToString(); txtCode.Text = CurrentCustomerOrg.Code; loadLbCustomerType(); if (CurrentCustomerOrg.OrganizationObjects.FirstOrDefault() == null) { #region customer session.BeginTransaction(); try { ObjectType objectType_cus1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_cus1 = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsObject_cus1 = objectBO_cus1.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); // OrganizationObject OrganizationObject organizatoinObject_cus1 = new OrganizationObject(session) { ObjectId = cmsObject_cus1, OrganizationId = CurrentCustomerOrg }; organizatoinObject_cus1.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType_cus1 = new OrganizationCustomType(session) { ObjectTypeId = objectType_cus1, OrganizationId = CurrentCustomerOrg }; organizationCustomType_cus1.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } if (lbCustomerType.Items[0].Selected == true) { xCallbackPanel_customer.Visible = true; ObjectType objectType_cus1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_cus1).FirstOrDefault(); grid_customer.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_customer.DataBind(); //grid_customer.CMSObjectId = cmsObject_cus1.ObjectId; //grid_customer.DataBind(); } else { xCallbackPanel_customer.Visible = false; } #endregion #region supplier session.BeginTransaction(); try { ObjectType objectType_sup1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_sup1 = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsObject_sup1 = objectBO_sup1.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); // OrganizationObject OrganizationObject organizatoinObject_sup1 = new OrganizationObject(session) { ObjectId = cmsObject_sup1, OrganizationId = CurrentCustomerOrg }; organizatoinObject_sup1.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType_sup1 = new OrganizationCustomType(session) { ObjectTypeId = objectType_sup1, OrganizationId = CurrentCustomerOrg }; organizationCustomType_sup1.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } if (lbCustomerType.Items[1].Selected == true) { xCallbackPanel_supplier.Visible = true; ObjectType objectType_sup1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_sup1).FirstOrDefault(); grid_supplier.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_supplier.DataBind(); //grid_supplier.CMSObjectId = cmsObject_sup1.ObjectId; //grid_supplier.DataBind(); } else { xCallbackPanel_supplier.Visible = false; } #endregion } else { #region load customer data if (lbCustomerType.Items[0].Selected == true) { xCallbackPanel_customer.Visible = true; ObjectType objectType_cus1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_cus1).FirstOrDefault(); grid_customer.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_customer.DataBind(); } else { xCallbackPanel_customer.Visible = false; } #endregion #region load supplier data if (lbCustomerType.Items[1].Selected == true) { xCallbackPanel_supplier.Visible = true; ObjectType objectType_sup1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_sup1).FirstOrDefault(); grid_supplier.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_supplier.DataBind(); } else { xCallbackPanel_supplier.Visible = false; } #endregion } } break; case "save": bool isSuccess = true; string recordIdStr = null; try { session.BeginTransaction(); //Check validation if (!IsSelectedLbType()) { throw new Exception(String.Format("Phải chọn ít nhất một phân loại cho khách hàng")); } if (!ASPxEdit.AreEditorsValid(pagCustomer, true)) { popCustomerEdit.JSProperties.Add("cpInvalid", true); pagCustomer.ActiveTabIndex = 0; return; } //Logic to save data if (args.Length > 1) { //Update mode //Update general information recordIdStr = args[1]; Guid recordId = Guid.Parse(recordIdStr); Organization editCustomerOrg = session.GetObjectByKey <Organization>(PrivateSession.Instance.CustomerOrgId); editCustomerOrg.Code = txtCode.Text; editCustomerOrg.Name = txtName.Text; editCustomerOrg.TaxNumber = txtTaxNumber.Text; // Duc.Vo 10/09/2013 INS-START editCustomerOrg.Address = txtAddress.Text; // Duc.Vo 10/09/2013 INS-START editCustomerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString()); //----Duc.Vo 03/11/2013 INS -START selectedObjectTypeId = new List <Guid>(); foreach (ListEditItem l in lbCustomerType.Items) { if (l.Selected) { selectedObjectTypeId.Add(Guid.Parse(l.Value.ToString())); } } if (editCustomerOrg is SupplierOrg) { supplierBO.updateTradingCategoriesForObject <SupplierOrg>(session, recordId, selectedObjectTypeId); } else { supplierBO.updateTradingCategoriesForObject <CustomerOrg>(session, recordId, selectedObjectTypeId); } //----Duc.Vo 03/11/2013 INS -END editCustomerOrg.Save(); session.CommitTransaction(); } else { //Insert mode CustomerOrg newCustomerOrg = session.GetObjectByKey <CustomerOrg>(PrivateSession.Instance.CustomerOrgId); newCustomerOrg.Code = txtCode.Text; newCustomerOrg.Name = txtName.Text; newCustomerOrg.TaxNumber = txtTaxNumber.Text; // Duc.Vo 10/09/2013 INS-START newCustomerOrg.Address = txtAddress.Text; // Duc.Vo 10/09/2013 INS-START newCustomerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString()); newCustomerOrg.Save(); //----Duc.Vo 03/11/2013 INS -START selectedObjectTypeId = new List <Guid>(); foreach (ListEditItem l in lbCustomerType.Items) { if (l.Selected) { selectedObjectTypeId.Add(Guid.Parse(l.Value.ToString())); } } supplierBO.updateTradingCategoriesForObject <CustomerOrg>(session, newCustomerOrg.OrganizationId, selectedObjectTypeId); //----Duc.Vo 03/11/2013 INS -END session.CommitTransaction(); } } catch (Exception ex) { session.RollbackTransaction(); isSuccess = false; throw; } finally { popCustomerEdit.JSProperties.Add("cpCallbackArgs", String.Format("{{ \"recordId\": \"{0}\", \"isSuccess\": {1} }}", recordIdStr, isSuccess.ToString().ToLower())); } break; default: break; } }