wangjianlin2008 发表于 2008-9-9 18:20

课程设计题目: 销售管理系统

/**
  C语言课程设计题目: 服装销售管理系统

  系统要求: 包含三类用户,管理员,店长,销售员
                管理员功能:                       
                                (1)自身密码修改
                                (2)用户信息管理:添加,修改,查询,删除
                                (3)商品信息管理:添加,修改,查询,删除
                                (4)销售报表显示:日报表,月报表,商品销售量报表,销售员业绩报表
                                (5)退出登陆系统
                店长功能:
                                (1)自身密码修改
                                (2)商品信息管理:添加,修改,查询,删除
                                (3)销售报表显示:日报表,月报表,商品销售量报表,销售员业绩报表
                                (4)退出登陆系统
                销售员功能:
                                (1)商品查询浏览,商品销售
                                (2)自己销售报表显示:日报表,月报表
                                (3)退出登陆系统
**************************************************
        程序作者: 双鱼林  作者真实姓名:  汪建林
        生日: 1985年2月26日 星座: 双鱼座
        血型: 0  家乡: 四川达州
        QQ: 287307421 手机:13558690869
***************************************************
**/

#include <stdio.h>
#include <windows.h>
#include <time.h>

#define ADMIN_USER_TYPE 1
#define BOSS_USER_TYPE 2
#define SELL_USER_TYPE 3


#define FUNCTION_FAILED -1
#define FUNCTION_SUCCESS 0

/** 系统用户结构 **/
typedef struct SystemUser {
        char userName[20];                                                //用户名,主键
        char password[20];                                                //用户密码
        int  userType;                                                                //用户类型(1:管理员;2:店长;3:销售员)
        struct SystemUser *next;                        //指向下一个用户的指针
} SystemUser;

/** 服装商品信息 **/
typedef struct Products {
        int productId;                                                                //商品编号,主键
        char productName[20];                                        //商品名称
        char productType[20];                                        //商品型号
        char productCompany[20];                        //商品厂家
        float productPrice;                                                //商品价格
        int productCount;                                                        //商品数量
        char memo[50];                                                                //商品附加信息
        struct Products *next;                                //指向下一个商品的指针
} Products;

/** 销售记录信息结构 **/
typedef struct SellInfoRecord {
        int saleId;                                                                                //销售编号,主键
        char userName[20];                                                //销售商品的用户名
        int productId;                                                                //销售的商品编号
        int sellCount;                                                                //销售数量
        int year;                                                                                        //销售商品年份
        int month;                                                                                //销售商品月份
        int day;                                                                                        //销售商品日期
        char memo[50];                                                                //销售的附加信息
        struct SellInfoRecord *next;        //下一条销售记录
} SellInfoRecord;

static char currentUser[20];                                                                        //系统全局变量,保存当前登陆用户名;
static int currentUserType;                                                                                //系统全局变量,保存当前登陆用户的用户类型

static SystemUser *pSystemUserHead = NULL;                //保存系统用户信息记录的头指针
static Products *pProductHead = NULL;                                        //保存系统商品信息记录的头指针
static SellInfoRecord *pSellInfoHead = NULL;        //保存系统销售记录的头指针

void InitSystem();                                                                                //对系统用户信息和商品信息进行初始化
int AddUser(SystemUser *);                                                //向用户信息链表中加入用户信息
int AddProduct(Products *pPro);                        //向商品信息链表中加入商品信息
int AddSellInfo(SellInfoRecord *);
void WelcomeMenu();                                                                                //系统欢迎菜单
void SystemLogin();                                                                                //系统登陆
void AdminOperationMenu();                                                //系统管理员操作菜单
void BossOperationMenu();                                                        //店长操作菜单
void SellOperationMenu();                                                        //销售员操作菜单
void ChangePassword();                                                                //修改密码
void UserManage();                                                                                //用户信息管理
        void UserInfoView();                                                                //用户信息查看
        void UserInfoAdd();                                                                        //用户信息添加
        void UserInfoModify();                                                        //用户信息修改
        void UserInfoDelete();                                                                //用户信息删除
void ProductsManage();                                                                //产品信息管理
        void ProductsView();                                                                //商品查看
        void ProductFind();
        void InputAndAddProduct();                                        //输入商品信息并添加
        void ModifyProduct();                                                                //修改商品信息
        void DeleteProduct();                                                                //删除商品信息
        void ProductsSell();                                                                        //商品销售

void ReportPrint();                                                                                //报表显示
        void ShowAllSellReport();                                                        //显示所有商品销售情况
        void ShowDaySellReport();                                                        //显示某日的销售情况
        void ShowMonthSellReport();                                                                //显示某月的销售情况
        void ShowEmployeeSellReport();                                                //显示某个销售员的销售情况
void ExitSystem();                                                                                // 退出登陆系统

float getPriceById(int );                                                        //通过商品编号查询商品价格
int getProductNameById(int,char *);                //通过商品编号查询商品名称
int getCountById(int);                                                                //通过商品编号查询商品库存数量
void ReduceProductCount(int,int);                        //通过商品编号减少商品数量


