- Code: Select all
SELECT TOP 1 HR_SalesmanGroups.SalesmanGroupID FROM HR_SalesmanGroups order BY
The code for the business object is below but I can't work out what might be missing, if I don't assign to the forms business logic variable the form loads with out a problem
- Code: Select all
class SMGroup : JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Maintenance
{
SMGroupMembers _Members;
string _GroupName;
public string GroupName
{
get { return _GroupName; }
set
{
_GroupName = value;
NotifyPropertyChanged("GroupName");
}
}
public SMGroupMembers Members
{
get { return _Members; }
set
{
_Members = value;
NotifyPropertyChanged("Members");
}
}
public SMGroup()
{
System.Diagnostics.Debugger.Launch();
base.ClientClassName = "JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Maintenance";
_GroupName = "";
//SortOrder.FieldName = "Description";
}
private void ClearVariables()
{
//this.RecID = this.Manager.Database.MakeID("");
RecID = Strings.Left(Guid.NewGuid().ToString().Replace("-", ""), 20);
_GroupName = "";
_Members.Clear();
}
public override string DocumentNo
{
get { return this._GroupName.ToString(); }
}
public override string RecIDFieldName
{
get { return "HR_SalesmanGroups.SalesmanGroupID"; }
}
public override string TableName
{
get { return "HR_SalesmanGroups"; }
}
public override string SortFieldValue
{
get
{
switch (SortOrder.Description)
{
case "Group Name.":
return this._GroupName.ToString();
default:
return null;
}
}
}
public override void Delete()
{
this.DeleteFlag = true;
this.Save();
}
public override void CreateNew()
{
ClearVariables();
this.InsertFlag = true;
}
public override void Setup()
{
base.Setup();
SortOrders.Add(new JiwaFinancials.Jiwa.JiwaApplication.IJiwaNavigable.SortKey {
Description = "Group Name.",
FieldName = "HR_SalesmanGroups.Description"
});
_Members = this.Manager.CollectionFactory.CreateCollection<SMGroupMembers, SMGroupMember>();
_Members.Manager = Manager;
_Members.SMGroup = this;
ClearVariables();
}
public override void Clear()
{
//base.Clear();
ClearVariables();
}
public void Search(System.Windows.Forms.Form OwnerForm)
{
var search = this.Manager.Search;
search.Clear();
search.Caption = "Salesman Groups";
var searchOption = new JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.SearchOption();
searchOption.Title = "Salesman Groups";
searchOption.SQLStr = @" SELECT [SalesmanGroupID]
,[Description]
FROM [dbo].[HR_SalesmanGroups] ";
searchOption.OrderBy = @"order by [Description] ";
searchOption.AddColumn("SalesmanGroupID", Microsoft.VisualBasic.VariantType.String, "", 0, 1);
searchOption.AddColumn("Group Name", Microsoft.VisualBasic.VariantType.String, "", 50, 2);
search.AddSearchOption(ref searchOption);
if (search.Show(OwnerForm) == DialogResult.OK)
{
if (search.Results.Count > 0)
{
var idField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(1);
Read(idField.FieldValue.ToString());
}
}
else
{
throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();
}
}
public override void Read(string RecID)
{
//System.Diagnostics.Debugger.Launch();
string SQL = "";
SqlDataReader SQLReader = null;
SqlParameter SQLParam = null;
bool oldReading = IsReading;
try
{
IsReading = true;
var db = this.Manager.Database;
OnReadStart();
Clear();
SQL = @" SELECT [SalesmanGroupID],[Description]
FROM [dbo].[HR_SalesmanGroups] WHERE SalesmanGroupID = @RecID ";
using (SqlCommand SQLCmd = new SqlCommand(SQL, db.SQLConnection, db.SQLTransaction))
{
SQLCmd.CommandTimeout = this.Manager.Database.DefaultCommandTimeout;
SQLParam = new SqlParameter("@RecID", System.Data.SqlDbType.Char);
SQLParam.Value = RecID;
SQLCmd.Parameters.Add(SQLParam);
SQLReader = SQLCmd.ExecuteReader();
if (SQLReader.Read())
{
this.RecID = db.Sanitise(SQLReader, "SalesmanGroupID").ToString();
this.GroupName = db.Sanitise(SQLReader, "Description").ToString();
}
else
{
throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException("Salesman group Not Found");
}
SQLReader.Close();
Members.ReadRecords(this.RecID);
}
if ((SQLReader != null))
{
SQLReader.Close();
}
OnReadEnd();
}
finally
{
if ((SQLReader != null))
{
SQLReader.Close();
}
IsReading = oldReading;
}
}
protected override void iSave()
{
string strSQl = "";
SqlParameter parameter = new SqlParameter();
database database = this.Manager.Database;
database.BeginNewTransaction();
if (this.DeleteFlag)
{
strSQl = @"delete from HR_SalesmanGroups where SalesmanGroupID = @RecID";
using (SqlCommand command = new SqlCommand(strSQl, database.SQLConnection, database.SQLTransaction))
{
parameter = new SqlParameter("@RecID", SqlDbType.Char)
{
Value = this.RecID
};
command.Parameters.Add(parameter);
Members.Delete();
Members.Save();
if (database.ExecuteNonQuery(command) == 0)
{
database.RollBack();
string[] ErrorMessage = new string[] { "unable to delete HR_SalesmanGroups - RecID ", this.RecID };
throw new ConcurrencyConflictException(string.Concat(ErrorMessage));
}
else
{
database.Commit();
}
}
}
else
{
if (this.InsertFlag)
{
strSQl =
@" INSERT INTO HR_SalesmanGroups ([SalesmanGroupID],[Description])
values (@RecID, @GroupName )";
}
else if (this.ChangeFlag)
{
strSQl =
@" update HR_SalesmanGroups set
Description = @GroupName where SalesmanGroupID = @RecID";
}
using (SqlCommand command = new SqlCommand(strSQl, database.SQLConnection, database.SQLTransaction))
{
parameter = new SqlParameter("@RecID", SqlDbType.Char)
{
Value = this.RecID
};
command.Parameters.Add(parameter);
parameter = new SqlParameter("@GroupName", SqlDbType.Char )
{
Value = this.GroupName
};
command.Parameters.Add(parameter);
if (database.ExecuteNonQuery(command) == 0)
{
database.RollBack();
string[] ErrorMessage = new string[] { "unable to ", this.InsertFlag ? "insert into" : "update", " HR_SalesmanGroups ", this.RecID.ToString() };
throw new ConcurrencyConflictException(string.Concat(ErrorMessage));
}
else
{
try
{
Members.Save();
database.Commit();
DeleteFlag = false;
InsertFlag = false;
ChangeFlag = false;
}
catch (Exception)
{
database.RollBack();
string[] ErrorMessage = new string[] { "unable to save Members for salesman group ", this.RecID.ToString() };
throw new ConcurrencyConflictException(string.Concat(ErrorMessage));
}
}
}
}
}
public override void Deserialise(string XMLString)
{
throw new NotImplementedException();
}
public override void Copy()
{
throw new NotImplementedException();
}
public override void Serialise(ref string XML)
{
throw new NotImplementedException();
}
public override Type SerialiseType()
{
return typeof(SMGroup);
}
}
The following is the code in the setup for the form that links the business object to the form
- Code: Select all
_SMGroup = this.Manager.BusinessLogicFactory.CreateBusinessLogic<SMGroup>(this);
this.BusinessLogic = _SMGroup;