private void button3_Click(object sender, EventArgs e) { //设定 comb1 if (dataGridView1.CurrentCell != null) { if (comboBox1.SelectedItem is AlarmStrategy) { AlarmStrategy cas = comboBox1.SelectedItem as AlarmStrategy; //此处还应该操作数据库 使用helper+手写sql语句 if (dataGridView1.CurrentCell.Value is DateCell && (dataGridView1.CurrentCell.Value as DateCell).AS != cas) { DateCell dc = dataGridView1.CurrentCell.Value as DateCell; dc.AS = cas; dataGridView1.Refresh(); if (CurrentSensor.AlarmDic.ContainsKey(dc.YYYYMMDD)) { CurrentSensor.AlarmDic[dc.YYYYMMDD] = cas; //UPDATE SQL string updateSql = string.Format("UPDATE T_ALARM_SENSOR_MAP SET aname='{0}' WHERE date='{1}' AND uid='{2}' AND node='{3}' AND port='{4}'", cas.Name, dc.YYYYMMDD, CurrentSensor.Uid, CurrentSensor.NodeId, CurrentSensor.PortId); SqlLiteHelper.ExecuteNonQuery(db, updateSql); } else { CurrentSensor.AlarmDic.Add(dc.YYYYMMDD, cas); //insert string insertSql = string.Format("INSERT INTO T_ALARM_SENSOR_MAP (aname,date,uid,node,port) VALUES('{0}','{1}','{2}','{3}','{4}')", cas.Name, dc.YYYYMMDD, CurrentSensor.Uid, CurrentSensor.NodeId, CurrentSensor.PortId); SqlLiteHelper.ExecuteNonQuery(db, insertSql); } } } } }
/** * Constructor invoked when copying a readable spreadsheet * * @param dc the date to copy */ protected DateRecord(DateCell dc) : base(CSharpJExcel.Jxl.Biff.Type.NUMBER, dc) { date = new CSharpJExcel.Interop.Date(dc.getDate()); time = dc.isTime(); calculateValue(false); }
void CreateDateCell() { for (int i = 0; i < maxDate; i++) { DateCell dateCell = Instantiate(dateCellPrefab, dateContent).GetComponent <DateCell>(); dateCells.Add(dateCell); } }
private void button4_Click(object sender, EventArgs e) { //编辑 if (dataGridView1.CurrentCell.Value is DateCell) { DateCell dc = dataGridView1.CurrentCell.Value as DateCell; if (dc.AS != null) { Ac.EditStrategy(dc.AS); } } }
protected override Size MeasureOverride(Size availableSize) { int usedCells = 0; double desiredWidth = 0; double desiredHeight = 0; if (!double.IsPositiveInfinity(availableSize.Height) && _band != null) { var index = (int)Math.Floor(_band.ScrollOffset); var offset = (index - _band.ScrollOffset) * cSlotHeight; while (offset < availableSize.Height) { DateCell cell; if (usedCells < _cells.Count) { cell = _cells[usedCells]; } else { cell = new DateCell(); Children.Add(cell); _cells.Add(cell); } usedCells++; var cellValue = _startDate.AddMonths(index); cell._offset = offset; cell._width = DateTime.DaysInMonth(cellValue.Year, cellValue.Month) * cSlotWidth; cell.Content = new CellData(cellValue); cell.ContentTemplate = _band.CellTemplate; cell.Measure(new Size(cell._width, cSlotHeight)); offset += cSlotHeight; index++; desiredHeight = Math.Max(desiredHeight, offset); desiredWidth = Math.Max(desiredWidth, cell._width); } } if (usedCells < _cells.Count) { for (int i = usedCells; i < _cells.Count; i++) { Children.Remove(_cells[i]); } _cells.RemoveRange(usedCells, _cells.Count - usedCells); } return(new Size(desiredWidth, desiredHeight)); }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.CurrentCell != null) { //删除Cell if (dataGridView1.CurrentCell.Value is DateCell) { DateCell dc = dataGridView1.CurrentCell.Value as DateCell; AlarmStrategy ast = dc.AS; if (ast != null) { string dsql = string.Format("DELETE FROM T_ALARM_SENSOR_MAP WHERE date='{0}' AND aname ='{1}' AND uid='{2}' AND node='{3}' AND port='{4}'", dc.YYYYMMDD, ast.Name, CurrentSensor.Uid, CurrentSensor.NodeId, CurrentSensor.PortId); SqlLiteHelper.ExecuteNonQuery(db, dsql); dataGridView1.Refresh(); if (CurrentSensor.AlarmDic.ContainsKey(dc.YYYYMMDD)) { CurrentSensor.AlarmDic.Remove(dc.YYYYMMDD); DateTimePicker1_ValueChanged(null, null); } } } } }
public override Element GetEditor(EditableField field, object parent) { Element view = null; if (view == null) { if (field.PropertyData.Readonly) { view = new TextCell() { Text = ObjectEditor.Translate(field.PropertyData.Title), BindingContext = field, Detail = field.Value.ToString() }; view.SetBinding(TextCell.DetailProperty, nameof(field.Value)); } else { var type = field.SourceProperty.PropertyType; if (field.PropertyData.RelationTo != null) { var inst = Activator.CreateInstance(field.PropertyData.RelationTo); if (inst is IEditorRelation rel) { view = new RelationCell(rel) { Text = ObjectEditor.Translate(field.PropertyData.Title) }; view.SetBinding(DateCell.ValueProperty, nameof(field.Value)); } } else if (type == typeof(string) || type == typeof(int)) { view = new EntryCell() { Label = ObjectEditor.Translate(field.PropertyData.Title) }; view.SetBinding(EntryCell.TextProperty, nameof(field.Value)); } else if (type == typeof(bool)) { view = new SwitchCell() { Text = ObjectEditor.Translate(field.PropertyData.Title) }; view.SetBinding(SwitchCell.OnProperty, nameof(field.Value)); } else if (type == typeof(DateTime)) { view = new DateCell() { Text = ObjectEditor.Translate(field.PropertyData.Title) }; view.SetBinding(DateCell.ValueProperty, nameof(field.Value)); } if (view != null) { view.BindingContext = field; } } } return(view as Element); }
/** * A constructor called by the worksheet when creating a writable version * of a spreadsheet that has been read in * * @param dc the date to copy */ public ExcelDateTime(DateCell dc) : base(dc) { }
private SheetData CreateSheetData <T>(List <T> objects, List <string> headerNames, WorkbookStylesPart stylesPart) { SheetData sheetData = new SheetData(); if (objects != null) { //Fields names of object List <string> fields = GetPropertyInfo <T>(); var az = new List <Char>(Enumerable.Range('A', 'Z' - 'A' + 1).Select(i => (Char)i).ToArray()); List <Char> headers = az.GetRange(0, fields.Count); int numRows = objects.Count; int numCols = fields.Count; Row header = new Row(); int index = 1; header.RowIndex = (uint)index; for (int col = 0; col < numCols; col++) { //Cell c = CreateHeaderCell(headers[col].ToString(), headerNames[col], index, stylesPart.Stylesheet); HeaderCell c = new HeaderCell(headers[col].ToString(), headerNames[col], index, stylesPart.Stylesheet, System.Drawing.Color.DodgerBlue, 12, true); header.Append(c); } sheetData.Append(header); CultureInfo ci = new CultureInfo("en-US"); for (int i = 0; i < numRows; i++) { index++; var obj1 = objects[i]; var r = new Row { RowIndex = (uint)index }; for (int col = 0; col < numCols; col++) { string fieldName = fields[col]; PropertyInfo myf = obj1.GetType().GetProperty(fieldName); if (myf != null) { object obj = myf.GetValue(obj1, null); if (obj != null) { if (obj.GetType() == typeof(string)) { // Cell c = CreateTextCell(headers[col].ToString(), obj.ToString(), index); TextCell c = new TextCell(headers[col].ToString(), obj.ToString(), index); r.Append(c); } else if (obj.GetType() == typeof(bool)) { string value = (bool)obj ? "Yes" : "No"; //Cell c = CreateTextCell(headers[col].ToString(), value, index); TextCell c = new TextCell(headers[col].ToString(), value, index); r.Append(c); } else if (obj.GetType() == typeof(DateTime)) { //string value = GetExcelSerialDate((DateTime) obj).ToString(); string value = ((DateTime)obj).ToOADate().ToString(ci); // stylesPart.Stylesheet is retrieved reference for the appropriate worksheet. //Cell c = CreateDateCell(headers[col].ToString(), value, index, stylesPart.Stylesheet); DateCell c = new DateCell(headers[col].ToString(), (DateTime)obj, index); r.Append(c); } else if (obj.GetType() == typeof(decimal)) { //Cell c = CreateDecimalCell(headers[col].ToString(), obj.ToString(), index, stylesPart.Stylesheet); FormatedNumberCell c = new FormatedNumberCell(headers[col].ToString(), ((decimal)obj).ToString(ci), index); r.Append(c); } else if (obj.GetType() == typeof(double)) { //Cell c = CreateDecimalCell(headers[col].ToString(), obj.ToString(), index, stylesPart.Stylesheet); FormatedNumberCell c = new FormatedNumberCell(headers[col].ToString(), ((double)obj).ToString(ci), index); r.Append(c); } else { long value; if (long.TryParse(obj.ToString(), out value)) { //Cell c = CreateIntegerCell(headers[col].ToString(), obj.ToString(), index); NumberCell c = new NumberCell(headers[col].ToString(), value.ToString(ci), index); r.Append(c); } else { //Cell c = CreateTextCell(headers[col].ToString(), obj.ToString(), index); TextCell c = new TextCell(headers[col].ToString(), obj.ToString(), index); r.Append(c); } } } } } sheetData.Append(r); } } return(sheetData); }
public void DateTimePicker1_ValueChanged(object sender, EventArgs e) { int weekNum = Convert.ToInt16(DateTime.Parse(dateTimePicker1.Value.ToString("yyyy年MM月01日")).DayOfWeek); dataGridView1.Rows.Clear(); if (weekNum == 0) { weekNum = 6; } else { weekNum -= 1; } //根据星期和每月天数计算行数 //31天并且1号是周六日 或 30天一号为周日 6行 //剩下均为5行 //边界高度为1所以 计算行高的时候应该先减上下边界为2再减列头高度减2得出结果再减1 int rowC = 0; int monthDayCount = DateTime.DaysInMonth(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month); if ((monthDayCount == 30 && weekNum == 6) || monthDayCount == 31 && weekNum >= 5) { rowC = 6; } else { rowC = 5; } int rowHeight = (this.Size.Height - 2 - dataGridView1.ColumnHeadersHeight - 2) / rowC - 1; dataGridView1.RowTemplate.Height = rowHeight; //必须先设置模板行高再添加行,否则不生效 dataGridView1.Rows.Add(rowC); int num = 0; for (int i = 0; i < dataGridView1.RowCount; i++) { if (i > 0) { weekNum = 0; } for (int j = weekNum; j < dataGridView1.ColumnCount; j++) { num++; if (num > monthDayCount) { break; } DateCell dc = new DateCell(); dc.ColIndex = weekNum; dc.RowIndex = i; dc.Year = dateTimePicker1.Value.Year; dc.Month = dateTimePicker1.Value.Month; dc.Day = num; if (CurrentSensor != null && CurrentSensor.AlarmDic.ContainsKey(dc.YYYYMMDD)) { dc.AS = CurrentSensor.AlarmDic[dc.YYYYMMDD]; } dataGridView1.Rows[i].Cells[j].Value = dc; if (num == DateTime.Now.Day && dateTimePicker1.Value.Month == DateTime.Now.Month && dateTimePicker1.Value.Year == DateTime.Now.Year) { dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.LightSkyBlue; } } } dataGridView1.CurrentCell = null; }