private void OnSaveInfo() { try { _serviceGroup.Code = txtCode.Text; _serviceGroup.Name = txtName.Text; _serviceGroup.EnglishName = string.Empty; _serviceGroup.Note = txtNote.Text; _serviceGroup.Status = (byte)Status.Actived; if (_isNew) { _serviceGroup.CreatedDate = DateTime.Now; _serviceGroup.CreatedBy = Guid.Parse(Global.UserGUID); } else { _serviceGroup.UpdatedDate = DateTime.Now; _serviceGroup.UpdatedBy = Guid.Parse(Global.UserGUID); } List <Service_ServiceGroup> addedList = new List <Service_ServiceGroup>(); foreach (string serviceGUID in _addedServices) { Service_ServiceGroup ssg = new Service_ServiceGroup(); ssg.ServiceGUID = Guid.Parse(serviceGUID); ssg.CreatedDate = DateTime.Now; ssg.DeletedBy = Guid.Parse(Global.UserGUID); ssg.Status = (byte)Status.Actived; addedList.Add(ssg); } Result result = ServiceGroupBus.InsertServiceGroup(_serviceGroup, addedList, _deletedServices); if (!result.IsOK) { MsgBox.Show(this.Text, result.GetErrorAsString("ServiceGroupBus.InsertServiceGroup"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("ServiceGroupBus.InsertServiceGroup")); this.DialogResult = System.Windows.Forms.DialogResult.Cancel; } } catch (Exception e) { MsgBox.Show(this.Text, e.Message, IconType.Error); Utility.WriteToTraceLog(e.Message); } }
public static Result GetServiceGroup(string serviceGUID) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); Service_ServiceGroup service_ServiceGroup = db.Service_ServiceGroups.SingleOrDefault <Service_ServiceGroup>(s => s.ServiceGUID.ToString() == serviceGUID && s.Status == (byte)Status.Actived); if (service_ServiceGroup != null) { if (service_ServiceGroup.ServiceGroup.Status == (byte)Status.Actived) { result.QueryResult = service_ServiceGroup.ServiceGroup; } } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }
public static Result InsertServiceGroup(ServiceGroup serviceGroup, List <Service_ServiceGroup> addedList, List <string> deletedKeys) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); string desc = string.Empty; using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew)) { //Insert if (serviceGroup.ServiceGroupGUID == null || serviceGroup.ServiceGroupGUID == Guid.Empty) { serviceGroup.ServiceGroupGUID = Guid.NewGuid(); db.ServiceGroups.InsertOnSubmit(serviceGroup); db.SubmitChanges(); desc += string.Format("- Nhóm dịch vụ: GUID: '{0}', Mã nhóm: '{1}', Tên nhóm: '{2}'\n", serviceGroup.ServiceGroupGUID.ToString(), serviceGroup.Code, serviceGroup.Name); if (addedList != null && addedList.Count > 0) { desc += "- Danh sách dịch vụ được thêm:\n"; //Danh sách dịch vụ foreach (Service_ServiceGroup ssg in addedList) { ssg.Service_GroupServiceGUID = Guid.NewGuid(); ssg.ServiceGroupGUID = serviceGroup.ServiceGroupGUID; db.Service_ServiceGroups.InsertOnSubmit(ssg); db.SubmitChanges(); desc += string.Format(" + GUID: '{0}', Dịch vụ: '{1}'\n", ssg.Service_GroupServiceGUID.ToString(), ssg.Service.Name); } } //Tracking desc = desc.Substring(0, desc.Length - 1); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Add; tk.Action = "Thêm thông tin nhóm dịch vụ"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } else //Update { ServiceGroup srvGroup = db.ServiceGroups.SingleOrDefault <ServiceGroup>(o => o.ServiceGroupGUID == serviceGroup.ServiceGroupGUID); if (srvGroup != null) { srvGroup.Code = serviceGroup.Code; srvGroup.Name = serviceGroup.Name; srvGroup.EnglishName = serviceGroup.EnglishName; srvGroup.CreatedDate = serviceGroup.CreatedDate; srvGroup.CreatedBy = serviceGroup.CreatedBy; srvGroup.UpdatedDate = serviceGroup.UpdatedDate; srvGroup.UpdatedBy = serviceGroup.UpdatedBy; srvGroup.DeletedDate = serviceGroup.DeletedDate; srvGroup.DeletedBy = serviceGroup.DeletedBy; srvGroup.Status = serviceGroup.Status; db.SubmitChanges(); desc += string.Format("- Nhóm dịch vụ: GUID: '{0}', Mã nhóm: '{1}', Tên nhóm: '{2}'\n", srvGroup.ServiceGroupGUID.ToString(), srvGroup.Code, serviceGroup.Name); //Delete dịch vụ if (deletedKeys != null && deletedKeys.Count > 0) { desc += "- Danh sách dịch vụ được xóa:\n"; foreach (string key in deletedKeys) { Service_ServiceGroup ssg = db.Service_ServiceGroups.SingleOrDefault <Service_ServiceGroup>(c => c.ServiceGUID.ToString() == key && c.Status == (byte)Status.Actived); if (ssg != null) { ssg.DeletedDate = DateTime.Now; ssg.DeletedBy = Guid.Parse(Global.UserGUID); ssg.Status = (byte)Status.Deactived; desc += string.Format(" + GUID: '{0}', Dịch vụ: '{1}'\n", ssg.Service_GroupServiceGUID.ToString(), ssg.Service.Name); } } db.SubmitChanges(); } //Add dịch vụ if (addedList != null && addedList.Count > 0) { desc += "- Danh sách dịch vụ được thêm:\n"; foreach (Service_ServiceGroup ssg in addedList) { ssg.Service_GroupServiceGUID = Guid.NewGuid(); ssg.ServiceGroupGUID = serviceGroup.ServiceGroupGUID; db.Service_ServiceGroups.InsertOnSubmit(ssg); db.SubmitChanges(); desc += string.Format(" + GUID: '{0}', Dịch vụ: '{1}'\n", ssg.Service_GroupServiceGUID.ToString(), ssg.Service.Name); } } //Tracking desc = desc.Substring(0, desc.Length - 1); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Edit; tk.Action = "Sửa thông tin nhóm dịch vụ"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } } tnx.Complete(); } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }