示例#1
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            SCIndexData obj = new SCIndexData();

            obj.OID        = newOid--;
            obj.IndexMonth = 0;
            obj.IndexYear  = 0;
            obj.IndexValue = 0;

            dataTable = (DataTable)gridData.DataSource;
            if (dataTable == null || dataTable.Rows.Count <= 0)
            {
                dataTable = ObjectUtils.ConvertToDataTable(new List <SCIndexData> {
                    obj
                });
                gridData.DataSource = dataTable;
            }
            else
            {
                DataRow drToAdd = dataTable.NewRow();
                drToAdd[Constant.OID] = obj.OID;
                drToAdd["IndexYear"]  = obj.IndexYear;
                drToAdd["IndexMonth"] = obj.IndexMonth;
                drToAdd["IndexValue"] = obj.IndexValue;
                dataTable.Rows.Add(drToAdd);
                dataTable.AcceptChanges();
            }

            gridData.Refresh();
        }
示例#2
0
        private void gridData_CellValidated(object sender, DataGridViewCellEventArgs e)
        {
            //Validated
            SCIndexData sCIndexData = convertToIndexData(gridData.Rows[e.RowIndex]);

            if (sCIndexData.OID > 0)
            {
                if (sCIndexData.isDelete)
                {
                    listDataChange.Add(sCIndexData);
                }
                else
                {
                    SCIndexData finder = listData.Find(x => x.OID == sCIndexData.OID);
                    //Kiem tra thay doi so voi db
                    if (finder != null && (finder.IndexYear != sCIndexData.IndexYear ||
                                           finder.IndexMonth != sCIndexData.IndexMonth ||
                                           finder.IndexValue != sCIndexData.IndexValue))
                    {
                        sCIndexData.isUpdate = true;

                        //Duyet list change de them hoac update data
                        SCIndexData finderChange = listDataChange.Find(x => x.OID == sCIndexData.OID);
                        if (finderChange == null)
                        {
                            listDataChange.Add(sCIndexData);
                        }
                        else
                        {
                            //Update
                            finderChange.IndexYear  = sCIndexData.IndexYear;
                            finderChange.IndexMonth = sCIndexData.IndexMonth;
                            finderChange.IndexValue = sCIndexData.IndexValue;
                        }
                    }
                }
            }
            else
            {
                sCIndexData.isInsert = true;
                SCIndexData finder = listDataChange.Find(x => x.OID == sCIndexData.OID);
                if (finder == null)
                {
                    listDataChange.Add(sCIndexData);
                }
                else
                {
                    finder.IndexYear  = sCIndexData.IndexYear;
                    finder.IndexMonth = sCIndexData.IndexMonth;
                    finder.IndexValue = sCIndexData.IndexValue;
                }
            }
        }
示例#3
0
 private void loadData()
 {
     newOid              = -1;
     listDataChange      = new List <SCIndexData>();
     gridData.DataSource = null;
     listData            = SCIndexData.getIndexData();
     if (listData == null)
     {
         listData = new List <SCIndexData>();
     }
     dataTable           = ObjectUtils.ConvertToDataTable(listData);
     gridData.DataSource = dataTable;
 }
示例#4
0
        private void dtIndexingDate_ValueChanged(object sender, EventArgs e)
        {
            DateTime    dt        = dtIndexingDate.Value;
            SCIndexData indexData = SCIndexData.getIndexData(dt);

            if (indexData != null)
            {
                dfIndexValue.Value = indexData.IndexValue;
            }
            else
            {
                dfIndexValue.Value = 0;
            }
        }
示例#5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int selectedRow = gridData.SelectedRows.Count;

            if (selectedRow > 0)
            {
                foreach (DataGridViewRow r in gridData.SelectedRows)
                {
                    SCIndexData obj = new SCIndexData();
                    obj.OID      = Int32.Parse(r.Cells[0].Value.ToString());
                    obj.isDelete = true;

                    //Add list delete
                    SCIndexData finder = listDataChange.Find(x => x.OID == obj.OID);
                    if (finder == null)
                    {
                        listDataChange.Add(obj);
                    }
                    else
                    {
                        finder.isDelete = true;
                    }

                    if (obj.OID > 0)
                    {
                        listData.RemoveAll(x => x.OID == obj.OID);
                    }

                    r.Cells["isDelete"].Value = true;
                    //Mark as delete with SCIndexData in db
                    ViewUtils.remarkHeader(r, "isDelete");

                    //if (obj.OID > 0)
                    //{
                    //    r.Cells["isDelete"].Value = true;
                    //    //Mark as delete with SCIndexData in db
                    //    ViewUtils.remarkHeader(r, "isDelete");
                    //}
                    //else
                    //{
                    //    //Delete from datatable with SCIndexData add new
                    //    dataTable.Rows.RemoveAt(r.Index);
                    //    dataTable.AcceptChanges();
                    //}
                }
            }
        }
示例#6
0
        private SCIndexData convertToIndexData(DataGridViewRow row)
        {
            SCIndexData obj = new SCIndexData();

            obj.OID = (int)row.Cells[0].Value;
            if (row.Cells[1].Value != null)
            {
                int year = 0;
                if (Int32.TryParse(row.Cells[1].Value.ToString(), out year))
                {
                    obj.IndexYear = year;
                }
                else
                {
                    obj.IndexYear = 0;
                }
            }
            if (row.Cells[2].Value != null)
            {
                int month = 0;
                if (Int32.TryParse(row.Cells[2].Value.ToString(), out month))
                {
                    obj.IndexMonth = month;
                }
                else
                {
                    obj.IndexMonth = 0;
                }
            }
            if (row.Cells[3].Value != null)
            {
                decimal value = 0;
                if (Decimal.TryParse(row.Cells[3].Value.ToString(), NumberStyles.Any, new CultureInfo(objGlobal.CultureInfo), out value))
                {
                    obj.IndexValue = value;
                }
                else
                {
                    obj.IndexValue = 0;
                }
            }
            return(obj);
        }
示例#7
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     SCIndexData.save(listDataChange);
     //Reload data
     loadData();
 }