Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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;
        }