コード例 #1
0
        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (txtpkey.Text == "")
            {
                return;
            }
            if (cur_node_typeid == "G")
            {
                MessageBox.Show("組節點不可注銷!", "提示信息");
                return;
            }

            string sql_u = string.Format(@"UPDATE sys_menu_window SET status='2' Where pkey={0}", int.Parse(txtpkey.Text));

            if (MessageBox.Show("註銷后菜單將不會出在系統菜單界面,是否要注銷此菜單?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                int result = 0;
                result = clsApp.ExecuteSqlUpdate(sql_u);
                if (result > 0)
                {
                    node_cur_selected.Remove();
                    MessageBox.Show("當前菜單項注銷成功!", "提示信息");
                }
                else
                {
                    MessageBox.Show("當前菜單項注銷失敗!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #2
0
ファイル: frmDeliveryTest.cs プロジェクト: cfmis/cfvn
        private void Save()          //保存
        {
            txtremark.Focus();
            if (!Save_Before_Valid())
            {
                return;
            }
            if (dgvDetails.RowCount == 0)
            {
                MessageBox.Show("表格明细资料不可为空 !", "提示信息");
                return;
            }
            if (!Check_Details_Valid())            //检查明细资料的有效性
            {
                return;
            }

            save_flag = false;
            myBDS1.EndEdit();
            myBDS2.EndEdit();
            dgvDetails.CloseEditor();

            #region  保存新增或編輯
            if (mState == "NEW" || mState == "EDIT")
            {
                string strSql;
                if (mState == "NEW")
                {
                    strSql = String.Format("Select '1' FROM dbo.delivery_mostly WHERE id='{0}'", txtID.Text);
                    if (clsConPad.ExecuteSqlReturnObject(strSql) != "")
                    {
                        //MessageBox.Show(string.Format("此公司数据[{0}]已存在!", txtID.EditValue));
                        //return;
                        //如已存在編號則重取最大單據編號
                        //GetID_No();
                        txtID.Text = clsConPad.ExecuteSqlReturnObject(@"Select dbo.fn_get_max_no('T') AS max_no");
                    }
                    clsConPad.ExecuteSqlUpdate(@"EXECUTE usp_set_max_no 'T'"); //更新最大单据号加1
                }
                if (txtcustomer_address.Text != "")
                {
                    strSql = string.Format(@"EXECUTE usp_update_address_history '{0}','{1}','{2}','{3}'", txtcompany_id.EditValue, txtcustomer_address.Text, txtserial_no.Text, txtserial_name.Text);
                    clsConPad.ExecuteSqlUpdate(strSql); //更新客户地址区域对照表
                }

                const string sql_i =
                    @"INSERT INTO dbo.delivery_mostly(id,delivery_date,customer_name,customer_address,contact,customer_tel,
                 customer_fax,company_id,serial_no,serial_name,amt_sum,remark,state,create_by,create_date) VALUES 
                 (@id,@delivery_date,@customer_name,@customer_address,@contact,@customer_tel,@customer_fax,
                  @company_id,@serial_no,@serial_name,@amt_sum,@remark,@state,@user_id,getdate())";
                const string sql_u =
                    @"Update dbo.delivery_mostly SET delivery_date=@delivery_date,customer_name=@customer_name,customer_address=@customer_address,
                  contact=@contact,customer_tel=@customer_tel,customer_fax=@customer_fax,company_id=@company_id,serial_no=@serial_no,
                  serial_name=@serial_name,amt_sum=@amt_sum,remark=@remark,state=@state,update_by=@user_id,update_date=getdate() 
                  WHERE id=@id";

                SqlConnection myCon = new SqlConnection(DBUtility.ConnectionString); //改爲CF01
                myCon.Open();
                SqlTransaction myTrans = myCon.BeginTransaction();
                using (SqlCommand myCommand = new SqlCommand()
                {
                    Connection = myCon, Transaction = myTrans
                })
                {
                    try
                    {
                        if (mState == "NEW")
                        {
                            myCommand.CommandText = sql_i;
                        }
                        else
                        {
                            myCommand.CommandText = sql_u;
                        }
                        myCommand.Parameters.Clear();
                        myCommand.Parameters.AddWithValue("@id", txtID.Text);
                        myCommand.Parameters.AddWithValue("@delivery_date", clsPub.Return_String_Date(dtDelivery_date.Text));
                        myCommand.Parameters.AddWithValue("@customer_name", txtcustomer_name.Text);
                        myCommand.Parameters.AddWithValue("@customer_address", txtcustomer_address.Text);
                        myCommand.Parameters.AddWithValue("@contact", txtcontact.Text);
                        myCommand.Parameters.AddWithValue("@customer_tel", txtcustomer_tel.Text);
                        myCommand.Parameters.AddWithValue("@customer_fax", txtcustomer_fax.Text);
                        myCommand.Parameters.AddWithValue("@company_id", txtcompany_id.EditValue.ToString());
                        myCommand.Parameters.AddWithValue("@serial_no", txtserial_no.EditValue.ToString());
                        myCommand.Parameters.AddWithValue("@serial_name", txtserial_name.Text);
                        myCommand.Parameters.AddWithValue("@amt_sum", clsPub.Return_Float_Value(txtamt_sum.Text));
                        myCommand.Parameters.AddWithValue("@remark", txtremark.Text);
                        myCommand.Parameters.AddWithValue("@state", "0");
                        myCommand.Parameters.AddWithValue("@user_id", DBUtility._user_id);
                        myCommand.ExecuteNonQuery();

                        //處理【項目刪除】刪除明細資料
                        bool   is_large;
                        string sql_item_d;
                        for (int i = 0; i < dtTempDel.Rows.Count; i++)
                        {
                            //刪除明細
                            sql_item_d            = @"DELETE FROM dbo.delivery_details WHERE id=@id and sequence_id=@sequence_id";
                            myCommand.CommandText = sql_item_d;
                            myCommand.Parameters.Clear();
                            myCommand.Parameters.AddWithValue("@id", txtID.Text);
                            myCommand.Parameters.AddWithValue("@sequence_id", dtTempDel.Rows[i]["sequence_id"].ToString());

                            myCommand.ExecuteNonQuery();
                        }

                        //保存明細
                        int    curRow;
                        string rowStatus;
                        if (dgvDetails.RowCount > 0)
                        {
                            const string sql_item_i =
                                @"INSERT INTO dbo.delivery_details
                                (id,sequence_id,is_large,goods_id,sec_qty,amt_total,amt_other,rmk) values(@id,@sequence_id,@is_large,@goods_id,@sec_qty,@amt_total,@amt_other,@rmk)";
                            const string sql_item_u =
                                @"Update dbo.delivery_details 
                                SET is_large=@is_large,goods_id=@goods_id,sec_qty=@sec_qty,amt_total=@amt_total,amt_other=@amt_other,rmk=@rmk 
                                Where id=@id AND sequence_id=@sequence_id";

                            for (int i = 0; i < dgvDetails.RowCount; i++)
                            {
                                curRow = dgvDetails.GetRowHandle(i);
                                //dgvDetails.AddNewRow();//新增必須初始貨當前單元格焦點
                                //否則rowStatus取不到狀態值
                                rowStatus = dgvDetails.GetDataRow(curRow).RowState.ToString();
                                if (rowStatus == "Added" || rowStatus == "Modified")
                                {
                                    myCommand.Parameters.Clear();
                                    if (rowStatus == "Added")
                                    {
                                        myCommand.CommandText = sql_item_i;
                                    }
                                    else
                                    {
                                        myCommand.CommandText = sql_item_u;
                                    }
                                    myCommand.Parameters.AddWithValue("@id", txtID.Text);
                                    myCommand.Parameters.AddWithValue("@sequence_id", dgvDetails.GetRowCellValue(curRow, "sequence_id").ToString());
                                    if (dgvDetails.GetRowCellValue(curRow, "is_large").ToString() == "True")
                                    {
                                        is_large = true;
                                    }
                                    else
                                    {
                                        is_large = false;
                                    }
                                    myCommand.Parameters.AddWithValue("@is_large", is_large);
                                    myCommand.Parameters.AddWithValue("@goods_id", dgvDetails.GetRowCellValue(curRow, "goods_id").ToString());
                                    myCommand.Parameters.AddWithValue("@sec_qty", clsPub.Return_Float_Value(dgvDetails.GetRowCellValue(curRow, "sec_qty").ToString()));
                                    myCommand.Parameters.AddWithValue("@amt_total", clsPub.Return_Float_Value(dgvDetails.GetRowCellValue(curRow, "amt_total").ToString()));
                                    myCommand.Parameters.AddWithValue("@amt_other", clsPub.Return_Float_Value(dgvDetails.GetRowCellValue(curRow, "amt_other").ToString()));
                                    myCommand.Parameters.AddWithValue("@rmk", dgvDetails.GetRowCellValue(curRow, "rmk").ToString());
                                    myCommand.ExecuteNonQuery();
                                }
                            }
                        }

                        myTrans.Commit();                         //數據提交
                        save_flag = true;
                    }
                    catch (Exception E)
                    {
                        myTrans.Rollback();                         //數據回滾
                        save_flag = false;
                        throw new Exception(E.Message);
                    }
                    finally
                    {
                        myCon.Close();
                    }
                }
            }
            #endregion

            SetButtonSatus(true);
            SetObjValue.SetEditBackColor(tabPage1.Controls, false);
            Set_Grid_Status(false);
            txtID.Properties.ReadOnly = true;
            mState = "";
            dtTempDel.Clear();

            if (save_flag)
            {
                Find_doc(txtID.Text);
                MessageBox.Show("当前数据保存成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("当前数据保存失败!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }