Example #1
0
        private void btnDEL_Click(object sender, EventArgs e)
        {
            try
            {
                string sSalesType = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridColSalesType).ToString().Trim();
                if (sSalesType == "")
                {
                    throw new Exception("Please Choose data");
                }

                DialogResult d = MessageBox.Show("Delete " + gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridColSalesType).ToString().Trim() + "?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                if (d != DialogResult.Yes)
                {
                    return;
                }

                //判断是否使用

                DAL._SalesSet dal  = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._SalesSet();
                string        sSQL = dal.Delete(sSalesType);
                int           iCou = DbHelperSQL.ExecuteSql(sSQL);

                if (iCou > 0)
                {
                    MessageBox.Show("OK");
                    GetGrid();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Example #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string sErr   = "";
            int    iCount = 0;

            try
            {
                gridView1.PostEditor();

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string   sSQL     = "select getdate()";
                    DateTime dNow     = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd"));

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        int    iID    = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColiID));
                        string iState = gridView1.GetRowCellValue(i, gridColiState).ToString().Trim();

                        if (iState == "")
                        {
                            continue;
                        }

                        Model._SalesSet model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._SalesSet();
                        model.SalesType     = gridView1.GetRowCellValue(i, gridColSalesType).ToString().Trim();
                        model.GLCode        = gridView1.GetRowCellValue(i, gridColGLCode).ToString().Trim();
                        model.Headtext      = gridView1.GetRowCellValue(i, gridColHeadtext).ToString().Trim();
                        model.Internalorder = gridView1.GetRowCellValue(i, gridColInternalorder).ToString().Trim();
                        model.ItemText      = gridView1.GetRowCellValue(i, gridColItemText).ToString().Trim();
                        model.ItemText2     = gridView1.GetRowCellValue(i, gridColItemText2).ToString().Trim();
                        model.ProfitCenter  = gridView1.GetRowCellValue(i, gridColProfitCenter).ToString().Trim();

                        model.Remark = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim();

                        if (iID == 0)
                        {
                            model.Creater    = sUserID;
                            model.CreateDate = dNowDate;

                            DAL._SalesSet dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._SalesSet();
                            sSQL   = dal.Add(model);
                            iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        else
                        {
                            model.Creater    = gridView1.GetRowCellValue(i, gridColCreateUid).ToString().Trim();
                            model.CreateDate = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColCreateDate));
                            DAL._SalesSet dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._SalesSet();
                            sSQL   = dal.Update(model);
                            iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }

                    if (sErr != "")
                    {
                        throw new Exception(sErr);
                    }

                    if (iCount > 0)
                    {
                        tran.Commit();

                        MessageBox.Show("OK");

                        GetGrid();
                    }
                    else
                    {
                        throw new Exception("no data");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }