//失去焦点事件 void txt_LostFocus(object sender, EventArgs e) { myTextBox txtBox = (myTextBox)sender; string fieldName = txtBox.Name.Replace("txt_", ""); if (txtBox.Text.Trim().Length > 0) { txtBox.Text = txtBox.Text.Trim().ToUpper(); if (rowHead[fieldName].ToString() != txtBox.Text.Trim().ToString()) { rowHead[fieldName] = txtBox.Text; } } switch (fieldName) { case "显示型号": #region 显示型号 if (txt_料件名.Text.Trim().Length == 0) { txt_料件名.Text = txt_显示型号.Text; rowHead["料件名"] = txt_料件名.Text; } break; #endregion } }
//文本控件值变化时验证 private void txt_Validating(object sender, CancelEventArgs e) { myTextBox txtBox = (myTextBox)sender; if (txtBox.Text.Trim().Length == 0) { return; } string fieldName = txtBox.Name.Replace("txt_", ""); string strSQL = string.Empty; IDataAccess dataAccess = null; switch (fieldName) { case "料件型号": #region 料件型号 if (rowHead.RowState == DataRowState.Added || (rowHead.RowState == DataRowState.Modified && rowHead["料件型号", DataRowVersion.Original].ToString() != txtBox.Text)) { strSQL = string.Format("SELECT 料件id FROM 料件资料表 WHERE 料件型号 = {0}", StringTools.SqlQ(txtBox.Text)); dataAccess = DataAccessFactory.CreateDataAccess(DataAccessEnum.DataAccessName.DataAccessName_Manufacture); dataAccess.Open(); DataTable dtManual = dataAccess.GetTable(strSQL.ToString(), null); dataAccess.Close(); if (dtManual.Rows.Count > 0) { SysMessage.InformationMsg("此料件型号已存在,请重新输入!"); e.Cancel = true; txtBox.Focus(); } } break; #endregion } }
private void txt_Validated(object sender, EventArgs e) { myTextBox txtBox = (myTextBox)sender; string fieldName = txtBox.Name.Replace("txt_", ""); if (rowHead[fieldName].ToString() != txtBox.Text) { rowHead[fieldName] = txtBox.Text; } }
private RadioButton rbSmallBills; //мелкие купюры public GetCashForm() { Text = "Получение наличных средств"; //Заголовок окна получения средств //Метка - приглашение Label labelInvitation = new Label(); labelInvitation.Text = "Укажите требуемую сумму в рублях:"; labelInvitation.Location = new Point(15, 15); labelInvitation.AutoSize = true; labelInvitation.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelInvitation); //Textbox для ввода запрашиваемой суммы tbGetCash = new myTextBox(); tbGetCash.Text = ""; tbGetCash.Location = new Point(labelInvitation.Width + 17, 15); tbGetCash.Width = 50; tbGetCash.Height = labelInvitation.Height; tbGetCash.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbGetCash); //GroupBox для выбора крупных/мелких купюр GroupBox gbLargeSmallBills = new GroupBox(); rbLargeBills = new RadioButton(); rbSmallBills = new RadioButton(); gbLargeSmallBills.Controls.Add(rbLargeBills); gbLargeSmallBills.Controls.Add(rbSmallBills); gbLargeSmallBills.Location = new Point(15, tbGetCash.Height + 17); gbLargeSmallBills.Width = rbLargeBills.Width + rbSmallBills.Width + 32; gbLargeSmallBills.Height = rbLargeBills.Height + 30; gbLargeSmallBills.Text = "Какими купюрами выдать сумму?"; rbLargeBills.Text = "Крупными"; rbSmallBills.Text = "С разменом"; rbLargeBills.Location = new Point(15, 20); rbSmallBills.Location = new Point(rbLargeBills.Width + 17, 20); rbLargeBills.AutoSize = true; rbSmallBills.AutoSize = true; Controls.Add(gbLargeSmallBills); rbLargeBills.Checked = true; //Кнопка получения наличных Button bGet = new Button(); bGet.Text = "Получить"; bGet.Location = new Point(15, gbLargeSmallBills.Height + tbGetCash.Height + 19); bGet.AutoSize = true; bGet.TextAlign = ContentAlignment.MiddleCenter; this.Controls.Add(bGet); bGet.Click += new System.EventHandler(bGet_Clicked); //Установка обработчика нажатия на кнопку получения наличных }
private void txtFloat_Validating(object sender, CancelEventArgs e) { myTextBox txtBox = (myTextBox)sender; if (txtBox.Text.Trim().Length > 0) { try { decimal.Parse(txtBox.Text.Trim()); } catch (Exception ex) { SysMessage.ErrorMsg(ex.Message); e.Cancel = true; } } }
private CheckBox cbPunctuationMarks; //Элемент выбора удаления знаков препинания public AppForm() { Text = "Программа обработки текста"; //Заголовок окна программы //Меню пограммы MainMenu mnuFileMenu = new MainMenu(); this.Menu = mnuFileMenu; MenuItem MenuItemFile = new MenuItem("&File"); MenuItemFile.MenuItems.Add("&Open", new System.EventHandler(this.MenuOpen_Click)); MenuItemFile.MenuItems.Add("E&xit", new System.EventHandler(this.MenuExit_Click)); mnuFileMenu.MenuItems.Add(MenuItemFile); //Метка для элемента ввода минимального количества букв в словах Label labelMinNumOfLetters = new Label(); labelMinNumOfLetters.Text = "Минимальное количество букв в словах:"; labelMinNumOfLetters.Location = new Point(15, 15); labelMinNumOfLetters.AutoSize = true; labelMinNumOfLetters.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelMinNumOfLetters); //Элемент ввода минимального количества букв в словах tbMinNumOfLetters = new myTextBox(); tbMinNumOfLetters.Text = "3"; tbMinNumOfLetters.Location = new Point(17 + labelMinNumOfLetters.Width, 15); tbMinNumOfLetters.Width = 30; tbMinNumOfLetters.Height = labelMinNumOfLetters.Height; tbMinNumOfLetters.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbMinNumOfLetters); //Метка для элемента выбора удаления знаков препинания Label labelPunctuationMarks = new Label(); labelPunctuationMarks.Text = "Удалить знаки препинания:"; labelPunctuationMarks.Location = new Point(15, 17 + tbMinNumOfLetters.Height); labelPunctuationMarks.AutoSize = true; labelPunctuationMarks.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelPunctuationMarks); //Элемент выбора удаления знаков препинания cbPunctuationMarks = new CheckBox(); cbPunctuationMarks.Location = new Point(17 + labelPunctuationMarks.Width, 17 + tbMinNumOfLetters.Height); this.Controls.Add(cbPunctuationMarks); }
private void txt_Validated(object sender, EventArgs e) { myTextBox txtBox = (myTextBox)sender; string fieldName = txtBox.Name.Replace("txt_", ""); if (rowHead[fieldName].ToString() != txtBox.Text) { if (fieldName == "序号" || fieldName == "损耗率" || fieldName == "单价" || fieldName == "换算因子") { if (txtBox.Text.Trim().Length == 0) { rowHead[fieldName] = DBNull.Value; } else { rowHead[fieldName] = txtBox.Text; if (fieldName == "序号") { if (txt_产品编号.Text.Trim().Length > 0) { return; } if (txtBox.Text.Length == 1) { txt_产品编号.Text = string.Format("A0{0}", txtBox.Text.Trim()); } else { txt_产品编号.Text = string.Format("A{0}", txtBox.Text.Trim()); } rowHead["产品编号"] = txt_产品编号.Text; } } } else { rowHead[fieldName] = txtBox.Text; } } }
/// <summary> /// 根据控件生成查询条件串 /// </summary> /// <param name="control"></param> public void MakeQueryWhere(Control control) { string strControlName = control.Name; //控件名称 string strFieldName = string.Empty; //控件对应的字段名 if (strControlName.StartsWith("txt_")) //textbox控件 { myTextBox tb = (myTextBox)control; if (tb.Text.Trim().Length > 0) { strFieldName = tb.Tag.ToString(); if (this.myCheckBox1.Checked) //模糊查询 { strReturnWhere += (strReturnWhere.Length > 0 ? " and " : "") + string.Format("{0} like '%{1}%'", strFieldName, StringTools.SqlLikeQ(tb.Text.Trim())); } else //精确查询 { strReturnWhere += (strReturnWhere.Length > 0 ? " and " : "") + string.Format("{0}={1}", strFieldName, StringTools.SqlQ(tb.Text.Trim())); } } } else if (strControlName.StartsWith("cbox_")) //下拉控件 { myComboBox cbox = (myComboBox)control; if (cbox.SelectedValue != null && cbox.SelectedValue.ToString().Length > 0) { string tag = cbox.Tag.ToString(); string dataType = tag.Split(',')[0]; strFieldName = tag.Split(',')[1]; if (dataType == "string") { strReturnWhere += (strReturnWhere.Length > 0 ? " and " : "") + string.Format("{0}={1}", strFieldName, StringTools.SqlQ(cbox.SelectedValue.ToString())); } else if (dataType == "int") { strReturnWhere += (strReturnWhere.Length > 0 ? " and " : "") + string.Format("{0}={1}", strFieldName, cbox.SelectedValue); } } } else if (strControlName.StartsWith("date_")) //日期控件 { myDateTimePicker dtp = (myDateTimePicker)control; if (dtp.Checked) { string tag = dtp.Tag.ToString(); string index = tag.Split(',')[0]; strFieldName = tag.Split(',')[1]; if (index == "0") //表示是指定日期 { strReturnWhere += (strReturnWhere.Length > 0 ? " and " : "") + string.Format("{0}={1}", strFieldName, dtp.Value.ToShortDateString()); } else if (index == "1") //表示起始日期 { strReturnWhere += (strReturnWhere.Length > 0 ? " and " : "") + string.Format("{0}>='{1} 00:00:01'", strFieldName, dtp.Value.ToShortDateString()); } else if (index == "2") //表示截止日期 { strReturnWhere += (strReturnWhere.Length > 0 ? " and " : "") + string.Format("{0}<'{1} 23:59:59'", strFieldName, dtp.Value.ToShortDateString()); } } } else if (strControlName.StartsWith("datetime_")) //日期(包含时间)控件 { myDateTimePicker dtp = (myDateTimePicker)control; if (dtp.Checked) { string tag = dtp.Tag.ToString(); string index = tag.Split(',')[0]; strFieldName = tag.Split(',')[1]; if (index == "1") //表示起始时间 { strReturnWhere += (strReturnWhere.Length > 0 ? " and " : "") + string.Format("{0}>='{1}'", strFieldName, dtp.Value.ToString("yyyy-MM-dd HH:mm:ss")); } else if (index == "2") //表示截止时间 { strReturnWhere += (strReturnWhere.Length > 0 ? " and " : "") + string.Format("{0}<'{1}'", strFieldName, dtp.Value.ToString("yyyy-MM-dd HH:mm:ss")); } } } }
//Получить численное значение myTextBox public int getIntValMTB(myTextBox mTB) { return((mTB.Text == "")?0:Convert.ToInt32(mTB.Text)); }
private myTextBox tbGet5000Rub; //5000 рублевки public GetCashExchangeForm() { Text = "Получение наличных средств с разменом"; //Заголовок окна получения наличных с разменом //Метка - приглашение Label labelInvitation = new Label(); labelInvitation.Text = "Укажите количество купюр достоинством:"; labelInvitation.Location = new Point(15, 15); labelInvitation.AutoSize = true; labelInvitation.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelInvitation); //Метка для поля получения 10 рублевых купюр Label labelGet10Rub = new Label(); labelGet10Rub.Text = "10 руб.:"; labelGet10Rub.Location = new Point(15, labelInvitation.Height + 25); labelGet10Rub.AutoSize = true; labelGet10Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelGet10Rub); //Textbox получения 10 рублевых купюр tbGet10Rub = new myTextBox(); tbGet10Rub.Text = ""; tbGet10Rub.Location = new Point(labelGet10Rub.Width + 17, labelInvitation.Height + 25); tbGet10Rub.Width = 30; tbGet10Rub.Height = labelGet10Rub.Height; tbGet10Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbGet10Rub); //Метка для поля получения 50 рублевых купюр Label labelGet50Rub = new Label(); labelGet50Rub.Text = "50 руб.:"; labelGet50Rub.Location = new Point(15, tbGet10Rub.Location.Y + tbGet10Rub.Height + 2); labelGet50Rub.AutoSize = true; labelGet50Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelGet50Rub); //Textbox получения 50 рублевых купюр tbGet50Rub = new myTextBox(); tbGet50Rub.Text = ""; tbGet50Rub.Location = new Point(labelGet50Rub.Width + 17, tbGet10Rub.Location.Y + tbGet10Rub.Height + 2); tbGet50Rub.Width = 30; tbGet50Rub.Height = labelGet50Rub.Height; tbGet50Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbGet50Rub); //Метка для поля получения 100 рублевых купюр Label labelGet100Rub = new Label(); labelGet100Rub.Text = "100 руб.:"; labelGet100Rub.Location = new Point(15, tbGet50Rub.Location.Y + tbGet50Rub.Height + 2); labelGet100Rub.AutoSize = true; labelGet100Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelGet100Rub); //Textbox получения 100 рублевых купюр tbGet100Rub = new myTextBox(); tbGet100Rub.Text = ""; tbGet100Rub.Location = new Point(labelGet100Rub.Width + 17, tbGet50Rub.Location.Y + tbGet50Rub.Height + 2); tbGet100Rub.Width = 30; tbGet100Rub.Height = labelGet100Rub.Height; tbGet100Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbGet100Rub); //Метка для поля получения 500 рублевых купюр Label labelGet500Rub = new Label(); labelGet500Rub.Text = "500 руб.:"; labelGet500Rub.Location = new Point(15, tbGet100Rub.Location.Y + tbGet100Rub.Height + 2); labelGet500Rub.AutoSize = true; labelGet500Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelGet500Rub); //Textbox получения 500 рублевых купюр tbGet500Rub = new myTextBox(); tbGet500Rub.Text = ""; tbGet500Rub.Location = new Point(labelGet500Rub.Width + 17, tbGet100Rub.Location.Y + tbGet100Rub.Height + 2); tbGet500Rub.Width = 30; tbGet500Rub.Height = labelGet500Rub.Height; tbGet500Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbGet500Rub); //Метка для поля получения 1000 рублевых купюр Label labelGet1000Rub = new Label(); labelGet1000Rub.Text = "1000 руб.:"; labelGet1000Rub.Location = new Point(15, tbGet500Rub.Location.Y + tbGet500Rub.Height + 2); labelGet1000Rub.AutoSize = true; labelGet1000Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelGet1000Rub); //Textbox получения 1000 рублевых купюр tbGet1000Rub = new myTextBox(); tbGet1000Rub.Text = ""; tbGet1000Rub.Location = new Point(labelGet1000Rub.Width + 17, tbGet500Rub.Location.Y + tbGet500Rub.Height + 2); tbGet1000Rub.Width = 30; tbGet1000Rub.Height = labelGet1000Rub.Height; tbGet1000Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbGet1000Rub); //Метка для поля получения 5000 рублевых купюр Label labelGet5000Rub = new Label(); labelGet5000Rub.Text = "5000 руб.:"; labelGet5000Rub.Location = new Point(15, tbGet1000Rub.Location.Y + tbGet1000Rub.Height + 2); labelGet5000Rub.AutoSize = true; labelGet5000Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelGet5000Rub); //Textbox получения 5000 рублевых купюр tbGet5000Rub = new myTextBox(); tbGet5000Rub.Text = ""; tbGet5000Rub.Location = new Point(labelGet5000Rub.Width + 17, tbGet1000Rub.Location.Y + tbGet1000Rub.Height + 2); tbGet5000Rub.Width = 30; tbGet5000Rub.Height = labelGet5000Rub.Height; tbGet5000Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbGet5000Rub); //Кнопка получения средств Button bGet = new Button(); bGet.Text = "Получить"; bGet.Location = new Point(15, tbGet5000Rub.Location.Y + tbGet1000Rub.Height + 10); bGet.AutoSize = true; bGet.TextAlign = ContentAlignment.MiddleCenter; this.Controls.Add(bGet); bGet.Click += new System.EventHandler(bGet_Clicked); //Установка обработчика нажатия на кнопку получения средств }
private myTextBox tbContrib5000Rub; //5000 рублевки public ContribForm() { Text = "Внесение наличных средств в банкомат"; //Заголовок окна внесения средств //Метка - приглашение Label labelInvitation = new Label(); labelInvitation.Text = "Укажите количество вносимых купюр достоинством:"; labelInvitation.Location = new Point(15, 15); labelInvitation.AutoSize = true; labelInvitation.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelInvitation); //Метка для поля внесения 10 рублевых купюр Label labelContrib10Rub = new Label(); labelContrib10Rub.Text = "10 руб.:"; labelContrib10Rub.Location = new Point(15, labelInvitation.Height + 25); labelContrib10Rub.AutoSize = true; labelContrib10Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelContrib10Rub); //Textbox внесения 10 рублевых купюр tbContrib10Rub = new myTextBox(); tbContrib10Rub.Text = ""; tbContrib10Rub.Location = new Point(labelContrib10Rub.Width + 17, labelInvitation.Height + 25); tbContrib10Rub.Width = 30; tbContrib10Rub.Height = labelContrib10Rub.Height; tbContrib10Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbContrib10Rub); //Метка для поля внесения 50 рублевых купюр Label labelContrib50Rub = new Label(); labelContrib50Rub.Text = "50 руб.:"; labelContrib50Rub.Location = new Point(15, tbContrib10Rub.Location.Y + tbContrib10Rub.Height + 2); labelContrib50Rub.AutoSize = true; labelContrib50Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelContrib50Rub); //Textbox внесения 50 рублевых купюр tbContrib50Rub = new myTextBox(); tbContrib50Rub.Text = ""; tbContrib50Rub.Location = new Point(labelContrib50Rub.Width + 17, tbContrib10Rub.Location.Y + tbContrib10Rub.Height + 2); tbContrib50Rub.Width = 30; tbContrib50Rub.Height = labelContrib50Rub.Height; tbContrib50Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbContrib50Rub); //Метка для поля внесения 100 рублевых купюр Label labelContrib100Rub = new Label(); labelContrib100Rub.Text = "100 руб.:"; labelContrib100Rub.Location = new Point(15, tbContrib50Rub.Location.Y + tbContrib50Rub.Height + 2); labelContrib100Rub.AutoSize = true; labelContrib100Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelContrib100Rub); //Textbox внесения 100 рублевых купюр tbContrib100Rub = new myTextBox(); tbContrib100Rub.Text = ""; tbContrib100Rub.Location = new Point(labelContrib100Rub.Width + 17, tbContrib50Rub.Location.Y + tbContrib50Rub.Height + 2); tbContrib100Rub.Width = 30; tbContrib100Rub.Height = labelContrib100Rub.Height; tbContrib100Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbContrib100Rub); //Метка для поля внесения 500 рублевых купюр Label labelContrib500Rub = new Label(); labelContrib500Rub.Text = "500 руб.:"; labelContrib500Rub.Location = new Point(15, tbContrib100Rub.Location.Y + tbContrib100Rub.Height + 2); labelContrib500Rub.AutoSize = true; labelContrib500Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelContrib500Rub); //Textbox внесения 500 рублевых купюр tbContrib500Rub = new myTextBox(); tbContrib500Rub.Text = ""; tbContrib500Rub.Location = new Point(labelContrib500Rub.Width + 17, tbContrib100Rub.Location.Y + tbContrib100Rub.Height + 2); tbContrib500Rub.Width = 30; tbContrib500Rub.Height = labelContrib500Rub.Height; tbContrib500Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbContrib500Rub); //Метка для поля внесения 1000 рублевых купюр Label labelContrib1000Rub = new Label(); labelContrib1000Rub.Text = "1000 руб.:"; labelContrib1000Rub.Location = new Point(15, tbContrib500Rub.Location.Y + tbContrib500Rub.Height + 2); labelContrib1000Rub.AutoSize = true; labelContrib1000Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelContrib1000Rub); //Textbox внесения 1000 рублевых купюр tbContrib1000Rub = new myTextBox(); tbContrib1000Rub.Text = ""; tbContrib1000Rub.Location = new Point(labelContrib1000Rub.Width + 17, tbContrib500Rub.Location.Y + tbContrib500Rub.Height + 2); tbContrib1000Rub.Width = 30; tbContrib1000Rub.Height = labelContrib1000Rub.Height; tbContrib1000Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbContrib1000Rub); //Метка для поля внесения 5000 рублевых купюр Label labelContrib5000Rub = new Label(); labelContrib5000Rub.Text = "5000 руб.:"; labelContrib5000Rub.Location = new Point(15, tbContrib1000Rub.Location.Y + tbContrib1000Rub.Height + 2); labelContrib5000Rub.AutoSize = true; labelContrib5000Rub.TextAlign = ContentAlignment.BottomLeft; this.Controls.Add(labelContrib5000Rub); //Textbox внесения 5000 рублевых купюр tbContrib5000Rub = new myTextBox(); tbContrib5000Rub.Text = ""; tbContrib5000Rub.Location = new Point(labelContrib5000Rub.Width + 17, tbContrib1000Rub.Location.Y + tbContrib1000Rub.Height + 2); tbContrib5000Rub.Width = 30; tbContrib5000Rub.Height = labelContrib5000Rub.Height; tbContrib5000Rub.TextAlign = HorizontalAlignment.Right; this.Controls.Add(tbContrib5000Rub); //Кнопка внесения средств Button bContrib = new Button(); bContrib.Text = "Внести"; bContrib.Location = new Point(15, tbContrib5000Rub.Location.Y + tbContrib1000Rub.Height + 10); bContrib.AutoSize = true; bContrib.TextAlign = ContentAlignment.MiddleCenter; this.Controls.Add(bContrib); bContrib.Click += new System.EventHandler(bContrib_Clicked); //Установка обработчика нажатия на кнопку внесения средств }