public static string DeleteOrganization(string org_id, string user_id, string RequestID) { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "delete")) { throw new Exception("No Access."); } LINQ_SystemDataContext dc = new LINQ_SystemDataContext(); try { SYS_Organization the_record = (from c in dc.SYS_Organizations where c.OrgID == org_id && c.Active == true select c).FirstOrDefault(); if (the_record == null) { return("Error~We can't find"); } the_record.Active = false; the_record.ModifiedOn = DateTime.Now; the_record.ModifiedBy = user_id; the_record.LastAction = Guid.NewGuid().ToString(); dc.SubmitChanges(); return("Success~"); } catch (ChangeConflictException ex) { return("Success~"); } }
public int InsertSYS_Organization(SYS_Organization sys_organization) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); try { List <DbParameter> para = new List <DbParameter>(); DbParameter ouput = _DbHelper.CreateParameter(FIELD_ID, DbType.Int32, true); para.Add(_DbHelper.CreateParameter(FIELD_NAME, sys_organization.Name, false)); para.Add(_DbHelper.CreateParameter(FIELD_CODE, sys_organization.Code, false)); para.Add(_DbHelper.CreateParameter(FIELD_ADDRESS, sys_organization.Address, false)); para.Add(_DbHelper.CreateParameter(FIELD_PHONE, sys_organization.Phone, false)); para.Add(_DbHelper.CreateParameter(FIELD_FAX, sys_organization.Fax, false)); para.Add(_DbHelper.CreateParameter(FIELD_EMAIL, sys_organization.Email, false)); para.Add(_DbHelper.CreateParameter(FIELD_WEBSITE, sys_organization.Website, false)); para.Add(_DbHelper.CreateParameter(FIELD_TYPE, sys_organization.Type, false)); para.Add(_DbHelper.CreateParameter(FIELD_PARENTID, sys_organization.ParentId, false)); para.Add(_DbHelper.CreateParameter(FIELD_IDPROVINCE, sys_organization.IDProvince, false)); para.Add(_DbHelper.CreateParameter(FIELD_LEVELREPORT, sys_organization.LevelReport, false)); para.Add(ouput); _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_Organization_Insert]", para.ToArray()); return((int)ouput.Value); } catch (Exception ex) { throw new Exception(String.Format("SYS_OrganizationDataAccess.Insert: {0}", ex.Message)); } finally { conn.Close(); } }
/// <summary> /// 根据对象实体数据新增一个组织机构节点 /// </summary> /// <param name="uid"></param> /// <param name="obj">组织节点对象</param> /// <param name="index">原序号</param> /// <returns>bool 是否成功</returns> private bool InsertData(Guid uid, SYS_Organization obj, int index) { var cmds = new List <SqlCommand>(); var sql = "insert SYS_Organization (ParentId, NodeType, [Index], Code, Name, Alias, FullName, PositionId, CreatorUserId)"; sql += "select @ParentId, @NodeType, @Index, @Code, @Name, @Alias, @FullName, @PositionId, @CreatorUserId;"; sql += "select ID from SYS_Organization where SN = scope_identity()"; var parm = new[] { new SqlParameter("@ParentId", SqlDbType.UniqueIdentifier) { Value = obj.ParentId }, new SqlParameter("@NodeType", obj.NodeType), new SqlParameter("@Index", obj.Index), new SqlParameter("@Code", obj.Code), new SqlParameter("@Name", obj.Name), new SqlParameter("@Alias", obj.Alias), new SqlParameter("@FullName", obj.FullName), new SqlParameter("@PositionId", SqlDbType.UniqueIdentifier) { Value = obj.PositionId }, new SqlParameter("@CreatorUserId", SqlDbType.UniqueIdentifier) { Value = uid } }; cmds.Add(MakeCommand(ChangeIndex("SYS_Organization", index, obj.Index, obj.ParentId, false))); cmds.Add(MakeCommand(sql, parm)); return(SqlExecute(cmds)); }
/// <summary> /// 根据对象实体数据更新组织机构信息 /// </summary> /// <param name="obj">组织节点对象</param> /// <param name="index">原序号</param> /// <returns>int 更新成功的记录数量</returns> private bool Update(SYS_Organization obj, int index) { var cmds = new List <SqlCommand>(); const string sql = "update SYS_Organization set [Index] = @Index, Code = @Code, Name = @Name, Alias = @Alias, FullName = @FullName, PositionId = @PositionId where ID = @ID"; var parm = new[] { new SqlParameter("@ID", SqlDbType.UniqueIdentifier) { Value = obj.ID }, new SqlParameter("@Index", obj.Index), new SqlParameter("@Code", obj.Code), new SqlParameter("@Name", obj.Name), new SqlParameter("@Alias", obj.Alias), new SqlParameter("@FullName", obj.FullName), new SqlParameter("@PositionId", SqlDbType.UniqueIdentifier) { Value = obj.PositionId } }; cmds.Add(MakeCommand(ChangeIndex("SYS_Organization", index, obj.Index, obj.ParentId, false))); cmds.Add(MakeCommand(sql, parm)); return(SqlExecute(cmds)); }
public SYS_Organization SelectSYS_Organization(int ID) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); SYS_Organization sys_organization = new SYS_Organization(); DbDataReader reader = null; try { List <DbParameter> para = new List <DbParameter>(); para.Add(_DbHelper.CreateParameter(FIELD_ID, ID, false)); reader = _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_Organization_GetByID]", para.ToArray()); if (reader.HasRows && reader.Read()) { SYS_OrganizationDataAccess.SetSYS_OrganizationInfo(reader, ref sys_organization); } return(sys_organization); } catch (Exception ex) { throw new Exception(String.Format("SYS_OrganizationDataAccess.SelectById: {0}", ex.Message)); } finally { if (reader != null) { reader.Close(); } conn.Close(); } }
public SYS_Organization SelectSYS_Organization_GetByCode(string Code, string Connect) { SYS_Organization sys_organization = new SYS_Organization(); DbDataReader reader = null; DbConnection dbConnection = Common.CreateConnection(Connect); dbConnection.Open(); try { List <DbParameter> para = new List <DbParameter>(); para.Add(_DbHelper.CreateParameter("Code", Code, false)); reader = _DbHelper.ExecuteReader(dbConnection, Common.DatabaseSchema + "[SYS_Organization_GetByCode]", para.ToArray()); if (reader.HasRows && reader.Read()) { SYS_OrganizationDataAccess.SetSYS_OrganizationInfo(reader, ref sys_organization); } return(sys_organization); } catch (Exception ex) { throw new Exception(String.Format("SYS_Organization_GetByCode: {0}", ex.Message)); } finally { if (reader != null) { reader.Close(); } dbConnection.Close(); } }
private static void SetSYS_OrganizationUserInfo(DbDataReader reader, ref SYS_Organization sys_organization) { sys_organization.UserName = "" + reader["UserName"]; sys_organization.Email = "" + reader["Email"]; sys_organization.Name = "" + reader[FIELD_NAME]; sys_organization.ID = int.Parse("0" + reader[FIELD_ID]); sys_organization.NumberPhone = "" + reader["NumberPhone"]; }
private static void SetListSYS_OrganizationUserInfo(ref DbDataReader reader, ref List <SYS_Organization> sys_organizations) { SYS_Organization sys_organization = null; while (reader.Read()) { sys_organization = new SYS_Organization(); SYS_OrganizationDataAccess.SetSYS_OrganizationUserInfo(reader, ref sys_organization); sys_organizations.Add(sys_organization); } }
/// <summary> /// 根据对象实体数据更新组织机构表ParentId字段 /// </summary> /// <param name="id"></param> /// <param name="org">组织节点对象</param> /// <returns>JsonResult</returns> public JsonResult SetOrgParent(string id, SYS_Organization org) { const string action = "DB1A4EA2-1B3E-41AD-91FA-A3945AB7D901"; var verify = new SessionVerify(); if (!verify.Compare(action)) { return(verify.Result); } return(Update(org) ? verify.Result : verify.Result.DataBaseError()); }
/// <summary> /// 根据对象实体数据更新组织机构信息 /// </summary> /// <param name="id"></param> /// <param name="obj">组织节点对象</param> /// <param name="index">原序号</param> /// <returns>JsonResult</returns> public JsonResult UpdateOrg(string id, SYS_Organization obj, int index) { const string action = "542D5E28-8102-40C6-9C01-190D13DBF6C6"; var verify = new SessionVerify(); if (!verify.Compare(action)) { return(verify.Result); } return(Update(obj) ? verify.Result : verify.Result.DataBaseError()); }
/// <summary> /// 根据对象实体数据新增一个组织机构节点 /// </summary> /// <param name="org">组织节点对象</param> /// <param name="index">原序号</param> /// <returns>JsonResult</returns> public JsonResult AddOrg(SYS_Organization org, int index) { const string action = "88AC97EF-52A3-4F7F-8121-4C311206535F"; var verify = new SessionVerify(); if (!verify.Compare(action)) { return(verify.Result); } var result = verify.Result; return(InsertData(verify.Basis.UserId, org, index) ? result.Created() : result.DataBaseError()); }
public void UpdateSYS_Organization(DbTransaction transaction, SYS_Organization sys_organization) { try { List <DbParameter> para = new List <DbParameter>(); para.Add(_DbHelper.CreateParameter(FIELD_ID, sys_organization.ID, false)); para.Add(_DbHelper.CreateParameter(FIELD_NAME, sys_organization.Name, false)); para.Add(_DbHelper.CreateParameter(FIELD_PARENTID, sys_organization.ParentId, false)); _DbHelper.ExecuteNonQuery(transaction, Common.DatabaseSchema + "[SYS_Organization_Update]", para.ToArray()); } catch (Exception ex) { throw new Exception(String.Format("SYS_OrganizationDataAccess.Update: {0}", ex.Message)); } }
private static void SetSYS_OrganizationInfo(DbDataReader reader, ref SYS_Organization sys_organization) { sys_organization.ID = int.Parse("0" + reader[FIELD_ID]); sys_organization.Name = "" + reader[FIELD_NAME]; sys_organization.ParentId = int.Parse("0" + reader[FIELD_PARENTID]); if (reader.FieldCount > 3) { sys_organization.Code = "" + reader[FIELD_CODE]; } sys_organization.Address = "" + reader[FIELD_ADDRESS]; sys_organization.Phone = "" + reader[FIELD_PHONE]; sys_organization.Fax = "" + reader[FIELD_FAX]; sys_organization.Email = "" + reader[FIELD_EMAIL]; sys_organization.Website = "" + reader[FIELD_WEBSITE]; sys_organization.Type = int.Parse("0" + reader[FIELD_TYPE]); sys_organization.IDProvince = int.Parse("0" + reader[FIELD_IDPROVINCE]); sys_organization.LevelReport = int.Parse("0" + reader[FIELD_LEVELREPORT]); }
public static string do_saveorganization(string orgid, string org_name, string org_code) { try { LINQ_SystemDataContext dc = new LINQ_SystemDataContext(); SYS_Organization the_record = new SYS_Organization(); if (string.IsNullOrEmpty(orgid)) { the_record = new SYS_Organization { OrgID = Guid.NewGuid().ToString(), OrgName = org_name, OrgCode = org_code, OrgPlan = string.Empty, JointDate = DateTime.Now, ExpiryDate = DateTime.Now, Remark1 = string.Empty, Active = true, UserCount = "5", Remark = string.Empty, CreatedBy = "4", CreatedOn = DateTime.Now, ModifiedBy = "4", ModifiedOn = DateTime.Now, LastAction = Guid.NewGuid().ToString() }; dc.SYS_Organizations.InsertOnSubmit(the_record); } else { the_record = (from org in dc.SYS_Organizations where org.OrgID == orgid && org.Active == true select org).FirstOrDefault(); the_record.OrgName = org_name; the_record.OrgCode = org_code; } dc.SubmitChanges(); return("Success~" + the_record.OrgID); } catch (Exception ex) { return("Error~" + ex.Message); } }
public void DeleteSYS_Organization(SYS_Organization sys_organization) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); try { List <DbParameter> para = new List <DbParameter>(); para.Add(_DbHelper.CreateParameter(FIELD_ID, sys_organization.ID, false)); _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_Organization_Delete]", para.ToArray()); } catch (Exception) { throw; } finally { conn.Close(); } }
public int InsertSYS_Organization(DbTransaction transaction, SYS_Organization sys_organization) { try { List <DbParameter> para = new List <DbParameter>(); DbParameter ouput = _DbHelper.CreateParameter(FIELD_ID, DbType.Int32, true); para.Add(_DbHelper.CreateParameter(FIELD_NAME, sys_organization.Name, false)); para.Add(_DbHelper.CreateParameter(FIELD_PARENTID, sys_organization.ParentId, false)); para.Add(ouput); _DbHelper.ExecuteNonQuery(transaction, Common.DatabaseSchema + "[SYS_Organization_Insert]", para.ToArray()); return((int)ouput.Value); } catch (Exception ex) { throw new Exception(String.Format("SYS_OrganizationDataAccess.Insert: {0}", ex.Message)); } }
/// <summary> /// 根据对象实体数据更新组织机构表ParentId字段 /// </summary> /// <param name="obj">组织节点对象</param> /// <returns>int 更新成功的记录数量</returns> private bool Update(SYS_Organization obj) { var org = GetOrg(obj.ID); var cmds = new List <SqlCommand>(); const string sql = "update SYS_Organization set ParentId = @ParentId, [Index] = @Index where ID = @ID"; var parm = new[] { new SqlParameter("@ID", SqlDbType.UniqueIdentifier) { Value = obj.ID }, new SqlParameter("@Index", obj.Index), new SqlParameter("@ParentId", SqlDbType.UniqueIdentifier) { Value = obj.ParentId } }; cmds.Add(MakeCommand(ChangeIndex("SYS_Organization", 999, obj.Index, obj.ParentId, false))); cmds.Add(MakeCommand(ChangeIndex("SYS_Organization", org.Index, 999, org.ParentId, false))); cmds.Add(MakeCommand(sql, parm)); return(SqlExecute(cmds)); }
public int InsertSYS_Organization(SYS_Organization sys_organization) { return(_sys_organizationDataAccess.InsertSYS_Organization(sys_organization)); }
public static List <Object> GetAllOrganizationWithPagination(string search_text, string search_org, string RequestID, string PageNoString) { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "read")) { throw new Exception("No Access."); } //Check Agent Access LINQ_SystemDataContext dc_system = new LINQ_SystemDataContext(); SYS_UserView the_user = (from c in dc_system.SYS_UserViews where c.UserID == RequestID select c).FirstOrDefault(); if (the_user == null) { throw new Exception("System cannot find the user"); } int pageNo = 0; int.TryParse(PageNoString, out pageNo); //Get Skip Count int skip_count = (pageNo - 1) * RecordCountPerPage; LINQ_SystemDataContext dc = new LINQ_SystemDataContext(); SYS_Organization org = new SYS_Organization(); //Add into Query Statment var Query = (from c in dc.SYS_OrganizationViews where c.Active == true && ((search_text == "") || (search_text != "" && ( c.LastAction.Contains(search_text) || c.OrgName.Contains(search_text) || c.OrgCode.Contains(search_text) || c.UserCount.Contains(search_text) || c.OrgPlan.Contains(search_text) ))) && ((search_org == "") || (search_org != "" && ( c.LastAction.Contains(search_org) || c.OrgName.Contains(search_org) || c.OrgCode.Contains(search_org) || c.UserCount.Contains(search_org) || c.OrgPlan.Contains(search_org) ))) select c).OrderByDescending(x => x.OrgName); //Get Total Record Count int TotalCount = Query.Count(); //Get Total Number of Page int TotalPage = (TotalCount / RecordCountPerPage) + (TotalCount % RecordCountPerPage == 0 ? 0 : 1); List <Object> result = new List <object>(); //Add overall pagination info on Index 0 string previous_button = "y"; if (pageNo == 1 || TotalPage == 1) { previous_button = "n"; } string next_button = "y"; if (pageNo == TotalPage) { next_button = "n"; } if (TotalPage == 1) { previous_button = "n"; next_button = "n"; } result.Add(TotalCount.ToString() + "~" + TotalPage.ToString() + "~" + pageNo.ToString() + "~" + previous_button + "~" + next_button); //Add Real Record Data from Index 1 result.AddRange(new List <Object>( Query .Skip(skip_count).Take(RecordCountPerPage) // Add Skip and Take Function .ToList())); return(result); }
public static string SaveOrganization(string org_id, string user_id, string org_name, string org_code, string orgType, string joint_date, string expiry_date, string InvoiceAccountName, string InvoiceAccountNo, string user_count, string orgplan, string Website, string Facebook, string Email, string PhoneNo, string Address, string InvoiceType, string remark, string remark1, string RequestID) { try { LINQ_SystemDataContext dc = new LINQ_SystemDataContext(); DateTime Joint_Date = DateTime.Today; DateTime.TryParseExact(joint_date, "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out Joint_Date); DateTime Expiry_Date = DateTime.Today; DateTime.TryParseExact(expiry_date, "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out Expiry_Date); SYS_Organization the_record = new SYS_Organization(); if (org_id == "" || org_id == null) { the_record = (from c in dc.SYS_Organizations where c.OrgID == org_id && c.Active == true select c).FirstOrDefault(); if (the_record == null) { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "create")) { throw new Exception("No Access."); } the_record = new SYS_Organization() { CreatedBy = user_id, CreatedOn = DateTime.Now, Active = true, OrgID = Guid.NewGuid().ToString(), LastAction = Guid.NewGuid().ToString() }; dc.SYS_Organizations.InsertOnSubmit(the_record); } else { return("Error~Duplicate Organization Name"); } } else { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "update")) { throw new Exception("No Access."); } the_record = (from c in dc.SYS_Organizations where c.OrgID == org_id select c).FirstOrDefault(); if (the_record == null) { throw new Exception("System cannot find the record"); } } the_record.ModifiedBy = user_id; the_record.ModifiedOn = DateTime.Now; the_record.LastAction = Guid.NewGuid().ToString(); the_record.OrgType = orgType; the_record.OrgName = org_name; the_record.OrgCode = org_code; the_record.JointDate = Joint_Date; the_record.ExpiryDate = Expiry_Date; the_record.UserCount = user_count; the_record.OrgPlan = org_code; the_record.Website = Website; the_record.Facebook = Facebook; the_record.Email = Email; the_record.PhoneNo = PhoneNo; the_record.Address = Address; the_record.InvoiceType = InvoiceType; the_record.Remark = remark; the_record.Remark1 = remark1; the_record.InvoiceAccountName = InvoiceAccountName; the_record.InvoiceAccountNo = InvoiceAccountNo; #region update the log SYS_Organization log_obj = dc.GetChangeSet().Updates.OfType <SYS_Organization>().FirstOrDefault(); if (log_obj != null) { if (Controller_SystemLog.WirteUpdateLog(dc.SYS_Organizations.GetModifiedMembers(log_obj).ToList(), org_id, RequestID) == false) { //Error fail to log. } } #endregion dc.SubmitChanges(); return("Success~" + the_record.OrgID); } catch (Exception ex) { return("Error~" + ex.Message); } }
public void DeleteSYS_Organization(SYS_Organization sys_organizations) { _sys_organizationDataAccess.DeleteSYS_Organization(sys_organizations); }
public void UpdateSYS_Organization(SYS_Organization sys_organization) { _sys_organizationDataAccess.UpdateSYS_Organization(sys_organization); }
//Added Organization Code for running no. public static string GetNewRunningCode(string RunningNoCode, string UserID) { string new_running_no = ""; try { LINQ_SystemDataContext dc_sys = new LINQ_SystemDataContext(); SYS_User the_user = (from c in dc_sys.SYS_Users where c.UserID == UserID && c.Active == true select c).FirstOrDefault(); if (the_user == null) { return("No User"); } SysRunningNo the_running_no = (from c in dc_sys.SysRunningNos where c.RunningNoCode == RunningNoCode && c.OrganizationID == the_user.OrgID select c).FirstOrDefault(); if (the_running_no == null) { //check default code SysRunningNo the_default_running_no = (from c in dc_sys.SysRunningNos where c.RunningNoCode == RunningNoCode select c).FirstOrDefault(); if (the_default_running_no == null) { return("No Running Code"); } the_running_no = new SysRunningNo() { RunningNoID = Guid.NewGuid().ToString(), OrganizationID = the_user.OrgID, RunningNoCode = the_default_running_no.RunningNoCode, RunningPrefix = the_default_running_no.RunningPrefix, RunningSequenceWord = "A", RunningSequneceLength = the_default_running_no.RunningSequneceLength, RunningSequence = 0, OrganizationPrefix = true }; dc_sys.SysRunningNos.InsertOnSubmit(the_running_no); } SYS_Organization the_org = (from c in dc_sys.SYS_Organizations where c.OrgID == the_user.OrgID && c.Active == true select c).FirstOrDefault(); if (the_org == null) { return("User don't have company info."); } the_running_no.RunningSequence = the_running_no.RunningSequence + 1; string running_number_length = "D" + the_running_no.RunningSequneceLength.ToString(); if (the_running_no.RunningSequence.ToString().Length > the_running_no.RunningSequneceLength) { #region Get New Running Sequence Word switch (the_running_no.RunningSequenceWord.ToUpper()) { case "A": the_running_no.RunningSequenceWord = "B"; break; case "B": the_running_no.RunningSequenceWord = "C"; break; case "C": the_running_no.RunningSequenceWord = "D"; break; case "D": the_running_no.RunningSequenceWord = "E"; break; case "E": the_running_no.RunningSequenceWord = "F"; break; case "F": the_running_no.RunningSequenceWord = "G"; break; case "G": the_running_no.RunningSequenceWord = "H"; break; case "H": the_running_no.RunningSequenceWord = "I"; break; case "I": the_running_no.RunningSequenceWord = "J"; break; case "J": the_running_no.RunningSequenceWord = "K"; break; case "K": the_running_no.RunningSequenceWord = "L"; break; case "L": the_running_no.RunningSequenceWord = "M"; break; case "M": the_running_no.RunningSequenceWord = "N"; break; case "N": the_running_no.RunningSequenceWord = "O"; break; case "O": the_running_no.RunningSequenceWord = "P"; break; case "P": the_running_no.RunningSequenceWord = "Q"; break; case "Q": the_running_no.RunningSequenceWord = "R"; break; case "R": the_running_no.RunningSequenceWord = "S"; break; case "S": the_running_no.RunningSequenceWord = "T"; break; case "T": the_running_no.RunningSequenceWord = "W"; break; case "W": the_running_no.RunningSequenceWord = "X"; break; case "X": the_running_no.RunningSequenceWord = "Y"; break; case "Y": the_running_no.RunningSequenceWord = "Z"; break; case "Z": the_running_no.RunningSequenceWord = "AA"; break; case "AA": the_running_no.RunningSequenceWord = "AB"; break; default: the_running_no.RunningSequenceWord = "ERR"; break; } the_running_no.RunningSequence = 1; #endregion } new_running_no = the_org.OrgCode.ToUpper() + the_running_no.RunningPrefix + the_running_no.RunningSequenceWord + the_running_no.RunningSequence.ToString(running_number_length); dc_sys.SubmitChanges(); return(new_running_no); } catch (Exception ex) { return("ERR"); } }