/// <summary> /// 可復寫,也可用dgv 事件 /// </summary> public override void CellValidated(object sender, DataGridViewCellEventArgs e) { DataGridView dgv = (DataGridView)sender; if (dgv.Name.ToLower() == "dgview1") { if (e.ColumnIndex == this.Column2.Index) { //檢查是否有重複 if (Exists(dgv)) { MessageBox.Show("對不起,此編號已經存在!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); dgv.EditingControl.Text = "" + histroyValue; dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = histroyValue; return; } Js.BLL.BaseDal dal = new Js.BLL.BaseDal("BU_Enterprise"); string filter = string.Format("EnterpriseID='{0}'", dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value); DataTable dt = dal.GetRecord(filter); if (dt.Rows.Count > 0) { dgv.Rows[e.RowIndex].Cells[this.Column3.Index].Value = dt.Rows[0]["EnterpriseName"].ToString(); } } } }
private void frmLabelNoDbView_Load(object sender, EventArgs e) { Js.BLL.BaseDal dal = new Js.BLL.BaseDal(FormID); string filter = string.Format("DbName='{0}'", DbName); dt = dal.GetRecord(filter); BindData(dt); }
private void btnSave_Click(object sender, EventArgs e) { if (this.txtUserName.Text.Trim() == "") { MessageBox.Show("請輸入登入帳號!", "存檔", MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtUserName.Focus(); return; } if (dtsub[0].Rows.Count <= 0) { MessageBox.Show("明細不能為空!", "存檔", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } for (int i = 0; i < dgView1.Rows.Count; i++) { if (dgView1.Rows[i].IsNewRow) continue; if (dgView1.Rows[i].Cells[1].Value.ToString().Trim() == "") { MessageBox.Show("企業編號不能為空!", "存檔", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else if(dgView1.Rows[i].Cells[2].Value.ToString().Trim() == "") { MessageBox.Show("企業編號不存在!", "存檔", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } Js.BLL.BaseDal dal = new Js.BLL.BaseDal(FormID); if (UserName.Length > 0 && this.txtUserName.Text.Trim() != UserName || UserName.Length <= 0) { if (dal.Exists(this.txtUserName.Text.Trim())) { MessageBox.Show("此登入帳號已經存在,請選取其他登入帳號!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } DataTable dt = dal.GetRecord("1=1"); DataRow dr = dt.NewRow(); dr["UserName"] = this.txtUserName.Text.Trim(); dr["PersonName"] = this.txtPersonName.Text.Trim(); dr["PersonID"] = this.txtPersonID.Text.Trim(); dr["CreateUserName"] = Js.Com.User.UserID; if (UserName.Length > 0) dr["CreateDate"] = this.txtCreateDate.Text; else dr["CreateDate"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); dr["LastModifyUserName"] = Js.Com.User.UserID; dr["LastModifyDate"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); dr["CheckUserName"] = this.txtCheckUserName.Text; if (this.txtCheckDate.Text.Length > 0) dr["CheckDate"] = this.txtCheckDate.Text; if (UserName.Length > 0) dal.Update(dr, UserName); else dal.Add(dr); dgView1.Update(); for (int i = 0; i < dtsub[0].Rows.Count; i++) { if (dgView1.Rows[i].IsNewRow) { dtsub[0].Rows.RemoveAt(i); } else { dtsub[0].Rows[i]["UserName"] = this.txtUserName.Text; } } dal.SaveDetail(dtsub, UserName); this.DialogResult = System.Windows.Forms.DialogResult.OK; }
private void txtUserName_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.txtUserName.Text = this.txtUserName.Text.Trim(); Js.BLL.BaseDal dal = new Js.BLL.BaseDal("BU_User"); string filter = string.Format("UserName='******'", this.txtUserName.Text); DataTable dt = dal.GetRecord(filter); if (dt.Rows.Count > 0) { this.txtUserName.Text = dt.Rows[0]["UserName"].ToString(); this.txtPersonID.Text = dt.Rows[0]["PersonID"].ToString(); this.txtPersonName.Text = dt.Rows[0]["PersonName"].ToString(); } } }
private void frmUserManagerEdit_Load(object sender, EventArgs e) { Js.BLL.BaseDal dal = new Js.BLL.BaseDal(FormID); if (UserName.Length > 0) { string filter = string.Format("UserName='******'", UserName); DataTable dt = dal.GetRecord(filter); BindData(dt); } else { this.txtLastModifyUserName.Text = Js.Com.User.UserID; this.txtLastModifyDate.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); this.txtCreateUserName.Text = Js.Com.User.UserID; this.txtCreateDate.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); } dtsub = new DataTable[1]; dtsub[0] = dal.GetSubDetail(this.txtUserName.Text.Trim()).Tables[0]; BindGridEventDoFormat(); BindGridView(); dgView1.Columns[2].ReadOnly = true; }
private void frmfrmEnterpriseDbEdit_Load(object sender, EventArgs e) { BindComboBox(); if (EnterpriseID.Length>0) { Js.BLL.BaseDal dal = new Js.BLL.BaseDal(FormID); string filter = string.Format("EnterpriseID='{0}'", EnterpriseID); DataTable dt = dal.GetRecord(filter); BindData(dt); } else { this.txtState.Text = "未開立"; this.txtLastModifyUserName.Text = Js.Com.User.UserID; this.txtLastModifyDate.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); this.txtCreateUserName.Text = Js.Com.User.UserID; this.txtCreateDate.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); } }
private void btnSave_Click(object sender, EventArgs e) { if (this.txtEnterpriseID.Text.Trim() == "") { MessageBox.Show("請輸入企業編號!", "存檔", MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtEnterpriseID.Focus(); return; } if (this.txtSQLServer.Text.Trim() == "") { MessageBox.Show("請輸入SQL Server名稱!", "存檔", MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtSQLServer.Focus(); return; } if (this.txtDbDataPath.Text.Trim() == "") { MessageBox.Show("請輸入資料庫存放路徑!", "存檔", MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtDbDataPath.Focus(); return; } //Js.BLL.Sys.SysComDal sdal = new Js.BLL.Sys.SysComDal(); //if (!sdal.OpenConnection(this.txtSQLServer.Text, this.txtDbName.Text, "", "", true)) //{ // MessageBox.Show("因在初始化提供者時遭遇錯誤,測試連接失敗。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} if(!System.IO.Directory.Exists(this.txtDbDataPath.Text.Trim())) { MessageBox.Show("資料庫路徑不存在或無法存取,請確認!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Js.BLL.BaseDal dal = new Js.BLL.BaseDal(FormID); if (EnterpriseID.Length > 0 && this.txtEnterpriseID.Text.Trim() != EnterpriseID || EnterpriseID.Length <= 0) { if (dal.Exists(this.txtEnterpriseID.Text.Trim())) { MessageBox.Show("此企業編號已經存在,請選取其他企業編號!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } if (!blnExists) { MessageBox.Show("此企業編號不存在,請選取其他企業編號!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Js.BLL.Sys.SysComDal SysComDal = new Js.BLL.Sys.SysComDal(); if (!SysComDal.OpenConnection(this.txtSQLServer.Text, "master", "", "", true)) { MessageBox.Show("因在初始化提供者時遭遇錯誤,測試連接失敗。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DataTable dt = dal.GetRecord("1=1"); DataRow dr = dt.NewRow(); dr["EnterpriseID"] = this.txtEnterpriseID.Text.Trim(); dr["EnterpriseName"] = this.txtEnterpriseName.Text.Trim(); dr["SQLServer"] = this.txtSQLServer.Text.Trim(); dr["DbDataPath"] = this.txtDbDataPath.Text.Trim(); dr["DbName"] = "SD" + this.txtEnterpriseID.Text.Trim(); dr["UserName"] = "******"; //if (this.txtState.Text == "未啟用") dr["State"] = 0; //else // dr["State"] = 1; dr["ManageGroup"] = this.cmbManageGroup.Text; dr["Memo"] = this.txtMemo.Text.Trim(); dr["CreateUserName"] = Js.Com.User.UserID; if (EnterpriseID.Length > 0) dr["CreateDate"] = this.txtCreateDate.Text; else dr["CreateDate"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); dr["LastModifyUserName"] = Js.Com.User.UserID; dr["LastModifyDate"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); dr["CheckUserName"] = this.txtCheckUserName.Text; if (this.txtCheckDate.Text.Length > 0) dr["CheckDate"] = this.txtCheckDate.Text; if (EnterpriseID.Length > 0) dal.Update(dr, EnterpriseID); else dal.Add(dr); this.DialogResult = System.Windows.Forms.DialogResult.OK; }