//保存内容 private void btnEdit_SaveClickHandleClick(object sender, EventArgs e) { // 这里是插入方法 if (EditOrInsert == 0) { //判断为空 if (string.IsNullOrEmpty(dgvBaseList.Rows[index].Cells["dgvBaseListName"].Value.ToString())) { lblError.Text = "名称没有添入内容"; return; //存在相同直接返回 } //这是插入记录 行号为Index for (int i = 0; i < dgvBaseList.Rows.Count - 1; i++) { if (dgvBaseList.Rows[i].Cells["dgvBaseListName"].Value.ToString().Trim() == dgvBaseList.Rows[index].Cells["dgvBaseListName"].Value.ToString()) { dgvBaseList.Rows[i].Cells["dgvBaseListName"].Style.BackColor = Color.Red; lblError.Text = "存在相同项"; return; //存在相同直接返回 } } //这里插入记录 GoodsTypeUp bs = new GoodsTypeUp(); bs.Name = dgvBaseList.Rows[index].Cells["dgvBaseListName"].Value.ToString(); bs.Code = dgvBaseList.Rows[index].Cells["dgvBaseListCode"].Value.ToString(); new BaseManager <GoodsTypeUp>().InsertBoxSize(bs); } //这里是修改记录方法 if (EditOrInsert == 1) { //进行相同比较 for (int i = 0; i < dgvBaseList.Rows.Count - 1; i++) { for (int j = i + 1; j < dgvBaseList.Rows.Count; j++) { if (dgvBaseList.Rows[i].Cells["dgvBaseListName"].Value.ToString() == dgvBaseList.Rows[j].Cells["dgvBaseListName"].Value.ToString()) { //存在相同 红色显示 dgvBaseList.Rows[i].Cells["dgvBaseListName"].Style.BackColor = Color.Red; dgvBaseList.Rows[j].Cells["dgvBaseListName"].Style.BackColor = Color.Red; lblError.Text = "存在相同的内容"; return; } } } foreach (DataGridViewRow item in dgvBaseList.Rows) //循环更新 { GoodsTypeUp bs = new GoodsTypeUp(); bs.ID = item.Cells["dgvBaseListID"].Value.ToString(); bs.Name = item.Cells["dgvBaseListName"].Value.ToString(); bs.Code = item.Cells["dgvBaseListCode"].Value.ToString(); new BaseManager <GoodsTypeUp>().UpdateBoxSize(bs); } } btnEdit.isTrue = true; lblError.Text = ""; Init(); }
private void btnIn_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Excel文件|*.xls"; ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { List <string> context = new List <string>(); new ExcelManager.ExcelHelper().LoadToBaseDB(ofd.FileName, 2, ref context); //3是需要读入的列 //插入到数据库 foreach (string item in context) { GoodsTypeUp p = new GoodsTypeUp(); p.Code = item.Split(',')[0]; p.Name = item.Split(',')[1]; new BaseService <GoodsTypeUp>().InsertRecord(p); } //重新装入到表格 Init(); } }