⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clsproduct.cpp

📁 用户名:liuxinrui 密码:zhongyong 您可以在 linux 系统上运行 main.exe 文件 IP 应设为192.168.0.1 重新编译请在linux终端提示符后输
💻 CPP
字号:
/***********************************
*  模块名称:clsProduct.cpp        *
*  模块功能: clsProduct  类 类体   *
*  作者:刘鑫锐                    *
*  撰写日期:2005-9-15             *
***********************************/
#include <iostream.h>           
#include <stdlib.h>             
#include "head/clsProduct.h"  //调用 clsProduct类声明  头文件
#include "head/clsTrade.h"    //调用 clsTrade 类声明 头文件 
#include "head/clsConn.h"     //调用 clsConn 类声明  头文件 
#include "head/clsMain.h"     //调用 clsMain 类声明  头文件 

void clsProduct::dispProdMenu()      //Product 信息管理 主菜单 
{
    system("clear"); 
    char choice;    //定义接收选择的变量 
    while(1)
    {
        system("clear");
        cout << endl << "\t\t   ********************************************" << endl;
        cout << endl << "\t\t   *           PRODUCT MIS MAIN MENU          *" << endl;
        cout << endl << "\t\t   ********************************************" << endl;
        cout << endl << "\t\t   ***  1) PROUCT INFORMATION LIST          ***" << endl;
        cout << endl << "\t\t   ***  2) PROUCT INFO FOR NEED STORAGE     ***" << endl;
        cout << endl << "\t\t   ***  3) PROUCT INFORMATION INSERT        ***" << endl;
        cout << endl << "\t\t   ***  4) PROUCT INFORMATION UPDATE/DELETE ***" << endl;
        cout << endl << "\t\t   ***  5) RETURN MAIN MENU                 ***" << endl;
        cout << endl << "\t\t   ********************************************" << endl;
        cout << endl << "\t\t   ********************************************" << endl;
        cout << endl << "\t\t   Please enter your choice : ";
        
        cin >> choice;           //输入选择
        switch(choice)           //根据选择,执行相关的操作 
        {
                case '1':
                {
                       system("clear");
                       clsProduct obj;               //创建对象
                       obj.listProdInfo();           //列表显示产品信息
                       break;
                }
                case '2':
                {
                       system("clear");
                       clsProduct obj;               //创建对象
                       obj.NeedOrder();            //列表显示需要定货的产品信息 
                       break;
                }
                
                case '3':
                {
		               system("clear");
		               clsProduct obj;               //创建对象
                       obj.addProdInfo();            //添加产品信息                               
                       break;
                }
                case '4':
                {
                       system("clear");
                       clsProduct obj;               //创建对象
                       obj.queryProdInfo();          //先查询产品信息 ,再进行修改和删除操作 
                       break;
                }
                case '5':				
                {
                       system("clear");
                       clsMain obj;                      
                       obj.mainlist();               //返回主菜单
                       break; 
                }
                default:
                {
                       system("clear");
                       clsMain obj;                       
                       obj.error();                  //显示错误信息 
                       break;
                }
        }
    }
}

void clsProduct::listProdInfo()                       //产品信息列表 
{
    clsConn obj;
    char ListString[1024];
    sprintf(ListString,"select * from Product ");
    obj.ClistInfo(ListString);
}

void clsProduct::NeedOrder()                       //需要定货的产品信息列表 
{
    char choice;
    system("clear");
    cout << "\n\n\n\n";
    cout << endl << "\t\t *****************************************";
    cout << endl << "\t\t *           QUERY STORAGE BEGIN         *";
    cout << endl << "\t\t *****************************************";
    cout << endl << "\t\t ASK:" << endl;
    cout << endl << "\t\t Your can query storage all and need order!\n";
    cout << endl << "\t\t --Query all Product storage,please enter A:  \n";       //查询全部产品的库存列表 
    cout << endl << "\t\t --Query need order product storage,please enter B:\n";  //查询要定货的产品库存列表 
    cout << endl << "\t\t --Other key will begin stock product:  \n";             //按其他键 则直接开始采购 
    cout << endl << "\t\t ANSWER:";
    cin >> choice;
    cout << endl;
    if(choice=='A' || choice=='a')
    {
        clsConn obj;
        char ListString[1024];
        sprintf(ListString,"exec proc_ProductInfo");
        obj.ClistInfo(ListString);
    }
    else if(choice=='B' || choice=='b')
    {
        clsConn obj;
        char ListString[1024];
        sprintf(ListString,"exec proc_NeedOrder");
        obj.ClistInfo(ListString);
        
    }
    else
    {
        clsTrade obj;
        obj.addTradeInfo();
    }
}

void clsProduct::addProdInfo()                       //添加产品信息 
{
    system("clear");
    cout << "\n\n";
    clsConn obj;
    char InsertString[1024];
        cout << endl << "\t\t *****************************************";
        cout << endl << "\t\t *              INSERT BEGIN             *";    //向数据库写入产品信息 
        cout << endl << "\t\t *****************************************";
        cout << endl << "\t\t Please enter ProductName:";
        cin >> ProductName;
        cout << endl << "\t\t Please enter ProductMetric:";
        cin >> Metric;
        cout << endl << "\t\t Please enter Product safe value:";
        cin >> SafeValue;
        sprintf(InsertString,"insert into Product (vProductName,cMetric,fSafeValue) values ('%s','%s',%f)",ProductName,Metric,SafeValue);
    
    obj.Cwork(InsertString);         
}

void clsProduct::queryProdInfo()                        //查询产品信息 
{
       char choice;
       system("clear");
       cout << "\n\n\n\n";
       cout << endl << "\t\t *****************************************";
       cout << endl << "\t\t *       QUERY,UPDATE,DELETE BEGIN       *";
       cout << endl << "\t\t *****************************************";
       cout << endl << "\t\t ASK:" << endl;
       cout << endl << "\t\t Your can use ProductId or ProductName for Query Product!\n";
       cout << endl << "\t\t --Use ProductId Query,please enter A:  \n";       //根据产品的Id查询 
       cout << endl << "\t\t --Use ProductName Query,please enter B:\n";       //根据产品的Name查询 
       cout << endl << "\t\t --Other key will begin delete/update:  \n";       //按其他键 则直接开始修改、删除操作
       cout << endl << "\t\t ANSWER:";
       cin >> choice;
       cout << endl;
       
        if(choice=='A' || choice=='a')
        {
                cout << "\t\t Please enter Product Id :";                     
                cin >> ProductId;                                //按产品ID查询 
                clsConn obj;
                char QueryString[1024]; 
                sprintf(QueryString,"select * from Product where iProductId = '%d'",ProductId);
                obj.ClistInfo(QueryString);
        }
       else if(choice=='B' || choice=='b')
        {
                cout << "\t\t Please enter Product Name :";                
                cin >> ProductName;                                //按产品名称查询 
                clsConn obj;
                char QueryString[1024];  
                sprintf(QueryString,"select * from Product where vProductName = '%s'",ProductName);
                obj.ClistInfo(QueryString);
        }
       else
        {
		        clsMain obj;
                obj.error();                //错误提示                                               
        }
        
        cout << endl << "\t\t Will your begin Delete or Update operate?[Y/N]";
        cout << endl << "\t\t **ANSWER:";
        char answer;
        cin >> answer;
        if(answer=='Y' || answer=='y')
        {
              cout << endl << "\t\t *****************************************";
              cout << endl << "\t\t --Begin Delete operate,please enter A:\n";
              cout << endl << "\t\t --Begin Update operate,please enter B:\n";
              cout << endl << "\t\t **ANSWER:";
              char ch;
              cin >> ch;
              if(ch=='A' || ch=='a')
              {
                            clsProduct obj;
                            obj.deleteProdInfo();              //删除产品信息                       
              }
              else if(ch=='B' || ch=='b')
              {
                            clsProduct obj;
                            obj.updateProdInfo();              //修改产品信息 
              }
              else
              {
                            clsMain obj;
                            obj.error();                       //错误提示 
              }  
        } 
        
}

void clsProduct::deleteProdInfo()                              //删除产品信息 
{
    cout << "\n\n";
    cout << endl << "\t\t *****************************************";
    cout << endl << "\t\t *             DELETE BEGIN              *";
    cout << endl << "\t\t *****************************************";
    cout << endl << "\t\t IF your are will delete row,please enter ProductId:";
    cin >> ProductId;
    clsConn obj;
    char DeleteString[1024];
    sprintf(DeleteString,"delete Product where iProductId = %d",ProductId);
    obj.Cwork(DeleteString);
}

void clsProduct::updateProdInfo()                               //修改产品信息 
{
    cout << "\n\n";
    cout << endl << "\t\t *****************************************";
    cout << endl << "\t\t *             UPDATE BEGIN              *";
    cout << endl << "\t\t *****************************************";
    cout << endl << "\t\t --Please enter ProductId for update:";
    cin >> ProductId;
    cout << endl << "\t\t --Please enter will update field count:";
    int count;
    cin >> count;        //输入要修改的字段个数 
    int i;
    for(i=1;i<=count;i++)
    {
        system("clear");
        clsConn obj;
        cout << endl << "\t\t *************************************";
        cout << endl << "\t\t      You can update these fields     ";
        cout << endl << "\t\t  1)ProductName,2)Metric,3)SafeValue  ";
        cout << endl << "\t\t *************************************\n";
        cout << endl << "\t\t --Please enter field number for update:";
        char FieldNumber;
        cin >>FieldNumber;                //输入要修改的那个字段的编号 
        char *FieldName;
        switch(FieldNumber)
        {
                case '1':
                {
                    FieldName = "vProductName";           
                    break;
                }
                case '2':
                {
                    FieldName = "cMetric"; 
                    break;
                }
                case '3':
                {
                    FieldName = "fSafeValue";
                    break;
                }
                default:
                {
                    cout << endl << "\t\t *    Without this Field    *";
                    break;
                }
        } 
        cout << endl << "\t\t --Please enter new value:";
        char NewValue[101];
        cin >> NewValue;
        char UpdateString[1024];
        sprintf(UpdateString,"update Product set %s='%s' where iProductId=%d",FieldName,NewValue,ProductId);
        obj.Cwork(UpdateString);
    }
}        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -