/// <summary> /// 增加一条数据 /// </summary> public int Add(Hownet.Model.FromCloumns model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into FromCloumns("); strSql.Append("Fileds,CName,Width,IsShow,IsCanEdit,IsCanFilter,IsCanGroup,IsCanSort,IsFix,Remark,EName,UserID,MainID,IsMust,TypeID,OrderBy)"); strSql.Append(" values ("); strSql.Append("@Fileds,@CName,@Width,@IsShow,@IsCanEdit,@IsCanFilter,@IsCanGroup,@IsCanSort,@IsFix,@Remark,@EName,@UserID,@MainID,@IsMust,@TypeID,@OrderBy)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Fileds", SqlDbType.NVarChar, 50), new SqlParameter("@CName", SqlDbType.NVarChar, 50), new SqlParameter("@Width", SqlDbType.Int, 4), new SqlParameter("@IsShow", SqlDbType.Bit, 1), new SqlParameter("@IsCanEdit", SqlDbType.Bit, 1), new SqlParameter("@IsCanFilter", SqlDbType.Bit, 1), new SqlParameter("@IsCanGroup", SqlDbType.Bit, 1), new SqlParameter("@IsCanSort", SqlDbType.Bit, 1), new SqlParameter("@IsFix", SqlDbType.Bit, 1), new SqlParameter("@Remark", SqlDbType.NVarChar, 4000), new SqlParameter("@EName", SqlDbType.NVarChar, 50), new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@MainID", SqlDbType.Int, 4), new SqlParameter("@IsMust", SqlDbType.Bit, 1), new SqlParameter("@TypeID", SqlDbType.Int, 4), new SqlParameter("@OrderBy", SqlDbType.Int, 4) }; parameters[0].Value = model.Fileds; parameters[1].Value = model.CName; parameters[2].Value = model.Width; parameters[3].Value = model.IsShow; parameters[4].Value = model.IsCanEdit; parameters[5].Value = model.IsCanFilter; parameters[6].Value = model.IsCanGroup; parameters[7].Value = model.IsCanSort; parameters[8].Value = model.IsFix; parameters[9].Value = model.Remark; parameters[10].Value = model.EName; parameters[11].Value = model.UserID; parameters[12].Value = model.MainID; parameters[13].Value = model.IsMust; parameters[14].Value = model.TypeID; parameters[15].Value = model.OrderBy; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void button4_Click(object sender, EventArgs e) { for (int i = 0; i < dataGridView2.RowCount; i++) { if (Convert.ToInt32(dataGridView2["TypeID", i].Value) == 1) { if (Convert.ToInt32(dataGridView2["ID", i].Value) == 0) { modFC = new Hownet.Model.FromCloumns(); modFC.Fileds = dataGridView2["Fileds", i].Value.ToString().Trim(); modFC.CName = dataGridView2["CName", i].Value.ToString().Trim(); modFC.EName = dataGridView2["EName", i].Value.ToString().Trim(); modFC.Width = Convert.ToInt32(dataGridView2["Width", i].Value); modFC.IsShow = Convert.ToBoolean(dataGridView2["IsShow", i].Value); modFC.IsCanEdit = Convert.ToBoolean(dataGridView2["IsCanEdit", i].Value); modFC.IsCanFilter = Convert.ToBoolean(dataGridView2["IsCanFilter", i].Value); modFC.IsCanGroup = Convert.ToBoolean(dataGridView2["IsCanGroup", i].Value); modFC.IsCanSort = Convert.ToBoolean(dataGridView2["IsCanSort", i].Value); modFC.IsFix = Convert.ToBoolean(dataGridView2["IsFix", i].Value); modFC.UserID = Convert.ToInt32(dataGridView2["UserID", i].Value); modFC.MainID = Convert.ToInt32(dataGridView2["MainID", i].Value); modFC.IsMust = Convert.ToBoolean(dataGridView2["IsMust", i].Value); modFC.Remark = dataGridView2["Remark", i].Value.ToString(); modFC.OrderBy = Convert.ToInt32(dataGridView2["OrderBy", i].Value); modFC.TypeID = 1; dataGridView2["ID", i].Value = bllFC.Add(modFC); } else { if (Convert.ToInt32(dataGridView2["A", i].Value) == 2) { modFC = bllFC.GetModel(Convert.ToInt32(dataGridView2["ID", i].Value)); modFC.CName = dataGridView2["CName", i].Value.ToString().Trim(); modFC.EName = dataGridView2["EName", i].Value.ToString().Trim(); modFC.Width = Convert.ToInt32(dataGridView2["Width", i].Value); modFC.IsShow = Convert.ToBoolean(dataGridView2["IsShow", i].Value); modFC.IsCanEdit = Convert.ToBoolean(dataGridView2["IsCanEdit", i].Value); modFC.IsCanFilter = Convert.ToBoolean(dataGridView2["IsCanFilter", i].Value); modFC.IsCanGroup = Convert.ToBoolean(dataGridView2["IsCanGroup", i].Value); modFC.IsCanSort = Convert.ToBoolean(dataGridView2["IsCanSort", i].Value); modFC.IsFix = Convert.ToBoolean(dataGridView2["IsFix", i].Value); modFC.UserID = Convert.ToInt32(dataGridView2["UserID", i].Value); modFC.MainID = Convert.ToInt32(dataGridView2["MainID", i].Value); modFC.IsMust = Convert.ToBoolean(dataGridView2["IsMust", i].Value); modFC.Remark = dataGridView2["Remark", i].Value.ToString(); modFC.OrderBy = Convert.ToInt32(dataGridView2["OrderBy", i].Value); bllFC.Update(modFC); dataGridView2["A", i].Value = 1; } } } } }
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e) { if (dataGridView1.CurrentRow == null) { return; } dtFC = bllFC.GetList("(MainID=" + Convert.ToInt32(dataGridView1["ID", dataGridView1.CurrentRow.Index].Value) + " And (TypeID=0) ) order by OrderBy").Tables[0]; dataGridView2.DataSource = dtFC; DataTable dt = bllFCM.GetColumnsName(dataGridView1["ClassName", dataGridView1.CurrentRow.Index].Value.ToString()).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { if (dtFC.Select("(Fileds='" + dt.Rows[i]["Name"].ToString() + "')").Length == 0) { if (dt.Rows[i]["Name"].ToString() != "ID" && dt.Rows[i]["Name"].ToString() != "A") { modFC = new Hownet.Model.FromCloumns(); modFC.Fileds = dt.Rows[i]["Name"].ToString(); modFC.CName = string.Empty; modFC.EName = string.Empty; modFC.Width = 100; modFC.IsShow = true; modFC.IsCanEdit = true; modFC.IsCanFilter = true; modFC.IsCanGroup = true; modFC.IsCanSort = true; modFC.IsFix = false; modFC.EName = string.Empty; modFC.UserID = 0; modFC.MainID = Convert.ToInt32(dataGridView1["ID", dataGridView1.CurrentRow.Index].Value); modFC.IsMust = false; modFC.Remark = string.Empty; modFC.A = modFCM.ID = 0; bllFC.Add(modFC); } } } dtFC = bllFC.GetList("(MainID=" + Convert.ToInt32(dataGridView1["ID", dataGridView1.CurrentRow.Index].Value) + " And (TypeID=0)) order by OrderBy").Tables[0]; dataGridView2.DataSource = dtFC; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Hownet.Model.FromCloumns model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update FromCloumns set "); strSql.Append("Fileds=@Fileds,"); strSql.Append("CName=@CName,"); strSql.Append("Width=@Width,"); strSql.Append("IsShow=@IsShow,"); strSql.Append("IsCanEdit=@IsCanEdit,"); strSql.Append("IsCanFilter=@IsCanFilter,"); strSql.Append("IsCanGroup=@IsCanGroup,"); strSql.Append("IsCanSort=@IsCanSort,"); strSql.Append("IsFix=@IsFix,"); strSql.Append("Remark=@Remark,"); strSql.Append("EName=@EName,"); strSql.Append("UserID=@UserID,"); strSql.Append("MainID=@MainID,"); strSql.Append("IsMust=@IsMust,"); strSql.Append("TypeID=@TypeID,"); strSql.Append("OrderBy=@OrderBy"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@Fileds", SqlDbType.NVarChar, 50), new SqlParameter("@CName", SqlDbType.NVarChar, 50), new SqlParameter("@Width", SqlDbType.Int, 4), new SqlParameter("@IsShow", SqlDbType.Bit, 1), new SqlParameter("@IsCanEdit", SqlDbType.Bit, 1), new SqlParameter("@IsCanFilter", SqlDbType.Bit, 1), new SqlParameter("@IsCanGroup", SqlDbType.Bit, 1), new SqlParameter("@IsCanSort", SqlDbType.Bit, 1), new SqlParameter("@IsFix", SqlDbType.Bit, 1), new SqlParameter("@Remark", SqlDbType.NVarChar, 4000), new SqlParameter("@EName", SqlDbType.NVarChar, 50), new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@MainID", SqlDbType.Int, 4), new SqlParameter("@IsMust", SqlDbType.Bit, 1), new SqlParameter("@TypeID", SqlDbType.Int, 4), new SqlParameter("@OrderBy", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.Fileds; parameters[1].Value = model.CName; parameters[2].Value = model.Width; parameters[3].Value = model.IsShow; parameters[4].Value = model.IsCanEdit; parameters[5].Value = model.IsCanFilter; parameters[6].Value = model.IsCanGroup; parameters[7].Value = model.IsCanSort; parameters[8].Value = model.IsFix; parameters[9].Value = model.Remark; parameters[10].Value = model.EName; parameters[11].Value = model.UserID; parameters[12].Value = model.MainID; parameters[13].Value = model.IsMust; parameters[14].Value = model.TypeID; parameters[15].Value = model.OrderBy; parameters[16].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Hownet.Model.FromCloumns GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,Fileds,CName,Width,IsShow,IsCanEdit,IsCanFilter,IsCanGroup,IsCanSort,IsFix,Remark,EName,UserID,MainID,IsMust,TypeID,OrderBy from FromCloumns "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Hownet.Model.FromCloumns model = new Hownet.Model.FromCloumns(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } model.Fileds = ds.Tables[0].Rows[0]["Fileds"].ToString(); model.CName = ds.Tables[0].Rows[0]["CName"].ToString(); if (ds.Tables[0].Rows[0]["Width"] != null && ds.Tables[0].Rows[0]["Width"].ToString() != "") { model.Width = int.Parse(ds.Tables[0].Rows[0]["Width"].ToString()); } if (ds.Tables[0].Rows[0]["IsShow"] != null && ds.Tables[0].Rows[0]["IsShow"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsShow"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsShow"].ToString().ToLower() == "true")) { model.IsShow = true; } else { model.IsShow = false; } } if (ds.Tables[0].Rows[0]["IsCanEdit"] != null && ds.Tables[0].Rows[0]["IsCanEdit"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsCanEdit"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsCanEdit"].ToString().ToLower() == "true")) { model.IsCanEdit = true; } else { model.IsCanEdit = false; } } if (ds.Tables[0].Rows[0]["IsCanFilter"] != null && ds.Tables[0].Rows[0]["IsCanFilter"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsCanFilter"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsCanFilter"].ToString().ToLower() == "true")) { model.IsCanFilter = true; } else { model.IsCanFilter = false; } } if (ds.Tables[0].Rows[0]["IsCanGroup"] != null && ds.Tables[0].Rows[0]["IsCanGroup"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsCanGroup"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsCanGroup"].ToString().ToLower() == "true")) { model.IsCanGroup = true; } else { model.IsCanGroup = false; } } if (ds.Tables[0].Rows[0]["IsCanSort"] != null && ds.Tables[0].Rows[0]["IsCanSort"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsCanSort"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsCanSort"].ToString().ToLower() == "true")) { model.IsCanSort = true; } else { model.IsCanSort = false; } } if (ds.Tables[0].Rows[0]["IsFix"] != null && ds.Tables[0].Rows[0]["IsFix"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsFix"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsFix"].ToString().ToLower() == "true")) { model.IsFix = true; } else { model.IsFix = false; } } model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString(); model.EName = ds.Tables[0].Rows[0]["EName"].ToString(); if (ds.Tables[0].Rows[0]["UserID"] != null && ds.Tables[0].Rows[0]["UserID"].ToString() != "") { model.UserID = int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString()); } if (ds.Tables[0].Rows[0]["MainID"] != null && ds.Tables[0].Rows[0]["MainID"].ToString() != "") { model.MainID = int.Parse(ds.Tables[0].Rows[0]["MainID"].ToString()); } if (ds.Tables[0].Rows[0]["IsMust"] != null && ds.Tables[0].Rows[0]["IsMust"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsMust"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsMust"].ToString().ToLower() == "true")) { model.IsMust = true; } else { model.IsMust = false; } } if (ds.Tables[0].Rows[0]["TypeID"] != null && ds.Tables[0].Rows[0]["TypeID"].ToString() != "") { model.TypeID = int.Parse(ds.Tables[0].Rows[0]["TypeID"].ToString()); } if (ds.Tables[0].Rows[0]["OrderBy"] != null && ds.Tables[0].Rows[0]["OrderBy"].ToString() != "") { model.OrderBy = int.Parse(ds.Tables[0].Rows[0]["OrderBy"].ToString()); } model.A = 1; return(model); } else { return(null); } }
//保存子表 private void button3_Click(object sender, EventArgs e) { //DataTable dtTem=((DataTable)dataGridView2.DataSource); //DataRow[] drs =dtTem .Select("(ID=3) or (ID=4)"); //StringBuilder ss = new StringBuilder(); //for (int j = 0; j < drs.Length; j++) //{ // drs[1][1] = 0; // for (int i = 0; i < dtTem.Columns.Count; i++) // { // //ss.Append(i); // //ss.Append("ю"); // ss.Append(drs[j][i].ToString()); // ss.Append("ж"); // } // ss.Append("й"); //} //MemoryStream ms = new MemoryStream(); //StreamWriter sw = new StreamWriter(ms); //sw.Write(ss.ToString()); //sw.Close(); //byte[] bsrc = ms.ToArray(); //ms.Close(); //ms.Dispose(); //ms = new MemoryStream(); //ms.Position = 0; //// 压缩数组序列并返回压缩后的数组 //DeflateStream zipStream = new DeflateStream(ms, CompressionMode.Compress); //zipStream.Write(bsrc, 0, bsrc.Length); //zipStream.Close(); //zipStream.Dispose(); //byte[] bbb= ms.ToArray(); //Hownet.BLL.Color bllC = new Hownet.BLL.Color(); //bllC.UpOrAdd( bbb); //dataGridView1.DataSource = bllC.GetList("ID=3").Tables[0]; for (int i = 0; i < dataGridView2.RowCount; i++) { if (Convert.ToInt32(dataGridView2["A", i].Value) == 2) { modFC = bllFC.GetModel(Convert.ToInt32(dataGridView2["ID", i].Value)); modFC.CName = dataGridView2["CName", i].Value.ToString().Trim(); modFC.EName = dataGridView2["EName", i].Value.ToString().Trim(); modFC.Width = Convert.ToInt32(dataGridView2["Width", i].Value); modFC.IsShow = modFC.CName.Length > 0; modFC.IsCanEdit = Convert.ToBoolean(dataGridView2["IsCanEdit", i].Value); modFC.IsCanFilter = Convert.ToBoolean(dataGridView2["IsCanFilter", i].Value); modFC.IsCanGroup = Convert.ToBoolean(dataGridView2["IsCanGroup", i].Value); modFC.IsCanSort = Convert.ToBoolean(dataGridView2["IsCanSort", i].Value); modFC.IsFix = Convert.ToBoolean(dataGridView2["IsFix", i].Value); modFC.UserID = 0; modFC.MainID = Convert.ToInt32(dataGridView2["MainID", i].Value); modFC.IsMust = Convert.ToBoolean(dataGridView2["IsMust", i].Value); modFC.Remark = dataGridView2["Remark", i].Value.ToString(); modFC.OrderBy = Convert.ToInt32(dataGridView2["OrderBy", i].Value); bllFC.Update(modFC); dataGridView2["A", i].Value = 1; } } }