/** 对系统进行初始化,建立用户记录和商品记录 **/
void InitSystem() {
        SystemUser adminUser,bossUser,sellUser;                        //管理员,店长,销售员三个角色信息
        Products products[2];                                                                                                //初始化两件服装商品信息
        SellInfoRecord sellInfo[2];                                                                        //初始化两条销售记录

        strcpy(adminUser.userName,"admin");
        strcpy(adminUser.password,"admin");
        adminUser.userType = ADMIN_USER_TYPE;
        adminUser.next = NULL;

        strcpy(bossUser.userName,"boss");
        strcpy(bossUser.password,"boss");
        bossUser.userType = BOSS_USER_TYPE;
        bossUser.next = NULL;

        strcpy(sellUser.userName,"sell");
        strcpy(sellUser.password,"sell");
        sellUser.userType = SELL_USER_TYPE;
        sellUser.next = NULL;

        AddUser(&adminUser);
        AddUser(&bossUser);
        AddUser(&sellUser);



        //products[0].productId = 1;
        strcpy(products[0].productName,"休闲男装");
        strcpy(products[0].productType,"SUN001");
        strcpy(products[0].productCompany,"太阳服装制造厂");
        products[0].productPrice = 23.5;
        products[0].productCount = 100;
        strcpy(products[0].memo,"好服装,太阳造");
        products[0].next = NULL;

        //products[1].productId = 2;
        strcpy(products[1].productName,"可爱女装");
        strcpy(products[1].productType,"STAR002");
        strcpy(products[1].productCompany,"双星服装制造厂");
        products[1].productPrice = 25.5;
        products[1].productCount = 150;
        strcpy(products[1].memo,"好服装,双星造");
        products[1].next = NULL;

        AddProduct(&products[0]);
        AddProduct(&products[1]);

        sellInfo[0].day = 16;
        strcpy(sellInfo[0].memo,"测试数据1");
        sellInfo[0].month = 7;
        sellInfo[0].next = NULL;
        sellInfo[0].productId = 1;
        sellInfo[0].sellCount = 8;
        strcpy(sellInfo[0].userName,"sell");
        sellInfo[0].year = 2008;

        sellInfo[1].day = 17;
        strcpy(sellInfo[1].memo,"测试数据2");
        sellInfo[1].month = 7;
        sellInfo[1].next = NULL;
        sellInfo[1].productId = 2;
        sellInfo[1].sellCount = 5;
        strcpy(sellInfo[1].userName,"sell");
        sellInfo[1].year = 2008;

        AddSellInfo(&sellInfo[0]);
        AddSellInfo(&sellInfo[1]);


};

/**函数功能: 向系统用户信息链表中加入用户信息**/
int AddUser(SystemUser *pUser) {
        SystemUser *pSystemUser,*tempSystemUser;

        tempSystemUser = pSystemUserHead;
        while(NULL != tempSystemUser) {
                if(0 ==strcmp(tempSystemUser->userName,pUser->userName)) {
                        printf("对不起,你要添叫的用户已经存在");
                        return FUNCTION_FAILED;
                }
                tempSystemUser = tempSystemUser->next;
        }

        pSystemUser = (SystemUser *) malloc(sizeof(SystemUser));         //在堆空间中分配用户信息的内存
        if(NULL == pSystemUser) {
                printf("分配用户信息内存时发生错误");
                return FUNCTION_FAILED;
        }
       
       
        strcpy(pSystemUser->userName,pUser->userName);                                                        //拷贝用户信息到堆空间中
        strcpy(pSystemUser->password,pUser->password);
        pSystemUser->userType = pUser->userType;
        pSystemUser->next = pUser->next;
       
        tempSystemUser = pSystemUserHead;
        if(NULL == tempSystemUser) {
                pSystemUserHead = pSystemUser;
        } else {
                while(NULL != tempSystemUser->next)                                                                                                //遍历到用户信息的最后一条记录
                        tempSystemUser = tempSystemUser->next;
                tempSystemUser->next = pSystemUser;                                                                                                        //将用户信息加入到链表的最后
        }
//        printf("添加用户信息成功!");
        return FUNCTION_SUCCESS;
};

/**函数功能: 向商品信息链表中加入商品信息**/
int AddProduct(Products *pPro) {
        int newProductId = 1;                                                                                                                                                                        //新加入商品的商品编号从1开始
        Products *tempProduct,*pProduct;
       
        tempProduct = pProductHead;                                                                                                                                                //生成编号,最后一件商品编号+1
        while(NULL != tempProduct) {
                newProductId = tempProduct->productId + 1;
                tempProduct = tempProduct->next;
        }

        pProduct = (Products *)malloc(sizeof(Products));
        if(NULL == pProduct) {
                printf("对不器,添加商品信息时,堆内存分配失败!");
                return FUNCTION_FAILED;
        }
        pProduct->productId = newProductId;                                                                                                                //拷贝商品信息
        strcpy(pProduct->productName,pPro->productName);
        strcpy(pProduct->productType,pPro->productType);
        strcpy(pProduct->productCompany,pPro->productCompany);
        pProduct->productPrice = pPro->productPrice;
        pProduct->productCount = pPro->productCount;
        strcpy(pProduct->memo,pPro->memo);
        pProduct->next = pPro->next;

        tempProduct = pProductHead;                                                                                                                                                //将商品信息加入到商品信息链表最后
        if(NULL == tempProduct) {
                pProductHead = pProduct;
        } else {
                while(NULL != tempProduct->next)
                        tempProduct = tempProduct->next;
                tempProduct->next = pProduct;
        }
        return FUNCTION_SUCCESS;
};

/**函数功能: 向系统销售信息链表中加入销售信息**/
int AddSellInfo(SellInfoRecord *pSellInfo) {
        int newSellInfoId = 1;                                                                                                                                                                //新加入销售记录的编号从1开始
        SellInfoRecord *tmpSellInfo,*pSellInfoRecord;
       
        tmpSellInfo = pSellInfoHead;                                                                                                                                                //生成编号,最后一个销售编号+1
        while(NULL != tmpSellInfo) {
                newSellInfoId = tmpSellInfo->saleId + 1;
                tmpSellInfo = tmpSellInfo->next;
        }

        pSellInfoRecord = (SellInfoRecord *)malloc(sizeof(SellInfoRecord));
        if(NULL == pSellInfoRecord) {
                printf("对不起,添加销售记录信息时,堆内存分配失败!");
                return FUNCTION_FAILED;
        }
        pSellInfoRecord->saleId = newSellInfoId;
        pSellInfoRecord->day = pSellInfo->day;
        strcpy(pSellInfoRecord->memo,pSellInfo->memo);
        pSellInfoRecord->month = pSellInfo->month;
        pSellInfoRecord->next = pSellInfo->next;
        pSellInfoRecord->productId = pSellInfo->productId;
        pSellInfoRecord->sellCount = pSellInfo->sellCount;
        strcpy(pSellInfoRecord->userName,pSellInfo->userName);
        pSellInfoRecord->year = pSellInfo->year;


        tmpSellInfo = pSellInfoHead;                                                                                                                                //将销售信息加入到销售记录信息链表最后
        if(NULL == tmpSellInfo) {
                pSellInfoHead = pSellInfoRecord;
        } else {
                while(NULL != tmpSellInfo->next)
                        tmpSellInfo = tmpSellInfo->next;
                tmpSellInfo->next = pSellInfoRecord;
        }
        return FUNCTION_SUCCESS;
};

/**函数功能: 向商品信息链表中加入商品信息**/

/*系统登陆函数*/
void SystemLogin() {
        char userName[20],password[20];
        int isLogin = 0;
        SystemUser *tmpUser;
        printf("请输入你的系统用户帐号:");
        scanf("%s",userName);
        printf("\n请输入你的系统用户密码:");
        scanf("%s",password);

        tmpUser = pSystemUserHead;
        while(NULL != tmpUser) {
                if(0 == strcmp(tmpUser->userName,userName)) {
                        if(0 == strcmp(tmpUser->password,password)) {
                                isLogin = 1;
                                strcpy(currentUser,tmpUser->userName);
                                currentUserType = tmpUser->userType;
                                switch(currentUserType) {
                                        case ADMIN_USER_TYPE:
                                                AdminOperationMenu();
                                                break;
                                        case BOSS_USER_TYPE:
                                                BossOperationMenu();
                                                break;
                                        case SELL_USER_TYPE:
                                                SellOperationMenu();
                                                break;
                                        default:
                                                break;
                                }
                        } else {
                                printf("对不起,你输入的密码错误!\n");
                                SystemLogin();                                                                                                                        //用户名正确,密码错误
                        }
                }
                tmpUser = tmpUser->next;
        }
        if(isLogin != 1) {
                printf("对不起,该用户不存在\n");                                                                                //遍历了所有用户都没有找到用户
                SystemLogin();
        }
}

void WelcomeMenu() {
        printf("********************欢迎光临服装销售管理系统********************\n");
        printf("系统功能说明:\n");
        printf("   管理员功能:\n");
        printf("       (1)自身密码修改\n");
        printf("       (2)用户信息管理:添加,修改,删除,查询\n");
        printf("       (3)商品信息管理:添加,修改,查询,删除\n");
        printf("       (4)销售报表显示:日销售报表,月销售报表,销售员销售报表\n");
        printf("       (5)退出登陆系统\n");
        printf("   店长功能:\n");
        printf("       (1)自身密码修改\n");
        printf("       (2)商品信息管理:添加,修改,查询,删除\n");
        printf("       (3)销售报表显示:日销售报表,月销售报表,销售员销售报表\n");
        printf("       (4)退出登陆系统\n");
        printf("   销售员功能:\n");
        printf("       (1)商品浏览,查询,商品销售\n");
        printf("       (2)自己商品销售报表显示:日销售报表,月销售报表\n");
        printf("       (3)退出登陆系统\n");
        printf("*************************欢迎使用本系统**************************\n");
};

void AdminOperationMenu() {
        int select;
        while(1) {
                printf("亲爱的管理员%s同志,欢迎使用本系统,你拥有下面所有功能:\n",currentUser);
                printf("  (1)自身密码修改\n");
                printf("  (2)用户信息管理:添加,修改,查询,删除\n");
                printf("  (3)商品信息管理:添加,修改,查询,删除\n");
                printf("  (4)销售报表显示:日报表,月报表,商品销售量报表,销售员业绩报表\n");
                printf("  (5)退出系统\n");
                printf("请输入上面功能对应的序号进行功能选择:");
                scanf("%d",&select);
                switch(select) {
                        case 1:
                                ChangePassword();
                                continue;
                        case 2:
                                UserManage();
                                continue;
                        case 3:
                                ProductsManage();
                                continue;
                        case 4:
                                ReportPrint();
                                continue;
                        case 5:
                                ExitSystem();
                                break;
                        default:
                                break;
                }
        }
};

void BossOperationMenu() {
  int select;
        while(1) {
                printf("亲爱的店长%s同志,欢迎使用本系统,你拥有下面所有功能:\n",currentUser);
                printf("  (1)自身密码修改\n");
                printf("  (2)商品信息管理:添加,修改,查询,删除\n");
                printf("  (3)销售报表显示:日报表,月报表,商品销售量报表,销售员业绩报表\n");
                printf("  (4)退出系统\n");
                printf("请输入上面功能对应的序号进行功能选择:");
                scanf("%d",&select);
                switch(select) {
                        case 1:
                                ChangePassword();
                                break;
                        case 2:
                                ProductsManage();
                                break;
                        case 3:
                                ReportPrint();
                                break;
                        case 4:
                                ExitSystem();;
                                break;
                        default:
                                break;
                }
        }
};

void SellOperationMenu() {
        int select;
        while(1) {
                printf("亲爱的销售员%s同志,欢迎使用本系统,你拥有下面所有功能:\n",currentUser);
                printf("  (1)商品浏览\n");
                printf("  (2)商品查询\n");
                printf("  (3)商品销售\n");
                printf("  (4)报表查看\n");
                printf("  (5)退出登陆系统\n");
                printf("请输入上面功能对应的序号进行功能选择:");
                scanf("%d",&select);
                switch(select) {
                        case 1:
                                ProductsView();
                                continue;
                        case 2:
                                ProductFind();
                                continue;
                        case 3:
                                ProductsSell();
                                continue;
                        case 4:
                                ReportPrint();
                                continue;
                        case 5:
                                ExitSystem();;
                                break;
                        default:
                                break;
                }
        }
};

void ChangePassword() {
        char newPassword1[20],newPassword2[20];
        SystemUser *tmpUser;
        printf("请输入你的新密码:");
        scanf("%s",newPassword1);
        printf("请再次输入你的新密码:");
        scanf("%s",newPassword2);
        if(0 != strcmp(newPassword1,newPassword2)) {
                printf("对不起,你两次输入的密码不一致,修改失败!\n");
                return ;
        }

        tmpUser = pSystemUserHead;
        while(NULL != tmpUser) {
                if(0 == strcmp(tmpUser->userName,currentUser)) {
                        strcpy(tmpUser->password,newPassword1);
                        printf("密码修改成功!\n");
                        break;
                }
                tmpUser = tmpUser->next;
        }
};

void UserManage() {
        int select;
        while(1) {
                printf("亲爱的管理员%s同志,你目前进入的是用户信息管理功能:\n",currentUser);
                printf("  (1)用户信息查看\n");
                printf("  (2)用户信息添加\n");
                printf("  (3)用户信息修改\n");
                printf("  (4)用户信息删除\n");
                printf("  (5)返回上级菜单\n");
                printf("  (6)退出登陆系统\n");
                printf("请输入上面功能对应的序号进行功能选择:");
                scanf("%d",&select);
                switch(select)
                {
                        case 1:
                                UserInfoView();
                                continue;
                        case 2:
                                UserInfoAdd();
                                continue;
                        case 3:
                                UserInfoModify();
                                continue;
                        case 4:
                                UserInfoDelete();
                                continue;
                        case 5:
                                AdminOperationMenu();
                                break;
                        case 6:
                                ExitSystem();
                                break;
                        default:
                                break;
                }
        }
};

void ProductsView() {
        Products *tmpProduct;
        int i;
        i = 1;
        tmpProduct = pProductHead;
        if(NULL == tmpProduct)
                printf("对不起,目前还没有商品信息");
        else{
                while(NULL != tmpProduct) {
                        printf("第%d件商品信息如下:\n",i);
                        printf("商品编号: %d\n",tmpProduct->productId);
                        printf("商品名称: %s\n",tmpProduct->productName);
                        printf("商品型号: %s\n",tmpProduct->productType);
                        printf("商品厂家: %s\n",tmpProduct->productCompany);
                        printf("商品价格: %f\n",tmpProduct->productPrice);
                        printf("商品数量: %d\n",tmpProduct->productCount);
                        printf("商品附加信息: %s\n",tmpProduct->memo);
                       
                        tmpProduct = tmpProduct->next;
                        i++;
                }
        }
};

void ProductsSell() {
        SellInfoRecord sellInfo;
        printf("亲爱的销售员朋友%s,你好,你现在进入的是产品的销售功能:",currentUser);
        printf("请依次输入以下销售信息:\n");
        printf("销售的产品编号:");
        scanf("%d",&sellInfo.productId);
        printf("销售的产品数量:");
        scanf("%d",&sellInfo.sellCount);
        if(sellInfo.sellCount > getCountById(sellInfo.productId)) {
                printf("对不起,你输入的销售数量大于库存,销售失败!\n");
                return ;
        }
        strcpy(sellInfo.userName,currentUser);
        printf("销售商品所在年份:");
        scanf("%d",&sellInfo.year);
        printf("销售商所在月份:");
        scanf("%d",&sellInfo.month);
        printf("销售商品所在号数:");
        scanf("%d",&sellInfo.day);
        printf("销售商品的附加信息:");
        scanf("%s",sellInfo.memo);

        sellInfo.next = NULL;


        if(FUNCTION_SUCCESS == AddSellInfo(&sellInfo)) {
                printf("商品销售成功!\n");
                ReduceProductCount(sellInfo.productId,sellInfo.sellCount);
        };
};


void ExitSystem() {
        memset(currentUser,0x00,sizeof(char)*20);
        currentUserType = 0;
        SystemLogin();
};

void ProductsManage() {
        int select;
        while(1) {
                printf("亲爱的%s朋友,你好,你现在进入的是商品管理功能,你可以选择以下功能:\n",currentUser);
                printf("   (1)商品信息查看\n");
                printf("   (2)商品信息查找\n");
                printf("   (3)商品信息添加\n");
                printf("   (4)商品信息修改\n");
                printf("   (5)商品信息删除\n");
                printf("   (6)返回上一级菜单\n");
                printf("   (7)退出登陆系统\n");
                printf("请选择应的操作编号:");
                scanf("%d",&select);
                switch(select) {
                        case 1:
                                ProductsView();
                                continue;
                        case 2:
                                ProductFind();
                                continue;
                        case 3:
                                InputAndAddProduct();
                                continue;
                        case 4:
                                ModifyProduct();
                                continue;
                        case 5:
                                DeleteProduct();
                                continue;
                        case 6:
                                switch(currentUserType) {
                                        case ADMIN_USER_TYPE:
                                                AdminOperationMenu();
                                                break;
                                        case BOSS_USER_TYPE:
                                                BossOperationMenu();
                                                break;
                                        case SELL_USER_TYPE:
                                                SellOperationMenu();
                                                break;
                                        default:
                                                break;
                                }
                                break;
                        case 7:
                                ExitSystem();
                                break;
                        default:
                                break;
                }
        }
};

void InputAndAddProduct() {
        Products product;
        printf("亲爱的%s朋友,你好,请依次输入新商品的信息:\n",currentUser);
        printf("商品名称:");
        scanf("%s",product.productName);
        printf("商品型号:");
        scanf("%s",product.productType);
        printf("商品制造商:");
        scanf("%s",product.productCompany);
        printf("商品价格:");
        scanf("%f",&product.productPrice);
        printf("商品数量:");
        scanf("%d",&product.productCount);
        printf("商品附加信息:");
        scanf("%s",product.memo);
        product.next = NULL;

        if(FUNCTION_SUCCESS == AddProduct(&product))
                printf("商品信息添加成功!\n");
};

void ModifyProduct() {
        int productId;                                                                //待修改的商品编号
        Products *tmpProduct;               
        printf("亲爱的%s朋友,你好,你现在进入的商品信息修改功能:\n",currentUser);
        printf("请输入要修改的商品编号:");
        scanf("%d",&productId);
        tmpProduct = pProductHead;
        if(NULL == tmpProduct) return ;
        while(NULL != tmpProduct) {
                if(productId == tmpProduct->productId){
                        printf("商品编号%d的商品信息如下:\n",productId);
                        printf("  商品名称: %s\n",tmpProduct->productName);
                        printf("  商品型号: %s\n",tmpProduct->productType);
                        printf("  商品厂家: %s\n",tmpProduct->productCompany);
                        printf("  商品价格: %f\n",tmpProduct->productPrice);
                        printf("  商品数量: %d\n",tmpProduct->productCount);
                        printf("  商品附加信息: %s\n",tmpProduct->memo);

                        printf("下面请对照修改该商品的相应信息:\n");
                        printf("新的商品名称: ");
                        scanf("%s",tmpProduct->productName);
                        printf("新的商品型号: ");
                        scanf("%s",tmpProduct->productType);
                        printf("新的商品厂家: ");
                        scanf("%s",tmpProduct->productCompany);
                        printf("新的商品价格: ");
                        scanf("%f",&tmpProduct->productPrice);
                        printf("新的商品数量: ");
                        scanf("%d",&tmpProduct->productCount);
                        printf("新的商品附加信息: ");
                        scanf("%s",tmpProduct->memo);

                        printf("商品信息修改成功!\n");

                        break;
                }
                tmpProduct = tmpProduct->next;
        }

       

};

void ProductFind() {
        Products *tmpProduct;       
        int findWay,productId;
        char productName[20];
        printf("亲爱的%s朋友,你好,你现在进入的商品查询功能:\n",currentUser);
        printf("请选择查询方式: 1--按商品编号查询  2--按商品名称查询\n");
        scanf("%d",&findWay);
        tmpProduct = pProductHead;
        switch(findWay) {
                case 1:
                        printf("请输入查询的商品编号:");
                        scanf("%d",&productId);
                        while(NULL != tmpProduct) {
                                if(productId == tmpProduct->productId) {
                                        printf("你查询的商品编号为%d的商品信息如下:\n",productId);
                                        printf("  商品名称: %s\n",tmpProduct->productName);
                                        printf("  商品型号: %s\n",tmpProduct->productType);
                                        printf("  商品厂家: %s\n",tmpProduct->productCompany);
                                        printf("  商品价格: %f\n",tmpProduct->productPrice);
                                        printf("  商品数量: %d\n",tmpProduct->productCount);
                                        printf("  商品附加信息: %s\n",tmpProduct->memo);
                                        return ;
                                }
                                tmpProduct = tmpProduct->next;
                        }
                        printf("对不起,不存在该商品编号的商品!\n");
                        break;
                case 2:
                        printf("请输入查询的商品名称:");
                        scanf("%s",productName);
                        while(NULL != tmpProduct) {
                                if(0 == strcmp(tmpProduct->productName,productName)) {
                                        printf("你要查询的商品名称为%s的商品信息如下:\n",productName);
                                        printf("  商品名称: %s\n",tmpProduct->productName);
                                        printf("  商品型号: %s\n",tmpProduct->productType);
                                        printf("  商品厂家: %s\n",tmpProduct->productCompany);
                                        printf("  商品价格: %f\n",tmpProduct->productPrice);
                                        printf("  商品数量: %d\n",tmpProduct->productCount);
                                        printf("  商品附加信息: %s\n",tmpProduct->memo);
                                        return ;
                                }
                                tmpProduct = tmpProduct->next;
                        }
                        printf("对不起,不存在该商品编号的商品!\n");
                        break;
                default:
                        break;
        }
}
void DeleteProduct() {
        int productId = 0;
        Products *tmpProductA,*tmpProductB;
        printf("亲爱的%s朋友,你好,你现在进入的商品删除功能:\n",currentUser);
        printf("请输入你要删除的商品编号:\n");
        scanf("%d",&productId);
        tmpProductA = tmpProductB = pProductHead;        //tmpProductB指向要删除的记录,tmpProductA指向前一条记录
        if(NULL == tmpProductB) return ;
        while(NULL != tmpProductB){
                if(tmpProductB->productId == productId) {
                        if(tmpProductB == pProductHead && tmpProductB->next == NULL){        //如果系统只有一条商品信息
                                free(pProductHead);
                                pProductHead = NULL;
                                printf("商品信息删除成功!\n");
                                return ;
                        }
                        tmpProductA->next = tmpProductB->next;
                        if(pProductHead == tmpProductB)
                                pProductHead = tmpProductB->next;
                        free(tmpProductB);
                        printf("商品信息删除成功!\n");
                        return ;
                }
                else {
                        tmpProductA = tmpProductB;
                        tmpProductB = tmpProductB->next;
                }
        }
        printf("对不起,不存在该商品编号的信息!");
};

void ReportPrint() {
        int select = 0;
        if(SELL_USER_TYPE != currentUserType) {
                while(1) {
                        printf("亲爱的朋友%s,你好,你现在进入的是销售报表功能界面:\n",currentUser);
                        printf("  (1)所有商品销售情况\n");
                        printf("  (2)商品日销售报表\n");
                        printf("  (3)商品月销售报表\n");
                        printf("  (4)销售员销售报表\n");
                        printf("  (5)返回上级菜单\n");
                        printf("  (6)退出登陆系统\n");
                        printf("请选择对应的功能号:");
                        scanf("%d",&select);
                        switch(select) {
                                case 1:
                                        ShowAllSellReport();
                                        continue;
                                case 2:
                                        ShowDaySellReport();
                                        continue;
                                case 3:
                                        ShowMonthSellReport();
                                        continue;
                                case 4:
                                        ShowEmployeeSellReport();
                                        continue;
                                case 5:
                                        switch(currentUserType) {
                                                case ADMIN_USER_TYPE:
                                                        AdminOperationMenu();
                                                        break;
                                                case BOSS_USER_TYPE:
                                                        BossOperationMenu();
                                                        break;
                                                default:
                                                        break;
                                        }
                                        break;
                                case 6:
                                        ExitSystem();
                                        break;
                                default:
                                        break;
                        }
                }
        } else {
                while(1) {
                        printf("亲爱的销售员%s,你好,你现在进入的是销售报表功能界面:\n",currentUser);
                        printf("  (1)查看自己日销售报表\n");
                        printf("  (2)查看自己月销售报表\n");
                        printf("  (3)返回上级菜单\n");
                        printf("  (4)退出登陆系统");
                        printf("请选择相应的功能号:");
                        scanf("%d",&select);
                        switch(select) {
                                case 1:
                                        ShowDaySellReport();
                                        continue;
                                case 2:
                                        ShowMonthSellReport();
                                        continue;
                                case 3:
                                        SellOperationMenu();
                                        break;
                                case 4:
                                        ExitSystem();
                                        break;
                                default:
                                        break;
                        }
                }
        }
};


void UserInfoView() {
        SystemUser *tmpUser;
        tmpUser = pSystemUserHead;
        printf("亲爱的管理员%s,你好,你查看的所有用户信息如下:\n",currentUser);
        printf("用户名\t密码\t用户类型(1代表管理员,2代表店长,3代表销售员)\n");
        while(NULL != tmpUser){
                printf("%s\t%s\t%d\n",tmpUser->userName,tmpUser->password,tmpUser->userType);
                tmpUser = tmpUser->next;
        }
};

void UserInfoAdd() {
        SystemUser tmpUser;
        printf("亲爱的管理员%s,请依次输入用户信息:\n",currentUser);
        printf("用户名:");
        scanf("%s",tmpUser.userName);
        printf("用户密码:");
        scanf("%s",tmpUser.password);
        printf("用户类型(1代表管理员,2代表店长,3代表销售员):");
        scanf("%d",&tmpUser.userType);
        tmpUser.next = NULL;

        if(FUNCTION_SUCCESS == AddUser(&tmpUser))
                printf("用户信息添加成功!\n");

};

void UserInfoModify() {
        char userName[20];
        SystemUser *pUser;
        printf("亲爱的管理员%s,请输入要修改的用户帐号:\n",currentUser);
        scanf("%s",userName);
        pUser = pSystemUserHead;
        while(NULL != pUser) {
                if(0 == strcmp(pUser->userName,userName)) {
                        printf("请输入新的帐号:");
                        scanf("%s",pUser->userName);
                        printf("请输入新的密码:");
                        scanf("%s",pUser->password);
                        printf("请输入新的用户类型(1代表管理员,2代表店长,3代表销售员):");
                        scanf("%d",&pUser->userType);
                        printf("用户信息修改成功\n");
                        return ;
                }
                pUser = pUser->next;
        }
        printf("对不起,没有你查找的用户信息!\n");
};

void UserInfoDelete() {

        SystemUser *pUserA,*pUserB;
        char userName[20];
        printf("亲爱的管理员%s朋友,你好,你现在进入的用户信息删除功能:\n",currentUser);
        printf("请输入你要删除的用户名:\n");
        scanf("%s",userName);
        pUserA = pUserB = pSystemUserHead;        //pUserB指向要删除的记录,pUserA指向前一条记录
        if(NULL == pUserB) return ;
        while(NULL != pUserB){
                if(0 == strcmp(userName,pUserB->userName)) {
                        if(pUserB == pSystemUserHead && pUserB->next == NULL){        //如果系统只有一条商品信息
                                free(pSystemUserHead);
                                pSystemUserHead = NULL;
                                printf("用户信息删除成功!\n");
                                return ;
                        }
                        pUserA->next = pUserB->next;
                        if(pSystemUserHead == pUserB)
                                pSystemUserHead = pUserB->next;
                        free(pUserB);
                        printf("用户信息删除成功!\n");
                        return ;
                }
                else {
                        pUserA = pUserB;
                        pUserB = pUserB->next;
                }
        }
        printf("对不起,不存在该帐号的用户信息!");
};

void ShowDaySellReport() {
        int year,month,day;
        int rsCount = 0;
        float totalPrice = 0.0,onePrice;
        char productName[20];
        SellInfoRecord *tmpSellInfo;
        printf("你好%s:当前功能将进行日销售报表显示\n",currentUser);
        printf("请输入销售时间年份:");
        scanf("%d",&year);
        printf("请输入销售时间月份:");
        scanf("%d",&month);
        printf("请输入销售时间号数:");
        scanf("%d",&day);

        tmpSellInfo = pSellInfoHead;
        if(NULL == tmpSellInfo) return ;
        while(NULL != tmpSellInfo) {
                if(year == tmpSellInfo->year &&
                   month == tmpSellInfo->month &&
                         day == tmpSellInfo->day &&
                         ((SELL_USER_TYPE == currentUserType)?(0 == strcmp(tmpSellInfo->userName,currentUser)):1)) {
                        rsCount++;
                        printf("符合条件的第%d条商品销售记录信息如下:\n",rsCount);
                        printf(" 销售编号:%d\n",tmpSellInfo->saleId);
                        printf(" 产品编号:%d\n",tmpSellInfo->productId);
                        getProductNameById(tmpSellInfo->productId,productName);
                        printf(" 产品名称:%s\n",productName);
                        onePrice = getPriceById(tmpSellInfo->productId);
                        printf(" 商品单价:%f\n",onePrice);
                        printf(" 销售数量:%d\n",tmpSellInfo->sellCount);
                        printf(" 销售员:%s\n",tmpSellInfo->userName);
                        printf(" 销售时间:%d年%d月%d日\n",tmpSellInfo->year,tmpSellInfo->month,tmpSellInfo->day);
                        totalPrice += onePrice*tmpSellInfo->sellCount;
                }
                tmpSellInfo = tmpSellInfo->next;
        }
        printf("总共有%d条符合条件的记录,销售总价%f元\n",rsCount,totalPrice);
};

void ShowMonthSellReport() {
        int year,month;
        int rsCount = 0;
        float totalPrice = 0.0,onePrice;
        char productName[20];
        SellInfoRecord *tmpSellInfo;
        printf("你好%s:当前功能将进行月销售报表显示\n",currentUser);
        printf("请输入销售时间年份:");
        scanf("%d",&year);
        printf("请输入销售时间月份:");
        scanf("%d",&month);

        tmpSellInfo = pSellInfoHead;
        if(NULL == tmpSellInfo) return ;
        while(NULL != tmpSellInfo) {
                if(year == tmpSellInfo->year &&
                   month == tmpSellInfo->month &&
                         ((SELL_USER_TYPE == currentUserType)?(0 == strcmp(tmpSellInfo->userName,currentUser)):1)) {
                        rsCount++;
                        printf("符合条件的第%d条商品销售记录信息如下:\n",rsCount);
                        printf(" 销售编号:%d\n",tmpSellInfo->saleId);
                        printf(" 产品编号:%d\n",tmpSellInfo->productId);
                        getProductNameById(tmpSellInfo->productId,productName);
                        printf(" 产品名称:%s\n",productName);
                        onePrice = getPriceById(tmpSellInfo->productId);
                        printf(" 商品单价:%f\n",onePrice);
                        printf(" 销售数量:%d\n",tmpSellInfo->sellCount);
                        printf(" 销售员:%s\n",tmpSellInfo->userName);
                        printf(" 销售时间:%d年%d月%d日\n",tmpSellInfo->year,tmpSellInfo->month,tmpSellInfo->day);
                        totalPrice += onePrice*tmpSellInfo->sellCount;
                }
                tmpSellInfo = tmpSellInfo->next;
        }
        printf("总共有%d条符合条件的记录,销售总价%f元\n",rsCount,totalPrice);
};

void ShowEmployeeSellReport() {
        char userName[20];
        int rsCount = 0;
        float totalPrice = 0.0,onePrice;
        char productName[20];
        SellInfoRecord *tmpSellInfo;
        printf("你好%s:当前功能将进行销售员销售报表显示\n",currentUser);
        printf("请输入销售员的帐户名:");
        scanf("%s",userName);
        tmpSellInfo = pSellInfoHead;
        if(NULL == tmpSellInfo) return ;
        while(NULL != tmpSellInfo) {
                if(0 == strcmp(userName,tmpSellInfo->userName)) {
                        rsCount++;
                        printf("符合条件的第%d条商品销售记录信息如下:\n",rsCount);
                        printf(" 销售编号:%d\n",tmpSellInfo->saleId);
                        printf(" 产品编号:%d\n",tmpSellInfo->productId);
                        getProductNameById(tmpSellInfo->productId,productName);
                        printf(" 产品名称:%s\n",productName);
                        onePrice = getPriceById(tmpSellInfo->productId);
                        printf(" 商品单价:%f\n",onePrice);
                        printf(" 销售数量:%d\n",tmpSellInfo->sellCount);
                        printf(" 销售员:%s\n",tmpSellInfo->userName);       
                        printf(" 销售时间:%d年%d月%d日\n",tmpSellInfo->year,tmpSellInfo->month,tmpSellInfo->day);
                        totalPrice += onePrice*tmpSellInfo->sellCount;
                }
                tmpSellInfo = tmpSellInfo->next;
        }
        printf("总共有%d条符合条件的记录,销售总价%f元\n",rsCount,totalPrice);
};

void ShowAllSellReport() {
        int rsCount = 0;
        float totalPrice = 0.0,onePrice;
        char productName[20];
        SellInfoRecord *tmpSellInfo;
        printf("你好%s:当前功能将进行所有销售报表显示\n",currentUser);
        tmpSellInfo = pSellInfoHead;
        if(NULL == tmpSellInfo) return ;
        while(NULL != tmpSellInfo) {
                rsCount++;
                printf("第%d条商品销售记录信息如下:\n",rsCount);
                printf(" 销售编号:%d\n",tmpSellInfo->saleId);
                printf(" 产品编号:%d\n",tmpSellInfo->productId);
                getProductNameById(tmpSellInfo->productId,productName);
                printf(" 产品名称:%s\n",productName);
                onePrice = getPriceById(tmpSellInfo->productId);
                printf(" 商品单价:%f\n",onePrice);
                printf(" 销售数量:%d\n",tmpSellInfo->sellCount);
                printf(" 销售员:%s\n",tmpSellInfo->userName);       
                printf(" 销售时间:%d年%d月%d日\n",tmpSellInfo->year,tmpSellInfo->month,tmpSellInfo->day);
                totalPrice += onePrice*tmpSellInfo->sellCount;

                tmpSellInfo = tmpSellInfo->next;
        }
        printf("总共有%d条符合条件的记录,销售总价%f元\n",rsCount,totalPrice);
};

int getCountById(int productId) {
        Products *tmpProduct;
        tmpProduct = pProductHead;
        while(NULL != tmpProduct) {
                if(productId == tmpProduct->productId)
                        return tmpProduct->productCount;
                tmpProduct = tmpProduct->next;
        }
        return FUNCTION_FAILED;
};

float getPriceById(int productId) {
        Products *tmpProduct;
        tmpProduct = pProductHead;
        while(NULL != tmpProduct) {
                if(productId == tmpProduct->productId)
                        return tmpProduct->productPrice;
                tmpProduct = tmpProduct->next;
        }
        return 0.0;
};

void ReduceProductCount(int productId,int Count) {
        Products *tmpProduct;
        tmpProduct = pProductHead;
        while(NULL != tmpProduct) {
                if(productId == tmpProduct->productId) {
                        tmpProduct->productCount = tmpProduct->productCount - Count;
                }
                tmpProduct = tmpProduct->next;
        }
};
int getProductNameById(int productId,char *p) {
        Products *tmpProduct;
        tmpProduct = pProductHead;
        while(NULL != tmpProduct) {
                if(productId == tmpProduct->productId) {
                        strcpy(p,tmpProduct->productName);
                        return FUNCTION_SUCCESS;
                }
                tmpProduct = tmpProduct->next;
        }
        return FUNCTION_FAILED;
}

void main()
{
        InitSystem();
        WelcomeMenu();       
        SystemLogin();
}

snakealpha 发表于 2008-9-9 18:32

嘎嘎,太巧了哈,我们也在做课程设计哦,我要是坏孩子我就把你的代码拷走^^

页: [1]

编程论坛