public int Compare(object x, object y) { int returnVal= -1; try { switch(_type) { case System.TypeCode.String: returnVal = String.Compare(((ListViewItem)x).SubItems[_col].Text, ((ListViewItem)y).SubItems[_col].Text); break; case System.TypeCode.Int32: if(int.Parse(((ListViewItem)x).SubItems[_col].Text)>int.Parse(((ListViewItem)y).SubItems[_col].Text)) { returnVal = 1; } break; case System.TypeCode.DateTime: DateTimeConverter dtc = new DateTimeConverter(); DateTime dtStartDate=(DateTime)dtc.ConvertFromString(((ListViewItem)x).SubItems[_col].Text); DateTime dtEndDate=(DateTime)dtc.ConvertFromString(((ListViewItem)y).SubItems[_col].Text); returnVal = dtStartDate.CompareTo(dtEndDate); break; default: returnVal = String.Compare(((ListViewItem)x).SubItems[_col].Text, ((ListViewItem)y).SubItems[_col].Text); break; } // Determine whether the sort order is descending. if(_order == SortOrder.Descending) // Invert the value returned by String.Compare. returnVal *= -1; } catch {} return returnVal; }
private void LaunchCardReader_Click(object sender, EventArgs e) { CardReader cr; String name = (String)CardReaderListBox.SelectedItem; if (name != null) { cr = cri.GetCardReader(name); String sdate = PickDateCalendar.SelectionStart.ToShortDateString(); String tdate = TimePicker.Value.ToShortTimeString(); DateTimeConverter dateC = new DateTimeConverter(); DateTime date = (DateTime)dateC.ConvertFromString(String.Concat(sdate, " ", tdate)); CardReaderPanel crp = new CardReaderPanel(cr, date); crp.Show(); } }
public DateTime ConverterDate(string date,bool None) { DateTimeConverter con = new DateTimeConverter(); if (None) { if (date.Contains("CH")) date = date.Replace("CH", "PM"); if (date.Contains("SA")) date = date.Replace("SA", "AM"); return (DateTime)con.ConvertFromString(date); } //Ngược lại string[] mang_ngay = date.Split('/', ' ', ':'); int ngay = int.Parse(mang_ngay[1]); int thang = int.Parse(mang_ngay[0]); int nam = int.Parse(mang_ngay[2]); int gio = int.Parse(mang_ngay[3]); int phut = int.Parse(mang_ngay[4]); int giay = int.Parse(mang_ngay[5]); if (mang_ngay[6] == "PM" && gio != 12) { gio += 12; } DateTime kq = new DateTime(nam, thang, ngay, gio, phut, giay); return kq; }
//hàm chuyển đổi ngày public DateTime convert_day(string date) { DateTimeConverter con = new DateTimeConverter(); return (DateTime)con.ConvertFromString(date); }
public int Compare(object x, object y) { int returnVal = -1; ListViewItem lvix = (ListViewItem)x; ListViewItem lviy = (ListViewItem)y; try { switch (_type) { case System.TypeCode.String: if (lvix.SubItems[_col].Tag != null && lviy.SubItems[_col].Tag != null) { returnVal = String.Compare(lvix.SubItems[_col].Tag.ToString(), lviy.SubItems[_col].Tag.ToString()); } else { returnVal = String.Compare(lvix.SubItems[_col].Text, lviy.SubItems[_col].Text); } break; case System.TypeCode.Int32: if (lvix.SubItems[_col].Tag != null && lviy.SubItems[_col].Tag != null) { if (int.Parse(lvix.SubItems[_col].Tag.ToString()) > int.Parse(lviy.SubItems[_col].Tag.ToString())) { returnVal = 1; } } else { if (int.Parse(lvix.SubItems[_col].Text) > int.Parse(lviy.SubItems[_col].Text)) { returnVal = 1; } } break; case System.TypeCode.Int64: if (lvix.SubItems[_col].Tag != null && lviy.SubItems[_col].Tag != null) { if (Int64.Parse(lvix.SubItems[_col].Tag.ToString()) > Int64.Parse(lviy.SubItems[_col].Tag.ToString())) { returnVal = 1; } } else { if (Int64.Parse(lvix.SubItems[_col].Text) > Int64.Parse(lviy.SubItems[_col].Text)) { returnVal = 1; } } break; case System.TypeCode.DateTime: DateTimeConverter dtc = new DateTimeConverter(); DateTime dtStartDate = (DateTime)dtc.ConvertFromString(lvix.SubItems[_col].Text); DateTime dtEndDate = (DateTime)dtc.ConvertFromString(lviy.SubItems[_col].Text); returnVal = dtStartDate.CompareTo(dtEndDate); break; default: if (lvix.SubItems[_col].Tag != null && lviy.SubItems[_col].Tag != null) { returnVal = String.Compare(lvix.SubItems[_col].Tag.ToString(), lviy.SubItems[_col].Tag.ToString()); } else { returnVal = String.Compare(lvix.SubItems[_col].Text, lviy.SubItems[_col].Text); } break; } // Determine whether the sort order is descending. if (_order == SortOrder.Descending) // Invert the value returned by String.Compare. returnVal *= -1; } catch { } return returnVal; }
public Projecto lerProjecto(string n) { Projecto p = new Projecto(); DataSet ds = new DataSet(); FileStream finschema = new FileStream("exemplo.xsd", FileMode.Open, FileAccess.Read, FileShare.Read); ds.ReadXmlSchema(finschema); finschema.Close(); FileStream findata = new FileStream(n + ".xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); ds.ReadXml(findata); findata.Close(); foreach (DataRow dr in ds.Tables["Projecto"].Rows) { p.setNome((string)(dr["nome"])); p.setFiltros((string)(dr["Filtros"])); DateTimeConverter d = new DateTimeConverter(); DateTime da = new DateTime(); da = (DateTime)(d.ConvertFromString((string)(dr[1]))); p.setData(da); } foreach (DataRow dr in ds.Tables["propriedades"].Rows) { p.setPasta((string)(dr["pasta"])); p.setUrlInicial((string)(dr["url"])); p.setvisualizacaolocal(Convert.ToInt32(dr["visualizacaolocal"])); p.setNivel(Convert.ToInt32(dr["niveis"])); p.setImagensRemotas(Convert.ToInt32(dr["imagensremotas"])); p.setAceitarRejeitar(Convert.ToInt32(dr["aceitarrejeitar"])); } return p; }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var str = value as string; if (str != null) { var note = new PNote(); var values = str.Split(DEL_NOTE); if (values.Length == Enum.GetValues(typeof(Fields)).Length) { string[] arr; var dtc = new DateTimeConverter(); var szc = new SizeConverter(); var scd = new System.Drawing.SizeConverter(); var ptc = new PointConverter(); var scv = new ScheduleConverter(); var skc = new SkinlessConverter(); note.Changed = Convert.ToBoolean(values[(int)Fields.Changed]); note.Completed = Convert.ToBoolean(values[(int)Fields.Completed]); note.CustomOpacity = Convert.ToBoolean(values[(int)Fields.CustomOpacity]); var dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateCreated]); if (dateFromString != null) note.DateCreated = (DateTime)dateFromString; dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateDeleted]); if (dateFromString != null) note.DateDeleted = (DateTime)dateFromString; dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateReceived]); if (dateFromString != null) note.DateReceived = (DateTime)dateFromString; dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateSaved]); if (dateFromString != null) note.DateSaved = (DateTime)dateFromString; dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateSent]); if (dateFromString != null) note.DateSent = (DateTime)dateFromString; note.DockStatus = (DockStatus)Convert.ToInt32(values[(int)Fields.DockStatus]); var sizeFromString = scd.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.EditSize]); if (sizeFromString != null) note.EditSize = (Size)sizeFromString; note.Favorite = Convert.ToBoolean(values[(int)Fields.Favorite]); note.FromDB = Convert.ToBoolean(values[(int)Fields.FromDB]); note.GroupID = Convert.ToInt32(values[(int)Fields.GroupID]); note.ID = values[(int)Fields.ID]; var temp = values[(int)Fields.LinkedNotes]; if (temp != "") { arr = temp.Split(DEL_INNER); foreach (var s in arr) { note.LinkedNotes.Add(s); } } note.Name = values[(int)Fields.Name]; var convertFromString = ptc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.NoteLocation]); if (convertFromString != null) note.NoteLocation = (Point)convertFromString; var fromString = szc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.NoteSize]); if (fromString != null) note.NoteSize = (System.Windows.Size)fromString; note.Opacity = Convert.ToDouble(values[(int)Fields.Opacity], PNStatic.CultureInvariant); note.PasswordString = values[(int)Fields.PasswordString]; note.Pinned = Convert.ToBoolean(values[(int)Fields.Pinned]); note.PrevGroupID = Convert.ToInt32(values[(int)Fields.PrevGroupID]); note.Priority = Convert.ToBoolean(values[(int)Fields.Priority]); note.Protected = Convert.ToBoolean(values[(int)Fields.Protected]); note.ReceivedFrom = values[(int)Fields.ReceivedFrom]; note.Rolled = Convert.ToBoolean(values[(int)Fields.Rolled]); note.Schedule = (PNNoteSchedule)scv.ConvertFromString(values[(int)Fields.Schedule]); note.SentReceived = (SendReceiveStatus)Convert.ToInt32(values[(int)Fields.SentReceived]); note.SentTo = values[(int)Fields.SentTo]; temp = values[(int)Fields.SkinName]; if (temp != PNSkinDetails.NO_SKIN && temp != "") { // TODO - get skin properties } note.Skinless = (PNSkinlessDetails)skc.ConvertFromString(values[(int)Fields.Skinless]); temp = values[(int)Fields.Tags]; if (temp != "") { arr = temp.Split(DEL_INNER); foreach (var s in arr) { note.Tags.Add(s); } } note.Topmost = Convert.ToBoolean(values[(int)Fields.Topmost]); note.Visible = Convert.ToBoolean(values[(int)Fields.Visible]); note.XFactor = Convert.ToDouble(values[(int)Fields.XFactor], PNStatic.CultureInvariant); note.YFactor = Convert.ToDouble(values[(int)Fields.YFactor], PNStatic.CultureInvariant); note.PinClass = values[(int)Fields.PinClass]; note.PinText = values[(int)Fields.PinText]; } return note; } return base.ConvertFrom(context, culture, value); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var str = value as string; if (str != null) { var dwc = new DaysOfWeekConverter(); var mc = new MonthDayConverter(); var avc = new AlarmAfterValuesConverter(); var dtc = new DateTimeConverter(); var sch = new PNNoteSchedule(); var values = str.Split(DEL_INNER); if (values.Length == Enum.GetValues(typeof(Fields)).Length) { sch.AlarmAfter = (AlarmAfterValues)avc.ConvertFromString(values[(int)Fields.AlarmAfter]); var dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.AlarmDate]); if (dateFromString != null) sch.AlarmDate = (DateTime)dateFromString; dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.LastRun]); if (dateFromString != null) sch.LastRun = (DateTime)dateFromString; sch.MonthDay = (MonthDay)mc.ConvertFromString(values[(int)Fields.MonthDay]); sch.RepeatCount = Convert.ToInt32(values[(int)Fields.RepeatCount]); sch.Sound = values[(int)Fields.Sound]; sch.SoundInLoop = Convert.ToBoolean(values[(int)Fields.SoundInLoop]); dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.StartDate]); if (dateFromString != null) sch.StartDate = (DateTime)dateFromString; sch.StartFrom = (ScheduleStart)Convert.ToInt32(values[(int)Fields.StartFrom]); sch.StopAfter = Convert.ToInt32(values[(int)Fields.StopAfter]); sch.Track = Convert.ToBoolean(values[(int)Fields.Track]); sch.Type = (ScheduleType)Convert.ToInt32(values[(int)Fields.Type]); sch.UseTts = Convert.ToBoolean(values[(int)Fields.UseTTS]); sch.Weekdays = (List<DayOfWeek>)dwc.ConvertFromString(values[(int)Fields.Weekdays]); sch.ProgramToRunOnAlert = values[(int)Fields.ExtRun]; sch.CloseOnNotification = Convert.ToBoolean(values[(int)Fields.CloseOnNotify]); } return sch; } return base.ConvertFrom(context, culture, value); }
private async Task<DateTime> GetDateTime(string cloudpath,string filename,LiveConnectClient liveConnectClient) { DateTime ddt = new DateTime(); try { LiveOperationResult lor = await liveConnectClient.GetAsync(cloudpath); DirectoryInfo dirin = new DirectoryInfo(@"C:\users\nico\desktop\office365 key.txt"); DateTime dt = dirin.LastWriteTime; var iEnum = lor.Result.Values.GetEnumerator(); iEnum.MoveNext(); string temp = ""; foreach(dynamic var in iEnum.Current as IEnumerable) { if(var.name.Equals(filename)) { temp = var.updated_time; } } DateTimeConverter dtc = new DateTimeConverter(); ddt = (DateTime)dtc.ConvertFromString(temp); } catch (Exception) { } return ddt; }
private int procura_filtros(string fonte) { if (fonte.Contains("!=")) { string[] valor = fonte.Split('='); valor[1] = valor[1].Trim(); ftd = new FiltroTipoDiferente(valor[1]); return 1; } else if (fonte.Contains("=")) { string[] valor = fonte.Split('='); valor[1] = valor[1].Trim(); fti = new FiltroTipoIgual(valor[1]); return 2; } else if (fonte.Contains("<") && !fonte.Contains("-")) { string[] valor = fonte.Split('<'); valor[1] = valor[1].Trim(); int tam = Convert.ToInt32(valor[1]); ftme = new FiltroTamanhoMenor(tam); return 3; } else if (fonte.Contains(">") && !fonte.Contains("-")) { string[] valor = fonte.Split('>'); valor[1] = valor[1].Trim(); int tam = Convert.ToInt32(valor[1]); ftma = new FiltroTamanhoMaior(tam); return 4; } else if (fonte.Contains("contem")) { fonte = fonte.Replace("contem", "%"); string[] valor = fonte.Split('%'); valor[1] = valor[1].Trim(); string pesquisa = valor[1]; fn = new FiltroNome(pesquisa); return 5; } else if (fonte.Contains("-") && fonte.Contains("<")) { DateTimeConverter conv = new DateTimeConverter(); DateTime d = new DateTime(); string[] partes = fonte.Split('<'); partes[1] = partes[1].Trim(); fonte = partes[1]; d = (DateTime)(conv.ConvertFromString(fonte)); fdme = new FiltroDataMenor(d); return 6; } else if (fonte.Contains("-") && fonte.Contains(">")) { DateTimeConverter conv = new DateTimeConverter(); DateTime d = new DateTime(); string[] partes = fonte.Split('>'); partes[1] = partes[1].Trim(); fonte = partes[1]; d = (DateTime)(conv.ConvertFromString(fonte)); fdma = new FiltroDataMaior(d); return 7; } else return 0; }
private void setupEnterpriseList() // creates all the tree nodes from current document (this.ep) { if (this.ep != null) { this.clearErrors(); DateTimeConverter dtc = new DateTimeConverter(); DateTime datetime = (DateTime)dtc.ConvertFromString(this.ep.properties.datetime); TimeSpan diff = DateTime.Now - datetime; if (diff.TotalHours > 1) addProblem(new Error(-1, "The date of the file is old, is the file saved on a local computer?", "Enterprise", ErrorType.Warning, "IMS Document")); if (encoding.IsEmpty()) encoding = "none"; if(encoding != "iso-8859-1") addProblem(new Error(-1, "Wrong encoding(" + encoding + ") on the IMS Document!", "XML-encoding", ErrorType.Warning, "IMS Document")); if (this.ep.group.ToList().Count == 0) addProblem(new Error(-1, "Could not find any groups in the IMS Document!", "Group", ErrorType.Error, "IMS Document")); if (this.ep.person.ToList().Count == 0) addProblem(new Error(-1, "Could not find any persons in the IMS Document!", "Person", ErrorType.Warning, "IMS Document")); if (this.ep.membership == null) addProblem(new Error(-1, "Could not find any memberships in the IMS Document!", "Membership", ErrorType.Error, "IMS Document")); if (this.errorListView1.InvokeRequired) this.enterpriseList.Invoke(new Action(() => this.enterpriseList.Nodes.Clear())); else this.enterpriseList.Nodes.Clear(); foreach (Root root in this.IMSSettings.General.StartPoint.Roots) { if (root.Value) { if (root.Type != "Person") // root type cannot be Person { List<group> groupList = new List<group>(); foreach (group group in ep.group) { if (group.grouptype[0].typevalue[0].Value == root.Type) { groupList.Add(group); } } if (root.Type == "Unit") // A Unit { if (groupList.Count != 0) { TreeNode parent = new TreeNode(); parent.Name = "None"; parent.Text = root.Type; parent.Tag = "DontRemove[!]"; parent.ToolTipText = "Starting point"; foreach (group group in groupList) { foreach (membership membership in ep.membership) { if (membership.sourcedid.id == group.sourcedid[0].id) { int index = ep.group.ToList().IndexOf(group); TreeNode node = new TreeNode(); node.Name = group.grouptype[0].typevalue[0].Value; if ([email protected]()) addProblem(new Error(index, "The group is missing short description", "Group", ErrorType.Warning, group.sourcedid[0].id)); if (group.sourcedid[0].id.IsEmpty()) addProblem(new Error(index, "The group is missing sourcedID", "Group", ErrorType.Error, "No ID")); node.Text = group.description.@short; node.Tag = index; node.Nodes.Add(""); node.ToolTipText = group.grouptype[0].typevalue[0].Value; parent.Nodes.Add(node); } } } if (this.enterpriseList.InvokeRequired) this.enterpriseList.Invoke(new Action(() => enterpriseList.Nodes.Add(parent))); else enterpriseList.Nodes.Add(parent); } } else // everything besides Unit { if (groupList.Count != 0) { TreeNode parent = new TreeNode(); parent.Name = "None"; parent.Text = root.Type; parent.Tag = "DontRemove[!]"; parent.ToolTipText = "Starting point"; foreach (group group in groupList) { int count = 0; foreach (group group2 in ep.group) // and for every person to find a member with correct sourcedid as a perosn { if (group.sourcedid[0].id == group2.sourcedid[0].id) // person found { TreeNode node = new TreeNode(); if ([email protected]()) addProblem(new Error(count, "The group short description is empty!", "Group", ErrorType.Warning, group.sourcedid[0].id)); if (group.sourcedid[0].id.IsEmpty()) addProblem(new Error(count, "The group did not have a sourcedID", "Group", ErrorType.Error, "No ID")); node.Name = group.grouptype[0].typevalue[0].Value; node.Text = group.description.@short; node.Tag = count; node.Nodes.Add(""); node.ToolTipText = group.grouptype[0].typevalue[0].Value; parent.Nodes.Add(node); } count++; } } if (this.enterpriseList.InvokeRequired) this.enterpriseList.Invoke(new Action(() => enterpriseList.Nodes.Add(parent))); else enterpriseList.Nodes.Add(parent); } } } else // A person { int count = 0; TreeNode parent = new TreeNode(); parent.Name = "None"; parent.Text = root.Type; parent.Tag = "DontRemove[!]"; parent.ToolTipText = "Starting point"; foreach (person person in ep.person) { TreeNode node = new TreeNode(); node.Name = "Person"; node.Text = person.name.fn; if (new Regex(@"[0-9\[\]\^\$\|\?\*\+\(\)\\~`\!@#%&_+={}""<>:;,]").IsMatch(person.name.fn)) addProblem(new Error(count, "The persons includes characters that are not allowed", "Person", ErrorType.Warning, person.sourcedid[0].id)); if (person.name.n.given.IsEmpty() || person.name.n.family.IsEmpty() || person.name.fn.IsEmpty()) addProblem(new Error(count, "Something is wrong with the persons name", "Person", ErrorType.Warning, person.sourcedid[0].id)); if (person.sourcedid[0].id.IsEmpty()) addProblem(new Error(count, "The person had no sourced ID!", "Person", ErrorType.Error, "No ID")); node.Tag = count; node.ToolTipText = "Person"; parent.Nodes.Add(node); count++; } if (this.enterpriseList.InvokeRequired) this.enterpriseList.Invoke(new Action(() => enterpriseList.Nodes.Add(parent))); else enterpriseList.Nodes.Add(parent); } } } } }