Example #1
0
        private void buttonSaveAdd_Click(object sender, EventArgs e)
        {
            Employee employee = new Employee(employeeId);

            if (!checkParameter())
            {
                return;
            }
            fillEmployee(employee);

            this.Enabled = false;
            MessageLocal msg = employeeDao.saveOrUpdateEmployee(employee);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Enabled = true;
                return;
            }

            if (!checkBoxIsCopy.Checked)
            {
                clearFieds();
            }

            employeeId   = -1;
            this.Enabled = true;
        }
Example #2
0
        private bool saveDepartment()
        {
            Department department = new Department(departmentId);

            if (!checkParameter())
            {
                return(false);
            }
            fillField(department);

            this.Enabled = false;
            MessageLocal msg = departmentDao.saveOrUpdateDepartment(department);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Enabled = true;
                return(false);
            }

            departmentId = -1;
            this.Enabled = true;

            return(true);
        }
Example #3
0
        private void ProductFrm_Load(object sender, EventArgs e)
        {
            labelTitle.Left = (this.Width - labelTitle.Width) / 2;

            if (!buttonQuery.Enabled)
            {
                return;
            }
            DateTime begin = DateTime.Now;

            //fill the category of product to tree view
            refreshTreeView();

            refreshDataGridView();
            ProductListHeadText();
            DateTime mid = DateTime.Now;

            Console.WriteLine("read date cost time:" + (mid - begin));

            MessageLocal msg = baseDao.fillDataGridView(Parameter.user, "tb_product", dataGridViewProd);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            DateTime end = DateTime.Now;

            Console.WriteLine("read date cost time:" + (end - mid));
        }
Example #4
0
        public MessageLocal login(User user)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams =
            {
                database.MakeInParam("@username", SqlDbType.VarChar,   20, user.Username),
                database.MakeInParam("@password", SqlDbType.VarChar,   20, user.Password),
                new SqlParameter("@message",      SqlDbType.NVarChar, 20),
                new SqlParameter("rval",          SqlDbType.Int, 4)
            };
            prams[2].Direction = ParameterDirection.Output;
            prams[3].Direction = ParameterDirection.ReturnValue;

            DataSet dataset = database.RunProcReturn("login", prams, "tb_user", CommandType.StoredProcedure);

            if (null == dataset)
            {
                msg.Message = "连接数据库时,出现错误!";
            }
            if ("0".Equals(prams[3].Value.ToString()))
            {
                user.Id      = int.Parse(dataset.Tables[0].Rows[0]["id"].ToString());
                user.Email   = dataset.Tables[0].Rows[0]["email"].ToString();
                user.Phone   = dataset.Tables[0].Rows[0]["phone"].ToString();
                user.Group   = new Group(int.Parse(getValue(dataset, "group")), getValue(dataset, "group_name"));
                msg.IsSucess = true;
            }
            msg.Message = prams[2].Value.ToString();


            return(msg);
        }
Example #5
0
        private void buttonSaveAdd_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            Product pro = new Product();

            if (0 != wrapProduct(pro))
            {
                this.Enabled = true;
                return;
            }

            MessageLocal msg = productDao.saveOrUpdateProduct(pro);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Enabled = true;
                return;
            }

            if (!checkBoxIsCopy.Checked)
            {
                clearFieds();
            }

            productId    = -1;
            this.Enabled = true;
        }
Example #6
0
        private void buttonSaveQuit_Click(object sender, EventArgs e)
        {
            User user = new User(userId);

            if (!checkParameter())
            {
                return;
            }
            fillUser(user);

            this.Enabled = false;
            MessageLocal msg = userDao.saveOrUpdateUser(user);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Enabled = true;
                return;
            }

            userId       = -1;
            this.Enabled = true;

            this.Close();
        }
Example #7
0
        SqlParameter[] constructParamsForUser(User user)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams =
            {
                database.MakeInParam("@id",          SqlDbType.Int,        0, user.Id),
                database.MakeInParam("@username",    SqlDbType.VarChar,   20, user.Username),
                database.MakeInParam("@password",    SqlDbType.VarChar,   20, user.Password),
                database.MakeInParam("@group",       SqlDbType.Int,        0, user.Group.Id),
                database.MakeInParam("@name",        SqlDbType.NVarChar,  20, user.Name),
                database.MakeInParam("@email",       SqlDbType.VarChar,   50, user.Email),
                database.MakeInParam("@phone",       SqlDbType.VarChar,   20, user.Phone),
                database.MakeInParam("@description", SqlDbType.NVarChar, 100, user.Description),
                database.MakeInParam("@isLock",      SqlDbType.Bit,        0, user.IsLock),
                database.MakeInParam("@isOnline",    SqlDbType.Bit,        0, user.IsOnline),
                database.MakeInParam("@createTime",  SqlDbType.DateTime,   0, DateTime.Now),
                new SqlParameter("@message",         SqlDbType.NVarChar, 50),
                new SqlParameter("rval",             SqlDbType.Int, 4)
            };
            prams[prams.Length - 2].Direction = ParameterDirection.Output;
            prams[prams.Length - 1].Direction = ParameterDirection.ReturnValue;

            return(prams);
        }
Example #8
0
        SqlParameter[] constructParamsForEmployee(Employee employee)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams =
            {
                database.MakeInParam("@id",            SqlDbType.Int,        0, employee.Id),
                database.MakeInParam("@name",          SqlDbType.NVarChar,  20, employee.Name),
                database.MakeInParam("@code",          SqlDbType.VarChar,   20, employee.Code),
                database.MakeInParam("@sex",           SqlDbType.Bit,        0, employee.Sex),
                database.MakeInParam("@birthday",      SqlDbType.DateTime,   0, employee.Birthday),
                database.MakeInParam("@id_card",       SqlDbType.VarChar,   20, employee.IdCard),
                database.MakeInParam("@phone",         SqlDbType.VarChar,   20, employee.Phone),
                database.MakeInParam("@join_date",     SqlDbType.DateTime,   0, employee.JoinDate),
                database.MakeInParam("@contract_date", SqlDbType.DateTime,   0, employee.ContractDate),
                database.MakeInParam("@department",    SqlDbType.Int,        0, employee.Department.Id),
                database.MakeInParam("@position",      SqlDbType.NVarChar,  20, employee.Position),
                database.MakeInParam("@address",       SqlDbType.NVarChar,  50, employee.Address),
                database.MakeInParam("@is_locked",     SqlDbType.Bit,        0, employee.IsLocked),
                new SqlParameter("@message",           SqlDbType.NVarChar, 50),
                new SqlParameter("rval",               SqlDbType.Int, 4)
            };
            prams[prams.Length - 2].Direction = ParameterDirection.Output;
            prams[prams.Length - 1].Direction = ParameterDirection.ReturnValue;

            return(prams);
        }
Example #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            messageLabel.Text = "";
            if ("".Equals(categoryName.Text))
            {
                messageLabel.Text = "类型名不能为空";
                return;
            }
            MessageLocal msg = categoryDao.saveCategory(categoryName.Text, (Category)categoryNode.Tag, table);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message + " 系统将刷新所有类型!");
                categoryFrm.refreshTreeView();
                this.Close();
                return;
            }

            // 再读一次的原因是,为了取得新创建的category的ID, 偷懒没有在saveCategory读取
            Category cop = categoryDao.getCategoryByName(categoryName.Text, table);

            if (null != cop)
            {
                TreeNode newNode = new TreeNode(categoryName.Text);
                newNode.Tag = cop;
                categoryNode.Nodes.Add(newNode);
                categoryFrm.refreshListView(categoryNode);
            }
            else
            {
                MessageBox.Show("该类型【" + categoryName.Text + "】被删除,系统将刷新所有类型!");
                categoryFrm.refreshTreeView();
            }
            this.Close();
        }
Example #10
0
        private void 保存订单NToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            if (!checkParameterForOrder())
            {
                this.Enabled = true;
                return;
            }

            Order        order = getOrder();
            MessageLocal msg   = purchaseOrderDao.saveOrUpdatePurchaseOrder(order);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Console.WriteLine("526 purchase msg.Message: " + msg.Message);
            }
            else
            {
                textBoxSN.Text = order.Sn;
                orderID        = order.Id;

                int i = 0;
                foreach (OrderItem item in order.OrderItems)
                {
                    dataGridViewItem.Rows[i++].Cells["ColumnItemID"].Value = item.Id;
                }
                i = 0;
                foreach (OrderStats stats in order.OrderStats)
                {
                    dataGridViewItemStats.Rows[i++].Cells["ColumnStatsID"].Value = stats.Id;
                }
            }
            this.Enabled = true;
        }
Example #11
0
        public MessageLocal saveOrUpdateWarehouse(Warehouse warehouse)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams = constructParamsForWarehouse(warehouse);

            return(baseDao.runProcedure("saveOrUpdate_warehouse", prams, "warehouse"));
        }
Example #12
0
        public MessageLocal saveOrUpdateUser(User user)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams = constructParamsForUser(user);

            return(baseDao.runProcedure("saveOrUpdate_user", prams, "user"));
        }
Example #13
0
        public MessageLocal saveOrUpdateEmployee(Employee employee)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams = constructParamsForEmployee(employee);

            return(baseDao.runProcedure("saveOrUpdate_employee", prams, "employee"));
        }
Example #14
0
        public MessageLocal saveOrUpdateDepartment(Department department)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams = constructParamsForDepartment(department);

            return(baseDao.runProcedure("saveOrUpdate_department", prams, "department"));
        }
Example #15
0
        public int deleteCategoryRecursive(Category cur, string table)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams =
            {
                database.MakeInParam("@id", SqlDbType.Int, 0, cur.Id),
            };

            return(database.RunProc("del_" + table, prams, CommandType.StoredProcedure));
        }
Example #16
0
        // 在传入table参数的时候,记得runProcedu自动在table前面加了tb_前缀。
        public MessageLocal runProcedureTran(string procedure, SqlParameter[] prams, string table, SqlTransaction sqlTran)
        {
            MessageLocal msg     = new MessageLocal();
            DataSet      dataset = database.RunProcReturnTran(procedure, prams, "tb_" + table, CommandType.StoredProcedure, sqlTran);

            if ("0".Equals(prams[prams.Length - 1].Value.ToString()))
            {
                msg.IsSucess = true;
            }
            msg.Message = prams[prams.Length - 2].Value.ToString();
            return(msg);
        }
Example #17
0
        private void 保存表格EToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            MessageLocal msg = baseDao.saveOrUpdateDataGridView(Parameter.user, "tb_image", dataGridViewImage);

            this.Enabled = true;

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #18
0
        private void PurchaseOrderFrm_Load(object sender, EventArgs e)
        {
            labelTitle.Left = (this.Width - labelTitle.Width) / 2;
            initField();

            MessageLocal msg = baseDao.fillDataGridView(Parameter.user, "tb_order_item", dataGridViewItem);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #19
0
        private void buttonSaveTable_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            MessageLocal msg = baseDao.saveOrUpdateDataGridView(Parameter.user, "tb_order_item", dataGridViewItem);

            this.Enabled = true;

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #20
0
        private void DepartmentFrm_Load(object sender, EventArgs e)
        {
            refreshDataGridView();
            departmentListHeadText();

            MessageLocal msg = baseDao.fillDataGridView(Parameter.user, TB_NAME, dataGridViewDepartment);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #21
0
        private void button5_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            MessageLocal msg = baseDao.saveOrUpdateDataGridView(Parameter.user, TB_NAME, dataGridViewDepartment);

            this.Enabled = true;

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #22
0
        private void ImageFrm_Load(object sender, EventArgs e)
        {
            refreshDataGridViewImage();
            ImageListHeadText();

            MessageLocal msg = baseDao.fillDataGridView(Parameter.user, "tb_image", dataGridViewImage);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #23
0
        private void EmployeeFrm_Load(object sender, EventArgs e)
        {
            labelTitle.Left = (this.Width - labelTitle.Width) / 2;
            refreshDataGridView();
            listHeadText();

            MessageLocal msg = baseDao.fillDataGridView(Parameter.user, TABLE_NAME, dataGridViewEmployee);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #24
0
        private void UserFrm_Load(object sender, EventArgs e)
        {
            labelTitle.Left             = (this.Width - labelTitle.Width) / 2;
            dataGridViewUser.DataSource = userDao.getAllUser(textBoxQuery.Text).Tables[0].DefaultView;
            ProductListHeadText();


            MessageLocal msg = baseDao.fillDataGridView(Parameter.user, "tb_user", dataGridViewUser);

            if (!msg.IsSucess)
            {
                MessageBox.Show(msg.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #25
0
        public MessageLocal saveOrUpdateDataGridView(User user, string table, DataGridView dataGridView)
        {
            MessageLocal   msg     = new MessageLocal();
            SqlConnection  con     = SessionFactory.getConnection();
            SqlTransaction sqlTran = con.BeginTransaction(IsolationLevel.RepeatableRead);

            try
            {
                int tableID = getTableIDByName(table, sqlTran);
                if (tableID < 0)
                {
                    msg.Message = "该表格的信息已经被删除,无法更改";
                    sqlTran.Commit();
                    return(msg);
                }

                int i = 0;
                for (i = 0; i < dataGridView.Columns.Count; i++)
                {
                    SqlParameter[] prams =
                    {
                        database.MakeInParam("@user",           SqlDbType.Int, 0, user.Id),
                        database.MakeInParam("@table",          SqlDbType.Int, 0, tableID),
                        database.MakeInParam("@original_index", SqlDbType.Int, 0, i),
                        database.MakeInParam("@display_index",  SqlDbType.Int, 0, dataGridView.Columns[i].DisplayIndex),
                        database.MakeInParam("@width",          SqlDbType.Int, 0, dataGridView.Columns[i].Width),
                        database.MakeInParam("@sort",           SqlDbType.Int, 0,                                    0),
                    };
                    // MessageBox.Show("original:[" + i + "] display:[" + dataGridView.Columns[i].DisplayIndex + "]");
                    database.RunProcTran("saveOrUpdate_table", prams, CommandType.StoredProcedure, sqlTran);
                }
                sqlTran.Commit();
            }
            catch (Exception e)
            {
                sqlTran.Rollback();
                MessageBox.Show(e.Message);
                msg.IsSucess = false;
                msg.Message  = "在保存表格样式时,出现错误!";
                return(msg);
            }
            finally
            {
                con.Close();
            }
            msg.IsSucess = true;
            return(msg);
        }
Example #26
0
        public MessageLocal updateCategoryByName(string name, Category cur, string table)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams =
            {
                database.MakeInParam("@id",   SqlDbType.Int,                       0, cur.Id),
                database.MakeInParam("@name", SqlDbType.NVarChar, Category.NAME_SIZE, name),
                new SqlParameter("@message",  SqlDbType.NVarChar,                20),
                new SqlParameter("rval",      SqlDbType.Int, 4)
            };

            prams[2].Direction = ParameterDirection.Output;
            prams[3].Direction = ParameterDirection.ReturnValue;

            return(baseDao.runProcedure("update_" + table, prams, table));
        }
Example #27
0
        public SqlParameter[] constructParamsForDepartment(Department department)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams =
            {
                database.MakeInParam("@id",          SqlDbType.Int,        0, department.Id),
                database.MakeInParam("@name",        SqlDbType.VarChar,   20, department.Name),
                database.MakeInParam("@description", SqlDbType.VarChar,  100, department.Description),
                new SqlParameter("@message",         SqlDbType.NVarChar, 50),
                new SqlParameter("rval",             SqlDbType.Int, 4)
            };
            prams[prams.Length - 2].Direction = ParameterDirection.Output;
            prams[prams.Length - 1].Direction = ParameterDirection.ReturnValue;

            return(prams);
        }
Example #28
0
        public MessageLocal deleteEntities(string table, string ids)
        {
            MessageLocal msg = new MessageLocal();

            try
            {
                database.RunProc("DELETE FROM " + table + " WHERE id IN (" + ids + ")");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                msg.Message = e.Message;
                return(msg);
            }
            msg.IsSucess = true;
            return(msg);
        }
Example #29
0
        private void buttonSure_Click(object sender, EventArgs e)
        {
            labelErrStatus.Text = "";

            if ("".Equals(textBoxName.Text) || (null == comboBoxUnit.SelectedItem && "".Equals(comboBoxUnit.Text)))
            {
                if ("".Equals(textBoxName.Text))
                {
                    labelErrStatus.Text += "【加工名称】 ";
                }
                if (null == comboBoxUnit.SelectedItem && "".Equals(comboBoxUnit.Text))
                {
                    labelErrStatus.Text += "【单位】 ";
                }
                labelErrStatus.Text += ",不能为空!";
                return;
            }


            TypeOfProcess typeOfProcess = new TypeOfProcess();

            typeOfProcess.Id   = typeOfProcessId;
            typeOfProcess.Name = textBoxName.Text;

            if (null != comboBoxUnit.SelectedItem)
            {
                typeOfProcess.Unit = comboBoxUnit.SelectedItem.ToString();
            }
            else
            {
                if (!"".Equals(comboBoxUnit.Text))
                {
                    typeOfProcess.Unit = comboBoxUnit.Text;
                }
            }

            MessageLocal msg = typeOfProcessDao.saveOrUpdateTypeOfProcess(typeOfProcess);

            if (!msg.IsSucess)
            {
                labelErrStatus.Text = msg.Message;
                return;
            }
            this.Close();
        }
Example #30
0
        private int getTableIDByName(string table)
        {
            MessageLocal msg = new MessageLocal();

            SqlParameter[] prams =
            {
                database.MakeInParam("@name", SqlDbType.VarChar, 50, table)
            };

            DataSet dataset = database.RunProcReturn("SELECT id FROM tb_table WHERE (name = @name)", prams, "tb_table", CommandType.Text);

            if (null != dataset && dataset.Tables[0].Rows.Count > 0)
            {
                return(int.Parse(dataset.Tables[0].Rows[0]["id"].ToString()));
            }

            return(-1);
        }