private void button2_Click(object sender, EventArgs e) { DataClassesSaleLinqDataContext allusers = new DataClassesSaleLinqDataContext(); var k = allusers.F_S_USER.Where(p => p.称 == this.comboBox1.Text).First(); if (this.textBox1.Text == k.密码) { staticLoinUser.loginID = k.id; staticLoinUser.loginName = k.称; staticLoinUser.loginPower = k.权限; this.Hide(); (new MainForm()).Show(); } else { MessageBox.Show("密码错误"); } }
/// <summary> /// 递归显示求得所有子结点 /// </summary> /// <param name="id"></param> /// <returns></returns> public static List <TreeNode> getNodsByID(int id) { //递归求出所有根节点下的子结点 List <TreeNode> l = new List <TreeNode>(); DataClassesSaleLinqDataContext DataContextLinq = new DataClassesSaleLinqDataContext(); var a = DataContextLinq.F_S_CLOTHTYPE.Where(p => p.父类ID == id && p.ID != 1).Select(p => p); foreach (var q in a) { TreeNode tn = new TreeNode(); tn.Name = q.ID.ToString(); tn.Text = q.类别; var ll = getNodsByID(q.ID); foreach (TreeNode tnn in ll) { tn.Nodes.Add(tnn); } l.Add(tn); } return(l); }
/// <summary> /// 保存添加或修改的记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1保存_Click(object sender, EventArgs e) { //检查表单位 if (!this.checkeFormOk()) { return; } //之所以用DataView 和DataRowView进行对行的复制是因为如果用表格行,会因为排序问题 //导致当前行发生变化,不好定位到最后修改的行上去. BindingSource bs = this.f_INCOMEBindingSource; DataView view = (DataView)bs.List; DataRowView crow = (DataRowView)bs.Current; if (this.groupBoxadd.Visible) { //如果是添加记录: bool isfirstLine = true; //用于检测是不是第一行 //建立尺寸表的对应 DataClassesSaleLinqDataContext dataclass = new DataClassesSaleLinqDataContext(); var sizeList = dataclass.F_S_SIZE.Select(p => p).ToList(); var sizeNameList = new List <string> { "S", "M", "L", "XL", "XXL" }; //循环检查尺寸添加新行 foreach (Control obj in this.groupBoxadd.Controls) { //如果不是尺寸控件,跑过下面代码进入下一循环 if (sizeNameList.Where(q => q == obj.Name).Count() == 0) { continue; } //控制值为零了跳过 if (((NumericUpDown)obj).Value == 0) { continue; } if (isfirstLine) { //第一行进行基本设置 DataGridViewRow copyTargetRow = this.f_INCOMEDataGridView.CurrentRow; copyTargetRow.Cells["尺码"].Value = sizeList.Where(pp => pp.尺寸 == obj.Name).Select(ppp => ppp.id).First(); copyTargetRow.Cells["进货数量"].Value = (int)((NumericUpDown)obj).Value; copyTargetRow.Cells["录入人员"].Value = staticLoinUser.loginID; copyTargetRow.Cells["录入时间"].Value = DateTime.Now; this.f_INCOMEBindingSource.EndEdit(); isfirstLine = false; } else { DataRowView newrow = view.AddNew();//每执行一次ADDNEW会自动将上次的ADDNEW的修改状态END。但CURRENT不变 for (int i = 1; i < this.f_INCOMEDataGridView.CurrentRow.Cells.Count; i++) { newrow[i] = crow[i]; } newrow["尺码"] = sizeList.Where(pp => pp.尺寸 == obj.Name).Select(ppp => ppp.id).First(); newrow["进货数量"] = (int)((NumericUpDown)obj).Value; } } this.f_INCOMEBindingSource.MoveLast(); //将当前行移动到最后的添加行上,要不然下面的ENDEDIT无效 this.f_INCOMEBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.saleDataSetAll); this.hasmodify = false; if (this.toolStripTextBox查找.Text != Properties.Settings.Default.批次) { this.toolStripTextBox查找.Text = Properties.Settings.Default.批次; MessageBox.Show("将自动显示同一批次进库信息!如果想查看其它批次,请清空上方查找框的内容"); } } else { //仅是修改记录 this.Validate(); DataGridViewRow ddr = this.f_INCOMEDataGridView.CurrentRow; ddr.Cells["备注"].Value = string.Format("修改于{0},by{1},原数量:{2}原尺寸:{3}原备注:【{4}】", DateTime.Now.ToShortDateString(), staticLoinUser.loginName, this.label原数量.Text, this.comboBox原尺码.Text, this.label原备注.Text); this.f_INCOMEBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.saleDataSetAll); this.hasmodify = false; } //关才添加/修改的窗体 this.panel1.Visible = false; this.f_INCOMEDataGridView.Enabled = true; this.f_INCOMEBindingNavigator.Enabled = true; this.f_INCOMEDataGridView.Enabled = true; }