Copy() public method

public Copy ( ) : DataTable
return DataTable
        private void InitialOriginTable(DataTable dt)
        {
            originalTable = dt.Copy();

            originalTable.Columns.Add("PassengerName");
            originalTable.Columns["PassengerName"].SetOrdinal(0);

            originalTable.Columns.Add("FlightInfo");
            originalTable.Columns["FlightInfo"].SetOrdinal(1);

            originalTable.Columns.Add("StaffName");
            //originalTable.Columns["StaffName"].SetOrdinal(2);

            foreach (DataRow row in originalTable.Rows)
            {
                Guid passengerID = Guid.Parse(row["PassengerID"].ToString());
                Passenger passenger = reservationSystem.GetPassengerByID(passengerID);
                string passengerName = passenger.firstName + " " + passenger.lastName;
                row["PassengerName"] = passengerName;

                Guid staffID = Guid.Parse(row["StaffID"].ToString());
                Staff staff = reservationSystem.GetStaffByID(staffID);
                string staffName = staff.firstName + " " + staff.lastName;
                row["StaffName"] = staffName;

                Guid flightID = Guid.Parse(row["FlightID"].ToString());
                Flight flight = reservationSystem.GetFlightByID(flightID);
                string flightInfo = flight.origin.name + " - " + flight.destination.name;
                row["FlightInfo"] = flightInfo;
            }
        }
        /// <summary>
        /// Sorts the <see cref="System.Data.DataTable"/>.
        /// </summary>
        /// <param name="sourceTable">The source table.</param>
        /// <param name="sortColumn">The column to sort by.</param>
        /// <param name="order">The <see cref="Tools.Common.SortOrder"/>.</param>
        /// <param name="copyIfNoSort">Should only be true when one table owner is assumed
        /// other time and space.</param>
        /// <returns></returns>
        public static DataTable SortDataTable(DataTable sourceTable, string sortColumn, SortOrder order, bool copyIfNoSort)
        {
            if (String.IsNullOrEmpty(sortColumn))
            {
                // copyIfNoSort make the semantic more stable, even if there is no sort required
                // the copy is returned, so the caller may assume same level of independence.
                if (copyIfNoSort) return sourceTable.Copy();
                return sourceTable;
            }

            DataTable targetTable = sourceTable.Clone();

            DataRow[] sourceRows = sourceTable.Select(null, 
                ("[" + sortColumn + "] " + order.ToString()).TrimEnd(' '));

            for (int i = 0; i < sourceRows.Length; i++)
            {
                DataRow newRow = targetTable.NewRow();

                newRow.ItemArray = sourceRows[i].ItemArray;

                targetTable.Rows.Add(newRow);
            }
            return targetTable;
        }
        public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)
        {
            if (PageIndex == 0)
                return dt;
            DataTable newdt = dt.Copy();
            newdt.Clear();

            int rowbegin = (PageIndex - 1) * PageSize;
            int rowend = PageIndex * PageSize;

            if (rowbegin >= dt.Rows.Count)
                return newdt;

            if (rowend > dt.Rows.Count)
                rowend = dt.Rows.Count;
            for (int i = rowbegin; i <= rowend - 1; i++)
            {
                DataRow newdr = newdt.NewRow();
                DataRow dr = dt.Rows[i];
                foreach (DataColumn column in dt.Columns)
                {
                    newdr[column.ColumnName] = dr[column.ColumnName];
                }
                newdt.Rows.Add(newdr);
            }

            return newdt;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            GridView grid = new GridView();
            DataTable dt = new DataTable();
            List<Terceiro> lista = new List<Terceiro>();
            TerceiroBL tbl = new TerceiroBL();
            lista = tbl.buscaTerceiros(Convert.ToInt16(Session["empresa"].ToString()));

            DataColumn c1 = new DataColumn("Cnpj", Type.GetType("System.String"));
            DataColumn c2 = new DataColumn("Nome", Type.GetType("System.String"));
            DataColumn c3 = new DataColumn("Email", Type.GetType("System.String"));
            DataColumn c4 = new DataColumn("Telefone", Type.GetType("System.String"));
            DataColumn c5 = new DataColumn("editar", Type.GetType("System.String"));

            dt.Columns.Add(c1);
            dt.Columns.Add(c2);
            dt.Columns.Add(c3);
            dt.Columns.Add(c4);
            dt.Columns.Add(c5);

            foreach (Terceiro t in lista)
            {
                DataRow dr = dt.NewRow();
                dr["Cnpj"] = t.cpfCnpj.ToString();
                dr["Nome"] = t.nome.ToString();
                dr["Email"] = t.email.ToString();
                dr["Telefone"] = t.telefone.ToString();
                dr["editar"] = "~/EditaTerceiro.aspx?id_terceiro=" + t.id.ToString();
                dt.Rows.Add(dr);
            }
            gridTerceiros.DataSource = dt.Copy();
            gridTerceiros.DataBind();
        }
Example #5
0
 /// <summary>
 /// Saves a copy of the ProxyTable in the application settings
 /// </summary>
 /// <param name="proxyTable">DataTable to save</param>
 public static void saveConfig(DataTable proxyTable)
 {
     DataTable copyTable = proxyTable.Copy();
     SwitchProxy.Properties.Settings.Default.ProxyTable = null;
     SwitchProxy.Properties.Settings.Default.ProxyTable = copyTable;
     SwitchProxy.Properties.Settings.Default.Save();
 }
Example #6
0
 //////////////////////////////////////////MySQL
 public void NW_Dhcp_Customer_Getlist_MySQL()
 {
     string sql = "Select * from NW_Dhcp_Customer";
     dt = Class.MySqlConnect.ExecQuery(sql);
     gridItem.DataSource = dt;
     dtIpPublic = dt.Copy();
 }
Example #7
0
        public void SerializePart( DataTable data )
        {
            // TODO: ТОЛЬКО ДЛЯ ТЕСТИРОВАНИЯ. УБРАТЬ!
            // data.TableName += Guid.NewGuid().ToString();

            ResultDataSet.Tables.Add( data.Copy() );
        }
 public static DataTable getTopCategoryTotals(DataTable inputTable, int topRowsCount)
 {
     DataTable table = inputTable.Copy();
     table.Clear();
     double otherTotal = 0;
     try
     {
         for (int i = 0; i < inputTable.Rows.Count; i++)
         {
             if (i > topRowsCount - 1)
             {
                 otherTotal = otherTotal + double.Parse(inputTable.Rows[i]["total"].ToString());
             }
             else
             {
                 table.Rows.Add(inputTable.Rows[i][0], inputTable.Rows[i][1]);
             }
         }
         if (inputTable.Rows.Count>5)
         {
             table.Rows.Add("Other", otherTotal);
         }
     }
     catch (Exception exception)
     {
         Logger.LogException(exception);
         Helper.showMessage("Unable to trim top category totals from database. \n\n " + exception.ToString());
     }
     return table;
 }
Example #9
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridView1.Columns[e.ColumnIndex].Name  == "exe")
     {//打开文件
        openFileDialog1.ShowDialog();
        dataGridView1.CurrentCell.Value = openFileDialog1.FileName;
     }
     else if (dataGridView1.Columns[e.ColumnIndex].Name == "ok")
     {//保存文件
         DataTable _dt = new DataTable();
         _dt.Columns.Add("exe");
         _dt.Columns.Add("message");
         _dt.Columns.Add("rule");
         foreach (DataGridViewRow var in dataGridView1.Rows)
         {
             if (var.Cells[1].Value == null)
             {
                 continue;
             }
             _dt.Rows.Add(var.Cells["exe"].Value.ToString(), var.Cells["message"].Value.ToString() == null ? "*" : var.Cells["message"].Value.ToString(), var.Cells["rule"].Value.ToString() == null ? "1" : var.Cells["rule"].Value.ToString());
         }
         DataSet _ds = new DataSet();
         _ds.Tables.Add(_dt.Copy());
         SaveData(_ds);
     }
 }
Example #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tbl"></param>
        public void AddGRAlarm(DataTable tbl)
        {
            DataTable s = this.dataGridView1.DataSource as DataTable;
            if (s == null)
            {
                s = tbl.Copy();
                this.dataGridView1.DataSource = s;
            }
            else
            {
                s.Merge(tbl);
            }

            if (dataGridView1.Rows.Count > 0)
            {
                // remove records
                //
                if (dataGridView1.Rows.Count > Config.Default.GRAlarmMaxCount)
                {
                    int n = dataGridView1.Rows.Count - Config.Default.GRAlarmMaxCount;
                    for (int i = 0; i < n; i++)
                    {
                        dataGridView1.Rows.RemoveAt(0);
                        //s.Rows[0].Delete();
                    }
                }

                // move to last record
                //
                DataGridViewCell lastCell = this.dataGridView1[0, this.dataGridView1.Rows.Count - 1];
                this.dataGridView1.CurrentCell = lastCell;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            GridView grid = new GridView();
            DataTable dt = new DataTable();
            List<Usuario> lista = new List<Usuario>();
            UsuarioBL uBL = new UsuarioBL();
            lista = uBL.buscaUsuariosEmpresa(Convert.ToInt16(Session["empresa"].ToString()));

            DataColumn c1 = new DataColumn("Email", Type.GetType("System.String"));
            DataColumn c2 = new DataColumn("Nome", Type.GetType("System.String"));
            DataColumn c3 = new DataColumn("Empresa", Type.GetType("System.String"));
            DataColumn c4 = new DataColumn("Licença", Type.GetType("System.String"));
            DataColumn c5 = new DataColumn("editar", Type.GetType("System.String"));

            dt.Columns.Add(c1);
            dt.Columns.Add(c2);
            dt.Columns.Add(c3);
            dt.Columns.Add(c4);
            dt.Columns.Add(c5);

            foreach (Usuario u in lista)
            {
                DataRow dr = dt.NewRow();
                dr["Email"] = u.email.ToString();
                dr["Nome"] = u.nome.ToString();
                dr["Empresa"] = u.idEmpresa.ToString();
                dr["Licença"] = u.dataFimLicenca.ToShortDateString();
                dr["editar"] = "~/EditarUsuario.aspx?user_mail=" + u.email.ToString();
                dt.Rows.Add(dr);
            }
            gridUsuarios.DataSource = dt.Copy();
            gridUsuarios.DataBind();
        }
        public void alimentagrid()
        {
            GridView grid = new GridView();
            DataTable dt = new DataTable();
            List<Etapa> lista = new List<Etapa>();
            EtapaBL ebl = new EtapaBL();

            lista = ebl.buscaEtapas();

            DataColumn c1 = new DataColumn("id", Type.GetType("System.String"));
            DataColumn c2 = new DataColumn("nome", Type.GetType("System.String"));
            DataColumn c3 = new DataColumn("editar", Type.GetType("System.String"));

            dt.Columns.Add(c1);
            dt.Columns.Add(c2);
            dt.Columns.Add(c3);

            foreach (Etapa e in lista)
            {
                DataRow dr = dt.NewRow();
                dr["id"] = e.id.ToString();
                dr["nome"] = e.tituloEtapa.ToString();
                dr["editar"] = "~/EditaEtapa.aspx?id_etapa=" + e.id.ToString();
                dt.Rows.Add(dr);
            }
            griEtapas.DataSource = dt.Copy();
            griEtapas.DataBind();
        }
        public void carregaTabela()
        {
            GridView grid = new GridView();
            DataTable dt = new DataTable();
            List<ItemTarefa> lista = new List<ItemTarefa>();
            TarefaBL tbl = new TarefaBL();
            lista = tbl.buscaItensTarefa(idTarefa);
            DataColumn c1 = new DataColumn("data", Type.GetType("System.String"));
            DataColumn c2 = new DataColumn("descricao", Type.GetType("System.String"));
            DataColumn c3 = new DataColumn("excluir", Type.GetType("System.String"));
            dt.Columns.Add(c1);
            dt.Columns.Add(c2);
            dt.Columns.Add(c3);

            foreach (ItemTarefa t in lista)
            {
                EtapaBL ebl = new EtapaBL();
                DataRow dr = dt.NewRow();
                dr["data"] = t.data.ToString();
                dr["descricao"] = t.descricao.ToString();
                dr["excluir"] = "ExcluirItemTarefa.aspx?id_item=" + t.id.ToString();
                dt.Rows.Add(dr);
            }
            gridItens.DataSource = dt.Copy();
            gridItens.DataBind();
        }
Example #14
0
        /// <summary>
        /// 取得 VDS_CRM_ORDER_MAIN && VDS_CRM_ORDER_DETL 的 Data
        /// </summary>
        /// <param name="ParameterList"></param>
        /// <returns>回傳查詢結果</returns>
        public DataSet QUERY_CRM041_MAIN_AND_DETL(ArrayList ParameterList)
        {
            try
            {
                DataSet ds_Return = new DataSet();
                DataTable dt_Return_Main = new DataTable();
                DataTable dt_Return_Detl = new DataTable();

                DBO.VDS_CRM_ORDER_MAINDBO VCOM = new VDS_CRM_ORDER_MAINDBO(ref USEDB);
                DBO.VDS_CRM_ORDER_DETLDBO VCOD = new VDS_CRM_ORDER_DETLDBO(ref USEDB);

                dt_Return_Main = VCOM.QUERY_CRM041_MAIN(ParameterList);
                dt_Return_Main.TableName = "VDS_CRM_ORDER_MAIN";

                dt_Return_Detl = VCOD.QUERY_CRM041_DETL(ParameterList);
                dt_Return_Detl.TableName = "VDS_CRM_ORDER_DETL";

                ds_Return.Tables.Add(dt_Return_Main.Copy());
                ds_Return.Tables.Add(dt_Return_Detl.Copy());

                dt_Return_Main.Clear();
                dt_Return_Detl.Clear();
                dt_Return_Main.Dispose();
                dt_Return_Detl.Dispose();

                return ds_Return;

            }
            catch (Exception ex)
            { throw GetNewException(ex); }
        }
 public DataTable ConvertEMeterTransaction(DataTable _dt, int adcID)
 {
     DataTable dt = _dt.Copy();
     //
     string sID = "device_adc_id";
     string sDate = "e_datetime";
     //
     if (!dt.Columns.Contains(sID))
         dt.Columns.Add(new DataColumn(sID, typeof(int), "'" + adcID + "'"));
     //
     if (!dt.Columns.Contains(sDate))
         dt.Columns.Add(new DataColumn(sDate, typeof(DateTime),
             "Convert(E_Date + ' ' + E_Time, 'System.DateTime')"));
     //
     string sConnection = "e_connection";
     if (!dt.Columns.Contains(sConnection))
         dt.Columns.Add(new DataColumn(sConnection, typeof(int),
             "Convert(IIF(E_CommStatus like '%complete',1,0), 'System.Int16')"));
     //
     foreach (DataRow r in dt.Rows)
     {
         foreach(DataColumn c in dt.Columns)
             if(r[c.ColumnName].ToString().Contains("null"))
                 r[c.ColumnName] = "0";
     }
     dt.AcceptChanges();
     //
     return dt;
 }
Example #16
0
 DataTable IConsulta.CarregaDadosMae(string idUnit)
 {
     DataTable table2;
     StringBuilder builder = new StringBuilder();
     DataTable table = new DataTable();
     try
     {
         builder.Length = 0;
         builder.AppendLine("EXECUTE INTOUCH.DBO.[BIINTOUCH.CARREGAINFORMACOES_MAE] ");
         builder.AppendLine("@ID_UNIT = '" + idUnit + "' ");
         table = DbIntouch.ExecuteDataTable(builder.ToString());
         table2 = table.Copy();
     }
     catch
     {
         table2 = null;
     }
     finally
     {
         if (table != null)
         {
             table.Dispose();
         }
     }
     return table2;
 }
        public void DarFormatoGrillas()
        {
            DataTable oDTIzq = new DataTable("Datos");

            oDTIzq.Columns.Add("-250-");
            oDTIzq.Columns.Add("-500-");
            oDTIzq.Columns.Add("-1K-");
            oDTIzq.Columns.Add("-2K-");
            oDTIzq.Columns.Add("-4K-");

            DataRow oDR = oDTIzq.NewRow();
            DataRow oDR2 = oDTIzq.NewRow();
            oDTIzq.Rows.Add(oDR);
            oDTIzq.Rows.Add(oDR2);

            DataTable oDTDer = oDTIzq.Copy();

            dgvTablaReflejosIzq.DataSource = oDTIzq;
            dgvTablaReflejosDer.DataSource = oDTDer;

            DeterminarAnchoColumnas();

            //String strDT = Mds.Architecture.HelpersFunctions.SerializationFunctions.Serialize(oDT);
            //DataTable kk = (DataTable)Mds.Architecture.HelpersFunctions.SerializationFunctions.DeserializeFromXml(typeof(DataTable), strDT);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            GridView grid = new GridView();
            DataTable dt = new DataTable();
            List<Mensagem> lista = new List<Mensagem>();
            MensagemBL mbl = new MensagemBL();
            UsuarioBL ubl = new UsuarioBL();

            lista = mbl.buscaMensagensusuario(Session["email"].ToString());

            DataColumn c1 = new DataColumn("data", Type.GetType("System.String"));
            DataColumn c2 = new DataColumn("remetente", Type.GetType("System.String"));
            DataColumn c3 = new DataColumn("nome", Type.GetType("System.String"));
            DataColumn c4 = new DataColumn("abrir", Type.GetType("System.String"));

            dt.Columns.Add(c1);
            dt.Columns.Add(c2);
            dt.Columns.Add(c3);
            dt.Columns.Add(c4);

            foreach (Mensagem m in lista)
            {
                DataRow dr = dt.NewRow();
                dr["data"] = m.data.ToShortDateString();
                dr["remetente"] = m.remetente.ToString();
                dr["nome"] = ubl.buscaNome(m.remetente.ToString());
                dr["abrir"] = "~/LerMensagem.aspx?id_mensagem=" + m.id.ToString();
                dt.Rows.Add(dr);
            }
            gridMensagens.DataSource = dt.Copy();
            gridMensagens.DataBind();
        }
 private void btnBUSCAR_Click(object sender, EventArgs e)
 {
     if (rdbDETALLE.Checked)
     {
         //BUSCAR POR ARTICULO
         if (cbxSUCURSAL.SelectedIndex >= 0 && cbxCATEGORIA.SelectedIndex >= 0)
         {
             INVENTARIO = dbInventario.CUSTODIA_PRENDASAL((string)cbxSUCURSAL.SelectedValue, (string)cbxCATEGORIA.SelectedValue, (string)cbxARTICULO.SelectedValue);
             tblINVENTARIO.DataSource = INVENTARIO.Copy();
             System.Media.SystemSounds.Exclamation.Play();
         }
     }
     else
     {
         //BUSCAR POR CODIGO
         if (txtCODIGO.Text.Trim() != string.Empty)
         {
             INVENTARIO = dbInventario.CUSTODIA_BY_CODIGO_PRENDASAL(txtCODIGO.Text.Trim());
             tblINVENTARIO.DataSource = INVENTARIO.Copy();
             System.Media.SystemSounds.Exclamation.Play();
         }
         else
         {
             MessageBox.Show("INGRESE CODIGO DE ARTICULOS A BUSCAR", "VALIDACION DE DATOS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
 }
Example #20
0
        // Function  : ExportDetails
        // Arguments : DetailsTable, FormatType, FileName
        // Purpose	 : To get all the column headers in the datatable and
        //               exorts in CSV / Excel format with all columns
        public void ExportDetails(DataTable DetailsTable, ExportFormat FormatType, string FileName)
        {
            try
            {
                if (DetailsTable.Rows.Count == 0)
                    throw new Exception("There are no details to export.");

                // Create Dataset
                DataSet dsExport = new DataSet("Export");
                DataTable dtExport = DetailsTable.Copy();
                dtExport.TableName = "Values";
                dsExport.Tables.Add(dtExport);

                // Getting Field Names
                string[] sHeaders = new string[dtExport.Columns.Count];
                string[] sFileds = new string[dtExport.Columns.Count];

                for (int i = 0; i < dtExport.Columns.Count; i++)
                {
                    //sHeaders[i] = ReplaceSpclChars(dtExport.Columns[i].ColumnName);
                    sHeaders[i] = dtExport.Columns[i].ColumnName;
                    sFileds[i] = ReplaceSpclChars(dtExport.Columns[i].ColumnName);
                }

                if (appType == "Web")
                    Export_with_XSLT_Web(dsExport, sHeaders, sFileds, FormatType, FileName);
                else if (appType == "Win")
                    Export_with_XSLT_Windows(dsExport, sHeaders, sFileds, FormatType, FileName);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
Example #21
0
 private void delete_Click(object sender, EventArgs e)
 {
     if(meeting_dg.Rows.Count==0) return ;
     int current_index= meeting_dg.CurrentRow.Index;
     object obj = meeting_dg.Rows[current_index].Cells[0].Value;
     string meetingname = Convert.ToString(obj);
     try
     {
         mainform.db.update("delete from dbo.meeting where meetingname='" + meetingname + "'");
         DataTable temp = new DataTable();
         temp =(DataTable) meeting_dg.DataSource;
         DataTable temp2 = new DataTable();
         temp2 = temp.Copy();
         temp2.Clear();
         for (int i = 0; i < temp.Rows.Count; i++)
         {
            string  tempname=Convert.ToString(temp.Rows[i].ItemArray[0]);
             if(tempname!=meetingname)
             {
                 temp2.Rows.Add(temp.Rows[i].ItemArray);
             }
         }
         meeting_dg.DataSource =temp2;
     }
     catch (Exception ee)
     {
         MessageBox.Show(ee.Message);
     }
 }
Example #22
0
        public Fuzzification(List<Description> descriptions, DataTable data)
        {
            m_Descriptions = descriptions;
            m_Data = data;
            result = new Dictionary<string, List<ValueItem>>();

            m_ResultData = m_Data.Copy();
        }
Example #23
0
        public Position(List<string> fullTickerList)
        {
            FullTickerList = fullTickerList;
            PositionWithFilledOrders = new DataTable();
            PositionWithFilledOrders.Columns.Add("FullTicker", typeof(string));
            PositionWithFilledOrders.Columns.Add("Qty", typeof(double));

            for (int i = 0; i < FullTickerList.Count; i++)
            {
               PositionWithFilledOrders.Rows.Add();
               PositionWithFilledOrders.Rows[i]["FullTicker"] = FullTickerList[i];
               PositionWithFilledOrders.Rows[i]["Qty"] = 0;
            }

            PositionWithWorkingOrders = PositionWithFilledOrders.Copy();
            PositionWithAllOrders = PositionWithFilledOrders.Copy();
        }
 public frmReport_The_kho(DataTable ct_tk, string ma_vt, string ten_vt, string dvt)
 {
     InitializeComponent();
     this.ct_thekho = ct_tk.Copy();
     this.ma_vt = ma_vt;
     this.ten_vt = ten_vt;
     this.dvt = dvt;
 }
Example #25
0
 public void AddResults(DataTable dt)
 {
     _results = dt.Copy();
     //foreach(DataRow dr in dt.Rows)
     //{
     //    _results.ImportRow(dr);
     //}
 }
Example #26
0
 public ServicosEstadia(DataTable t)
 {
     _tabela = new DataTable();
     _tabela = t.Copy();
     _tabela.PrimaryKey = null;
     _tabela.Columns.Remove("id");
     _tabela.Columns.Remove("data");
 }
Example #27
0
        public ReportForm(DataTable reportData, string crystalReportFilePath)
        {
            InitializeComponent();

            // Make a copy of the data to be provided to the Crystal Report...
            _reportSourceTable = reportData.Copy();
            _crystalReportFilePath = crystalReportFilePath;
        }
        public static DataTable Calculate(DataTable source, DataTable template, string formulaColumn, string[] calculateColumns)
        {
            //构造目的表
            DataTable result = template.Copy();
            foreach (string item in calculateColumns)
            {
                DataColumn column = new DataColumn(item, source.Columns[item].DataType);
                result.Columns.Add(column);
            }
            //END

            foreach (DataRow dr in result.Rows)
            {
                //公式
                string formula = dr[formulaColumn].ToString().Trim();
                //拆分公式 variableList中存储各个因式
                IEnumerable<string> factorList = Regex.Split(formula, @"[+\-*/()]+")
                                                .Except((IEnumerable<string>)new string[] { "" })
                                                .Select(p => p = Regex.Replace(p, @"^([0-9]+)([\.]([0-9]+))?$", ""))
                                                .Except((IEnumerable<string>)new string[] { "" });
                //m_dictionary存储各个因式及其对应的行记录
                IDictionary<string, DataRow> m_dictionary = new Dictionary<string, DataRow>();
                foreach (string item in factorList)
                {
                    //因式(factor)
                    string factor = item.TrimStart('[').TrimEnd(']');
                    DataRow[] rows = source.Select("VariableId='" + factor + "'");
                    if (1 == rows.Count())
                    {
                        m_dictionary.Add(factor, rows[0]);
                    }
                    else if (0 == rows.Count())
                    {
                        m_dictionary.Add(factor, source.NewRow());//没有找到则添加一个空行
                    }
                    else
                    {
                        throw new Exception(item + "对应" + rows.Count() + "条数据!");
                    }
                }

                ///item当前要计算的列名
                foreach (string item in calculateColumns)
                {
                    try
                    {
                        string tempFormulaValue = formula;
                        foreach (string node in m_dictionary.Keys.ToArray())
                        {
                            tempFormulaValue = tempFormulaValue.Replace("[" + node + "]", m_dictionary[node][item].ToString());
                        }
                        dr[item] = Convert.ToDecimal(source.Compute(tempFormulaValue, "true"));
                    }
                    catch { dr[item] = 0; };
                }
            }
            return result;
        }
        public void Combos()
        {
            var dt = new DataTable();

            cboLunes.DataSource = dt.Copy();
            cboLunes.ValueMember = "CODIGO";
            cboLunes.DisplayMember = "DESCRIPCION";

            cboMartes.DataSource = dt.Copy();
            cboMartes.ValueMember = "CODIGO";
            cboMartes.DisplayMember = "DESCRIPCION";

            cboMiercoles.DataSource = dt.Copy();
            cboMiercoles.ValueMember = "CODIGO";
            cboMiercoles.DisplayMember = "DESCRIPCION";

            cboJueves.DataSource = dt.Copy();
            cboJueves.ValueMember = "CODIGO";
            cboJueves.DisplayMember = "DESCRIPCION";

            cboViernes.DataSource = dt.Copy();
            cboViernes.ValueMember = "CODIGO";
            cboViernes.DisplayMember = "DESCRIPCION";

            cboSabado.DataSource = dt.Copy();
            cboSabado.ValueMember = "CODIGO";
            cboSabado.DisplayMember = "DESCRIPCION";

            cboDomingo.DataSource = dt.Copy();
            cboDomingo.ValueMember = "CODIGO";
            cboDomingo.DisplayMember = "DESCRIPCION";
        }
Example #30
0
        public static DataTable getDifferentRecords(DataTable FirstDataTable, DataTable SecondDataTable)
        {
            FirstDataTable = FirstDataTable.Copy();
            FirstDataTable.TableName += " First";
            SecondDataTable = SecondDataTable.Copy();
            SecondDataTable.TableName += " Second";
            //Create Empty Table
            DataTable ResultDataTable = new DataTable("ResultDataTable");

            //use a Dataset to make use of a DataRelation object
            using (DataSet ds = new DataSet())
            {

                //Add tables
                ds.Tables.AddRange(new DataTable[] { FirstDataTable, SecondDataTable });

                //Get Columns for DataRelation
                DataColumn[] firstColumns = FirstDataTable.Columns.Cast<DataColumn>().ToArray();

                DataColumn[] secondColumns = SecondDataTable.Columns.Cast<DataColumn>().ToArray();

                //Create DataRelation
                DataRelation r1 = new DataRelation(string.Empty, firstColumns, secondColumns, false);
                ds.Relations.Add(r1);

                //DataRelation r2 = new DataRelation(string.Empty, secondColumns, firstColumns, false);
                //ds.Relations.Add(r2);

                //Create columns for return table
                List<DataColumn> PK = new List<DataColumn>();
                for (int i = 0; i < FirstDataTable.Columns.Count; i++)
                {
                    DataColumn newdc = ResultDataTable.Columns.Add(FirstDataTable.Columns[i].ColumnName, FirstDataTable.Columns[i].DataType);
                    if (FirstDataTable.PrimaryKey.Contains(FirstDataTable.Columns[i]))
                        PK.Add(newdc);
                }
                ResultDataTable.PrimaryKey = PK.ToArray();
                //If FirstDataTable Row not in SecondDataTable, Add to ResultDataTable.
                ResultDataTable.BeginLoadData();
                foreach (DataRow parentrow in FirstDataTable.Rows)
                {
                    DataRow[] childrows = parentrow.GetChildRows(r1);
                    if (childrows == null || childrows.Length == 0)
                        ResultDataTable.LoadDataRow(parentrow.ItemArray, true);
                }

                ////If SecondDataTable Row not in FirstDataTable, Add to ResultDataTable.
                //foreach (DataRow parentrow in SecondDataTable.Rows)
                //{
                //    DataRow[] childrows = parentrow.GetChildRows(r2);
                //    if (childrows == null || childrows.Length == 0)
                //        ResultDataTable.LoadDataRow(parentrow.ItemArray, true);
                //}
                ResultDataTable.EndLoadData();
            }
            return ResultDataTable;
        }