예제 #1
0
        public OperationsModel Update(OperationsModel model)
        {
            try
            {
                string query = @"UPDATE Operations SET 
                OperationsName =@OperationsName 
                ,OperationsDescription = @OperationsDescription
                WHERE OperationsId = @OperationsId";

                List <SqlParameter> param = new List <SqlParameter>();
                param.Add(new SqlParameter("@OperationsId", model.OperationsId));
                param.Add(new SqlParameter("@OperationsName", model.OperationsName));
                param.Add(new SqlParameter("@OperationsDescription", model.OperationsDescription));

                fun.OpenConnection();
                if (fun.getConnection().State == System.Data.ConnectionState.Open)
                {
                    fun.ExecuteQueryWithParameters(query, param, "Yes");

                    if (model.OperationsId > 0)
                    {
                        foreach (OperationTypeModel item in model.OperationTypes)
                        {
                            if (item.OprId == 0)
                            {
                                query = @"INSERT INTO OperationsType(OperationsId, OprName) 
                                OUTPUT Inserted.OprId
                                VALUES(@OperationsId, @OprName)";
                                List <SqlParameter> p = new List <SqlParameter>();
                                p.Add(new SqlParameter("@OperationsId", model.OperationsId));
                                p.Add(new SqlParameter("@OprName", item.OprName));

                                item.OprId = fun.ExecuteQueryWithParameters(query, p, "Yes");
                            }
                            else
                            {
                                query = @"UPDATE OperationsType SET 
                                OperationsId = @OperationsId, 
                                OprName = @OprName WHERE OprId = @OprId";
                                List <SqlParameter> p = new List <SqlParameter>();
                                p.Add(new SqlParameter("@OperationsId", model.OperationsId));
                                p.Add(new SqlParameter("@OprName", item.OprName));
                                p.Add(new SqlParameter("@OprId", item.OprId));

                                fun.ExecuteQueryWithParameters(query, p);
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Please check network connection");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
예제 #2
0
        public OperationsModel GetOperation(int OperationsId)
        {
            OperationsModel model = new OperationsModel();

            model.OperationTypes = new List <OperationTypeModel>();
            try
            {
                string query = String.Format(@"SELECT [OperationsId]
                                  ,[OperationsName]
                                  ,[OperationsDescription]
                              FROM [Operations] WHERE [OperationsId] = {0};
                                SELECT [OprId]
                                  ,[OperationsId]
                                  ,[OprName]
                              FROM [OperationsType] WHERE [OperationsId] = {0}", OperationsId);
                fun.OpenConnection();
                if (fun.getConnection().State == ConnectionState.Open)
                {
                    DataSet ds = fun.fillComboDataset(query);
                    if (ds.Tables.Count == 2)
                    {
                        foreach (DataRow item in ds.Tables[0].Rows)
                        {
                            model.OperationsDescription = item["OperationsDescription"].ToString();
                            model.OperationsId          = OperationsId;
                            model.OperationsName        = item["OperationsName"].ToString();
                        }
                        foreach (DataRow item in ds.Tables[1].Rows)
                        {
                            model.OperationTypes.Add(new OperationTypeModel()
                            {
                                OperationsId = OperationsId,
                                OprId        = Convert.ToInt32(item["OprId"].ToString()),
                                OprName      = item["OprName"].ToString()
                            });
                        }
                    }
                }
                else
                {
                    throw new Exception("Please check network connection");
                }
                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }