private bool IntiRow(DataRow row) { string pid = tbId.Text.Trim(); string innerid = tbInnerId.Text.Trim(); string size = tbSize.Text.Trim(); string colornum = tbColorNum.Text.Trim(); string name = tbName.Text.Trim(); string pos = tbPosition.Text.Trim(); decimal price = nudPrice.Value; decimal cost = nudCost.Value; decimal store = nudStore.Value; decimal pkgnum = nudPkgNum.Value; if (String.IsNullOrEmpty(innerid)) { MessageBox.Show("编号不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } row.SetField<string>("productid", pid); row.SetField<string>("innerid", innerid); row.SetField<string>("size", size); row.SetField<string>("colornum", colornum); row.SetField<string>("name", name); row.SetField<string>("position", pos); row.SetField<decimal>("price", price); row.SetField<decimal>("cost", cost); row.SetField<decimal>("storenum", store); row.SetField<decimal>("packagenum", pkgnum); row.SetField<string>("opr", GlobalVar.LogInfo.Name); return true; }
private void btnAddSou_Click(object sender, EventArgs e) { int ixh = GetMaxXH() + 1; DataTable dt = this.treePosPair.DataSource as DataTable; System.Data.DataRow row = dt.NewRow(); row.SetField("I_XH", ixh); row.SetField("WKID", this._wkid); dt.Rows.Add(row); this.treePosPair.DataSource = dt; this.treePosPair.RefreshDataSource(); }
private void button1_Click(object sender, System.EventArgs e) { DataTable gridDataTable = this.sfDataGrid.DataSource as DataTable; if (gridDataTable == null || this.sfDataGrid.View == null) { return; } // Creates a new row. System.Data.DataRow addNewRow = sfDataGrid.View.AddNew() as System.Data.DataRow; // Commits the newly created row. sfDataGrid.View.CommitNew(); // Initialize the values of first row to the newly added row. addNewRow.SetField(0, gridDataTable.Rows[0][0]); addNewRow.SetField(1, gridDataTable.Rows[0][1]); addNewRow.SetField(2, gridDataTable.Rows[0][2]); addNewRow.SetField(3, gridDataTable.Rows[0][3]); addNewRow.SetField(4, gridDataTable.Rows[0][4]); }
//function adding data to sql table public void SqlTableAdd() { System.Data.DataRow[] foundRows; String Strtofind; if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "" || textBox8.Text == "" || textBox9.Text == "" || textBox10.Text == "" || textBox11.Text == "" || textBox12.Text == "" || textBox13.Text == "" || textBox14.Text == "" || textBox17.Text == "") { System.Windows.Forms.MessageBox.Show("Incomplete Information, Try Again !!"); return; } Strtofind = "PartnerID =" + textBox1.Text; foundRows = ds.Tables["AwarObjSqlTable"].Select(Strtofind); if (foundRows.Length == 0) { //its a new record, we should be able to add System.Data.DataRow NewRow = ds.Tables["AwarObjSqlTable"].NewRow(); //Next line is needed so we can update the database System.Data.OleDb.OleDbCommandBuilder Cb = new System.Data.OleDb.OleDbCommandBuilder(da); //NewRow.SetField<int>("PartnerID", Convert.ToInt32(textBox1.Text)); //NewRow.SetField<String>("PartnetType", textBox2.Text); //NewRow.SetField<String>("Name", textBox3.Text); //NewRow.SetField<String>("Phone", textBox4.Text); //NewRow.SetField<String>("AlternativePhone", textBox5.Text); //NewRow.SetField<String>("FaxNumber", textBox6.Text); //NewRow.SetField<String>("Email", textBox7.Text); //NewRow.SetField<String>("AlternativeEmail", textBox8.Text); //NewRow.SetField<String>("SuiteNumber", textBox9.Text); //NewRow.SetField<String>("StreetNumber", textBox10.Text); //NewRow.SetField<String>("StreetName", textBox11.Text); //NewRow.SetField<String>("City", textBox12.Text); //NewRow.SetField<String>("Province", textBox13.Text); //NewRow.SetField<String>("PostalCode", textBox14.Text); SaveinSqlTable(); NewRow.SetField <Int16>("WhichDB", Convert.ToInt16(textBox17.Text)); ds.Tables["AwarObjSqlTable"].Rows.Add(NewRow); //da.UpdateCommand = Cb.GetUpdateCommand(); da.Update(ds, "AwarObjSqlTable"); //da.AcceptChangesDuringUpdate = true; //ds.AcceptChanges(); RecordCount = RecordCount + 1; //Adding a record for starting Credit Balance //On Transaction System.Windows.Forms.MessageBox.Show("Record Added Succesfully"); //sending an email } else { System.Windows.Forms.MessageBox.Show("Duplicate ID, try Again!!!"); return; } }
private void frmColumnSorting_Load(object sender, EventArgs e) { ds_ViewColumns = obj_bllFormCustomization.LoadDefaultColumnsSorting(); for (int i = 0; i <= ds_TakeQryData.Tables[0].Columns.Count - 1; i++) { dr_ViewColumn = ds_ViewColumns.Tables[0].NewRow(); //dr_ViewColumn = new DataRow(); dr_ViewColumn.SetField("Column Name", ds_TakeQryData.Tables[0].Columns[i].Caption.ToString()); dr_ViewColumn.SetField("ASC", 0); dr_ViewColumn.SetField("DESC", 0); ds_ViewColumns.Tables[0].Rows.Add(dr_ViewColumn); ds_ViewColumns.AcceptChanges(); } gridView1.GridControl.DataSource = ds_ViewColumns.Tables[0]; foreach (GridColumn column in gridView1.Columns) // disable editing for all columns { if (column.AbsoluteIndex == 0) { column.OptionsColumn.AllowEdit = false; } //column.OptionsColumn.AllowEdit = false; } gridView1.BestFitColumns(true); for (int i = 0; i <= gridView1.Columns.Count - 1; i++) { gridView1.Columns[i].BestFit(); } }
private void calcExtraColumns(DataRow row) { // For some reason, if the file was selected from the ComboBox, // then the FileNumber text was not displayed if it was bound // to the expression column expr_FileNumber. // So, I'm making it much more explicit here. if (row == null) return; int fileid = row.Field<int>("FileID"); var file = fileDropTable.FindByFileID(fileid); string filenum = file == null ? "" : file.FileNumber; row.SetField<String>("extra_FileNumber", filenum); }
/// <summary> /// 将合同信息加入行中 /// </summary> /// <param name="row"></param> /// <param name="con"></param> /// <returns></returns> public static DataRow getRowFromContract(DataRow row, Contract con) { row.SetField(0, con.proCate); row.SetField(1, con.proName); row.SetField(2, con.proId); row.SetField(3, con.unicomLinkMan); row.SetField(4, con.linkPhone); row.SetField(5, con.groupCusManager); row.SetField(6, con.proSignUnitName); row.SetField(7, con.unitAdd); row.SetField(8, con.proSign); row.SetField(9, con.signUnitLinkMan); row.SetField(10, con.signUnitLinkPhone); row.SetField(11, con.payPhone); ; row.SetField(12, con.payStand); row.SetField(13, con.proSignDate); row.SetField(14, con.proSignExeDate); row.SetField(15, con.proDeadLine); row.SetField(16, con.proExpireData); row.SetField(17, con.proDesc); row.SetField(18, con.remark); row.SetField(19, con.dltdh); row.SetField(20, con.fileName); return row; }
private void ReadStringField(int colIndex, ColumnMeta meta, DataRow dataRow, BinaryReader br) { if (m_dbreader is WDBReader) dataRow.SetField(colIndex, br.ReadStringNull()); else if (m_dbreader is STLReader) { int offset = br.ReadInt32(); dataRow.SetField(colIndex, (m_dbreader as STLReader).ReadString(offset)); } else { try { dataRow.SetField(colIndex, m_dbreader.IsSparseTable ? br.ReadStringNull() : m_dbreader.StringTable[br.ReadInt32(meta)]); } catch { dataRow.SetField(colIndex, "Invalid string index!"); } } }
private void btnedtSou_TextChanged(object sender, EventArgs e) { if (btnedtSou.Text == "") { return; } string[] sPosPairs = System.IO.File.ReadAllLines(btnedtSou.Text); if (sPosPairs == null || sPosPairs.Length == 0) { MessageBox.Show("请选择正确的文件"); return; } int startIndex = 0; if (chkBegin2.Checked) { startIndex = 1; } if (sPosPairs.Length <= startIndex) { MessageBox.Show("请选择正确的文件"); return; } int ixh = GetMaxXH() + 1; DataTable dt = this.treePosPair.DataSource as DataTable; double soux, souy, souz, tarx, tary, tarz; int errCount = 0; for (int i = startIndex; i < sPosPairs.Length; i++) { souz = 0; tarz = 0; try { string[] parts = sPosPairs[i].Split(','); soux = Convert.ToDouble(parts[1]); souy = Convert.ToDouble(parts[2]); if (chkHavZ.Checked) { souz = Convert.ToDouble(parts[3]); tarx = Convert.ToDouble(parts[4]); tary = Convert.ToDouble(parts[5]); tarz = Convert.ToDouble(parts[6]); } else { tarx = Convert.ToDouble(parts[3]); tary = Convert.ToDouble(parts[4]); } } catch { errCount++; continue; } System.Data.DataRow row = dt.NewRow(); row.SetField("I_XH", ixh++); row.SetField("WKID", this._wkid); row.SetField("SOU_X", soux); row.SetField("SOU_Y", souy); row.SetField("SOU_Z", souz); row.SetField("TAR_X", tarx); row.SetField("TAR_Y", tary); row.SetField("TAR_Z", tarz); dt.Rows.Add(row); } if (errCount == 0 || DialogResult.OK == MessageBox.Show(string.Format("总计{0}条记录,其中无效记录{1}条,\r\n是否继续添加?点击“OK”,则继续添加,否则不添加。", sPosPairs.Length - startIndex, errCount), "提示", MessageBoxButtons.OKCancel)) { this.treePosPair.DataSource = dt; this.treePosPair.RefreshDataSource(); } else { this.btnedtSou.Text = ""; } }