private void btnSave_Click(object sender, EventArgs e) { gxbDetail.Enabled = false; btnSave.Enabled = false; if (Validate()) { usersBindingSource.EndEdit(); if (1 == usersTableAdapter.Update(farmManageDataSet.Users)) { var log = new UserLogTableAdapter(); log.Insert(TypeUtil.User, UserID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_MODIFY, DateTime.Now); DialogResult = DialogUtil.SaveSuccess(); } else { DialogResult = DialogUtil.SaveError(); } } else { gxbDetail.Enabled = true; btnSave.Enabled = true; } }
private void btnChange_Click(object sender, EventArgs e) { if (!tbxPassword.Text.Trim().Equals(tbxConfirmPassword.Text.Trim())) { MessageBox.Show("รหัสผ่านไม่ตรงกัน, กรุณาลองใหม่อีกครั้ง", "รหัสผ่านไม่ตรงกัน", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { if (tbxPassword.Text.Trim().Length < 6) { MessageBox.Show("รหัสผ่านสั้นเกินไป, กรุณาลองใหม่อีกครั้ง", "รหัสผ่านสั้นเกินไป", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (ValidateChildren()) { usersBindingSource.EndEdit(); if (1 == usersTableAdapter.Update(farmManageDataSet.Users)) { var log = new UserLogTableAdapter(); log.Insert(TypeUtil.User, UserID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CHANGE_PASSWORD, DateTime.Now); DialogResult = DialogUtil.SaveSuccess(); } else { DialogResult = DialogUtil.SaveError(); } } }
private void btnSave_Click(object sender, EventArgs e) { if (OrderOutID > 0) { this.Validate(); this.deadViewBindingSource.EndEdit(); this.fKCowOrderOut1BindingSource.EndEdit(); Int32 result = this.deadViewTableAdapter.Update(this.farmManageDataSet.DeadView); if (result == 1) { this.DialogResult = DialogUtil.SaveSuccess(); } else { this.DialogResult = DialogUtil.SaveError(); } } else { OrderOutID = (int)this.deadViewTableAdapter.InsertQuery( (byte)2, Convert.ToInt32(this.cbxBy.SelectedValue), this.dtpDate.Value, this.tbxDescription.Text); if (OrderOutID > 0) { var log = new UserLogTableAdapter(); log.Insert(TypeUtil.OrderOut, OrderOutID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now); foreach (DataGridViewRow row in this.dgvCowAdd.Rows) { Int32 tCorralID = Convert.ToInt32(row.Cells["colCorral"].Value); String tCowNO = row.Cells["colCowNO"].Value.ToString(); int result = this.cowTableAdapter.UpdateCowOrderOut(OrderOutID, new Double?(), tCowNO); if (result == 1) { log.Insert(TypeUtil.Cow, tCowNO, MainForm.User.UserID, TypeUtil.EVENT_DEAD, DateTime.Now); this.corralTableAdapter.UpdateRemoveCurrent(1, tCorralID); } } this.DialogResult = DialogUtil.AddSuccess(); } else { this.DialogResult = DialogUtil.AddError(); } } }
private void btnSave_Click(object sender, EventArgs e) { if (!this.ValidateChildren()) { return; } if (CorralID > 0) { this.Validate(); this.corralBindingSource.EndEdit(); var ResultId = this.corralTableAdapter.Update(farmManageDataSet.Corral); if (ResultId == 1) { UserLogTableAdapter logTableAdapter = new UserLogTableAdapter(); logTableAdapter.Insert(TypeUtil.Corral, CorralID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_MODIFY, DateTime.Now); DialogUtil.SaveSuccess(); this.DialogResult = DialogResult.Yes; } else { DialogUtil.SaveError(); this.DialogResult = DialogResult.No; } } else { CorralID = (int)this.corralTableAdapter.InsertQuery(tbxName.Text.Trim(), Convert.ToInt32(tbxMax.Text), Convert.ToInt32(tbxCurrent.Text), tbxDescription.Text.Trim()); if (CorralID > 0) { UserLogTableAdapter logTableAdapter = new UserLogTableAdapter(); logTableAdapter.Insert(TypeUtil.Corral, CorralID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_MODIFY, DateTime.Now); DialogUtil.AddSuccess(); this.DialogResult = DialogResult.Yes; } else { DialogUtil.AddError(); this.DialogResult = DialogResult.No; } } }
private void btnSave_Click(object sender, EventArgs e) { if (!this.ValidateChildren()) { return; } if (StockID != 0) { this.Validate(); this.stockBindingSource.EndEdit(); if (1 == stockTableAdapter.Update(farmManageDataSet.Stock)) { var log = new UserLogTableAdapter(); log.Insert(TypeUtil.Stock, StockID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now); DialogResult = DialogUtil.SaveSuccess(); } else { DialogResult = DialogUtil.SaveError(); } } else { StockID = (int)stockTableAdapter.InsertQuery(tbxSuppliesName.Text, Convert.ToDouble(tbxUnit.Text), Convert.ToByte(cbxSuppliesType.SelectedValue), tbxDescription.Text); if (StockID > 0) { var log = new UserLogTableAdapter(); log.Insert(TypeUtil.Stock, StockID.ToString(), MainForm.User.UserID, 0, DateTime.Now); DialogResult = DialogUtil.AddSuccess(); } else { DialogResult = DialogUtil.AddError(); } } }
private void btnSave_Click(object sender, EventArgs e) { if (!this.ValidateChildren()) { return; } if (GeneID != 0) { this.geneBindingSource.EndEdit(); if (1 == this.geneTableAdapter.Update(this.farmManageDataSet.Gene)) { UserLogTableAdapter logTableAdapter = new UserLogTableAdapter(); logTableAdapter.Insert(TypeUtil.Gene, GeneID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_MODIFY, DateTime.Now); this.DialogResult = DialogUtil.SaveSuccess(); } else { this.DialogResult = DialogUtil.SaveError(); } } else { GeneID = (int)this.geneTableAdapter.InsertQuery(this.tbxName.Text.Trim(), this.tbxNatural.Text.Trim()); if (GeneID > 0) { UserLogTableAdapter logTableAdapter = new UserLogTableAdapter(); logTableAdapter.Insert(TypeUtil.Gene, GeneID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now); this.DialogResult = DialogUtil.AddSuccess(); } else { this.DialogResult = DialogUtil.AddError(); } } }
private void btnSave_Click(object sender, EventArgs e) { Int32 CorralID = ((cowBindingSource.Current as DataRowView).Row as FarmManageDataSet.CowRow).CorralID; this.Validate(); this.cowBindingSource.EndEdit(); if (1 == this.cowTableAdapter.Update(this.farmManageDataSet.Cow)) { if (CorralID != Convert.ToInt32(cbxCorral.SelectedValue)) { corralTableAdapter.UpdateRemoveCurrent(1, CorralID); corralTableAdapter.UpdateAddCurrent(1, Convert.ToInt32(cbxCorral.SelectedValue)); } var log = new UserLogTableAdapter(); log.Insert(TypeUtil.Cow, CowNO, MainForm.User.UserID, 1, DateTime.Now); DialogResult = DialogUtil.SaveSuccess(); } else { DialogResult = DialogUtil.SaveError(); } }
private void btnSave_Click(object sender, EventArgs e) { if (this.dgvAddList.Rows.Count == 0) { MessageBox.Show("ไม่มีรายการที่เพิ่มอย่างสมบูรณ์ กรุณาเพิ่มหรือป้อนข้อมูลให้ครบ"); return; } for (var i = 0; i < dgvAddList.Rows.Count; i++) { if (this.dgvAddList.Rows[i].Cells[0].Value == null || Convert.ToDouble(dgvAddList.Rows[i].Cells[1].Value) == 0) { MessageBox.Show("ข้อมูลไม่ครบ กรุณาลองใหม่อีกครั้ง", "ข้อผิดผลาก", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } var Stocks = new Dictionary <Int32, Double>(); foreach (DataGridViewRow vRow in this.dgvAddList.Rows) { var StockID = Convert.ToInt32(vRow.Cells[0].Value); var Unit = Convert.ToDouble(vRow.Cells[1].Value); if (Stocks.ContainsKey(StockID)) { Stocks[StockID] += Unit; } else { Stocks.Add(StockID, Unit); } } var Msg = new StringBuilder(); foreach (KeyValuePair <Int32, Double> Stock in Stocks) { Double?CurrentUnit = this.stockTableAdapter.QueryCurrentUnit(Stock.Key); if (CurrentUnit.Value < Stock.Value) { Msg.Append(String.Format("{0} จำนวนปัจจุบัน:{1} จำนวนที่ต้องการ:{2}\n", stockTableAdapter.GetDataByPK(Stock.Key)[0].Name, CurrentUnit, Stock.Value)); } } if (Msg.Length != 0) { MessageBox.Show(String.Format("พัสดุไม่พอ \n{0}\n กรุณาลองใหม่อีกครั้ง", Msg), "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } RemoveStockID = (int)this.stockRemoveTableAdapter.InsertQuery( Convert.ToInt32(cbxBy.SelectedValue), this.dtpDate.Value, 0, "0");//0 เบิกตามปกติ if (RemoveStockID > 0) { var log = new UserLogTableAdapter(); log.Insert(TypeUtil.StockRemove, RemoveStockID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now); var StockRemoveID = stockRemoveTableAdapter.QueryMaxID(); foreach (DataGridViewRow row in this.dgvAddList.Rows) { var result = this.stockRemoveListTableAdapter.Insert( StockRemoveID.Value, Convert.ToInt32(row.Cells[0].Value), Convert.ToDouble(row.Cells[1].Value), row.Cells[2].Value == null ? string.Empty : row.Cells[2].Value.ToString()); if (result == 1) { this.stockTableAdapter.UpdateRemoveUnit(Convert.ToDouble(row.Cells[1].Value), Convert.ToInt32(row.Cells[0].Value)); } } this.DialogResult = DialogUtil.SaveSuccess(); } else { this.DialogResult = DialogUtil.SaveError(); } }
private void btnSave_Click(object sender, EventArgs e) { btnSave.Enabled = false; pnlContent.Enabled = false; Cursor = System.Windows.Forms.Cursors.WaitCursor; if (tbxUsername.Text.Length < 5) { btnSave.Enabled = true; pnlContent.Enabled = true; Cursor = System.Windows.Forms.Cursors.Default; MessageBox.Show("ชื่อผู้ใช้ 5 อักษรขึ้นไป กรุณาลองใหม่อีกครั้ง", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning); tbxUsername.Focus(); return; } int result = (int)usersTableAdapter.CheckUsername(tbxUsername.Text.Trim()); if (result == 0) { if (!tbxPassword.Text.Trim().Equals(tbxConfirmPassword.Text.Trim())) { btnSave.Enabled = true; pnlContent.Enabled = true; Cursor = System.Windows.Forms.Cursors.Default; MessageBox.Show("รหัสผ่านไม่ตรงกัน, กรุณาลองใหม่อีกครั้ง", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { if (tbxPassword.Text.Trim().Length < 6) { btnSave.Enabled = true; pnlContent.Enabled = true; Cursor = System.Windows.Forms.Cursors.Default; MessageBox.Show("รหัสผ่านสั้นเกินไป 6 ตัวอักษรขึ้นไป, กรุณาลองใหม่อีกครั้ง", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } int UserID = (int)usersTableAdapter.InsertQuery(tbxUsername.Text.Trim(), tbxPassword.Text.Trim(), Convert.ToByte(cbxPrename.SelectedValue), tbxFirstname.Text.Trim(), tbxLastname.Text.Trim(), chkSuperUser.Checked, chkEnable.Checked, tbxEmail.Text.Trim(), tbxTel.Text.Trim()); if (UserID > 0) { UserLogTableAdapter logTableAdapter = new UserLogTableAdapter(); logTableAdapter.Insert(TypeUtil.User, UserID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now); DialogUtil.SaveSuccess(); DialogResult = System.Windows.Forms.DialogResult.Yes; } else { DialogUtil.SaveError(); DialogResult = System.Windows.Forms.DialogResult.No; } } else { btnSave.Enabled = true; pnlContent.Enabled = true; Cursor = System.Windows.Forms.Cursors.Default; MessageBox.Show("ไม่สามารถใช้ชื่อผู้ใช้นี้ กรุณาลองใหม่อีกครั้ง", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning); tbxUsername.Focus(); } }
private void btnSave_Click(object sender, EventArgs e) { if (OrderInID > 0) { this.Validate(); this.bornViewBindingSource.EndEdit(); this.fKCowOrderIn1BindingSource.EndEdit(); Int32 result = this.bornViewTableAdapter.Update(this.farmManageDataSet.BornView); if (result == 1) { this.DialogResult = DialogUtil.SaveSuccess(); } else { this.DialogResult = DialogUtil.SaveError(); } } else { OrderInID = (int)this.bornViewTableAdapter.InsertQuery( (byte?)2, Convert.ToInt32(this.cbxBy.SelectedValue), this.dtpDate.Value, this.tbxDescription.Text); if (OrderInID > 0) { var log = new UserLogTableAdapter(); log.Insert(TypeUtil.OrderIn, OrderInID.ToString(), MainForm.User.UserID, TypeUtil.EVENT_CREATE, DateTime.Now); foreach (DataGridViewRow row in this.dgvCowAdd.Rows) { Int32 tCorralID = Convert.ToInt32(row.Cells["colCorral"].Value); Int32 tGeneID = Convert.ToInt32(row.Cells["colGene"].Value); Byte tSexlID = Convert.ToByte(row.Cells["colSex"].Value); String tDesc = row.Cells["colDescription"].Value.ToString(); String CowNO = String.Format("{0:000}-{1:000}", OrderInID, Convert.ToInt32(row.Cells["colID"].Value)); CowNO = (String)this.cowTableAdapter.InsertQuery( CowNO, tCorralID, tGeneID, tSexlID, tDesc, OrderInID, 0.0, new Int32?(), new Double?()); if (CowNO != null) { log.Insert(TypeUtil.Cow, CowNO, MainForm.User.UserID, TypeUtil.EVENT_BORN, DateTime.Now); this.corralTableAdapter.UpdateAddCurrent(1, tCorralID); } } this.DialogResult = DialogUtil.AddSuccess(); } else { this.DialogResult = DialogUtil.AddError(); } } }