signed

QiShunwang

“诚信为本、客户至上”

编写开发环境很难吗

2020/12/27 3:18:52   来源:

结束语

 

在这几篇文章的最后,我想呈现我做为一个代码者(我不是开发者,我是业务者)的代码风格,代码风格就是代码者的本性。

系统登录界面的代码段:

        private void ToolBoxClick(object sender, ToolBoxItemClickEventArgs e)
        {
            if (!FTP.GetHostInfo()) //加载解密服务器链接文件
            {
                EAS.ResultInfo.Throw(this); //抛出异常消息清单
                return;
            }
            if (!CheckUser()) //检查用户及密码是否合法
            {
                EAS.ResultInfo.Throw(this);
                return;
            }

            switch (e.KeyCode)
            {
                case "Logon":
                    if (DownLoadFile())
                        DialogResult = DialogResult.OK;
                    else
                    {
                        EAS.ResultInfo.Throw(this);
                        DialogResult = DialogResult.No;
                    }
                    break;
                case "NewPass":
                    ModifyPass();
                    break;
            }
        }
        private bool DownLoadFile()
        {
            //下载最新的系统菜单
            string ServerFile = "/EASHome.eas";
            if (!EAS.FTP.FileExists(ServerFile)) return false;

            string ClientFile = EAS.Comm.ClientDir + "\\EASHome.eas";
            if (EAS.FTP.HasNewVersion(ServerFile, ClientFile))
            {
                if (!EAS.FTP.DownLoadFile(ServerFile, ClientFile))
                {
                    EAS.ResultInfo.Add("", "无法加载系统菜单", MessageType.Error, "Logon");
                    return false;
                }
            }
            if (!File.Exists(ClientFile))
            {
                EAS.ResultInfo.Add("", "无法加载系统菜单", MessageType.Error, "Logon");
                return false;
            }
            //加载最新的程序依赖项
            ServerFile = "/EASCore/EASCore.dll";
            if (!EAS.FTP.FileExists(ServerFile))
            {
                EAS.ResultInfo.Add("", "无法加载程序依赖项", MessageType.Error, "Logon");
                return false;
            }

            ClientFile = EAS.Comm.ClientDir + "\\EASCore\\EASCore.dll";
            if (EAS.FTP.HasNewVersion(ServerFile, ClientFile))
            {
                if (!EAS.FTP.DownLoadFile(ServerFile, ClientFile))
                {
                    EAS.ResultInfo.Add("", "无法加载程序依赖项", MessageType.Error, "Logon");
                    return false;
                }
            }
            if (!File.Exists(ClientFile))
            {
                EAS.ResultInfo.Add("", "无法加载程序依赖项", MessageType.Error, "Logon");
                return false;
            }

            return true;
        }
        private bool CheckUser()
        {
            tbUser.Text = tbUser.Text.Trim().ToUpper();
            if (!EAS.User.Check(tbUser.Text, tbPassword.Text))
                return false;
            Data.Xarray vXarray = new Data.Xarray();
            vXarray.LoadData("SELECT FORMA1,FORMA2 FROM X00002 WHERE USRCOD = '" + tbUser.Text + "'");
            if (vXarray.RowCount == 0)
                return false;
            
            string Format1 = vXarray.GetValue(0, "FORMA1");  //日期格式
            string Format2 = vXarray.GetValue(0, "FORMA2");  //数字格式
            SetSysInfo(Format1, Format2);
            return true;
        }

数据处理的代码段:

        public bool Submit(string SourceName, bool BeginTran)
        {
            if (SourceName == "")
            {
                EAS.ResultInfo.Add("", "无效的数据源名,数据提交终止", MessageType.Error, "Xarray");
                return false;
            }
            if (BeginTran)
            {
                if (!Comm.BeginTransaction())
                    return false;
            }
            foreach (DataRow Row in Array.Rows)
            {
                if (IsEmpty(Row)) continue; //空行

                if (Row.RowState == DataRowState.Added)
                {
                    if (!DML.Insert(Row, SourceName))
                    {
                        if(BeginTran) Comm.RollbackTran();
                        return false;
                    }
                }
                else if (Row.RowState == DataRowState.Modified)
                {
                    if (!DML.Update(Row, SourceName))
                    {
                        if(BeginTran) Comm.RollbackTran();
                        return false;
                    }
                }
            }
            foreach (DataRow Row in Array1.Rows) //被删除了的行
            {
                if (IsEmpty(Row)) continue; //空行

                if (!DML.Delete(Row, SourceName))
                {
                    if(BeginTran) Comm.RollbackTran();
                    return false;
                }
            }

            if (BeginTran)
            {
                if (!Comm.CommitTran())
                    return false;
            }
            Array.AcceptChanges();
            Array1.Rows.Clear();

            return true;
        }



       public static bool Insert(DataRow Row, string SourceName)
        {
            string FileName = EAS.Comm.SourceDir + "\\Data\\DWH\\DT\\" + SourceName + ".dt";
            if (File.Exists(FileName)) //更新对象为表 
            {
                DataTable Tab = Row.Table;
                string SQL = "INSERT INTO " + SourceName + " (";
                foreach (DataColumn Col in Tab.Columns)
                {
                    if (Col.ColumnName == "X") continue; //汇总列
                    SQL += Col.ColumnName + ",";
                }
                int CharIndex = SQL.Length - 1;
                if (SQL.Substring(CharIndex, 1) != ",")
                {
                    EAS.ResultInfo.Add("", "无有效的数据列,数据提交终止", MessageType.Error, "DML");
                    return false;
                }

                SQL = SQL.Substring(0, CharIndex) + ") VALUES (";
                foreach (DataColumn Col in Tab.Columns)
                {
                    if (Col.ColumnName == "X") continue; //汇总列

                    SQL += GetColValue(Row, Col);
                }
                SQL = SQL.Substring(0, SQL.Length - 1) + ")";

                if (!Submit(SQL, false)) return false;

                return true;
            }
            else //为视图时则根据其定义的INSERT语句执行
            {
                FileName = EAS.Comm.SourceDir + "\\Data\\DWH\\DV\\" + SourceName + ".dv";
                if (!File.Exists(FileName))
                {
                    EAS.ResultInfo.Add("", "插入数据对象“" + SourceName + "”不存在,数据提交终止", MessageType.Error, "DML");
                    return false;
                }

                EasView vEasView = new EasView();
                vEasView.LoadData(FileName);
                string InSQL = vEasView.InSQL;
                if (InSQL == "")
                {
                    EAS.ResultInfo.Add("", "视图“" + SourceName + "”没有定义插入SQL,数据提交终止", MessageType.Error, "DML");
                    return false;
                }
                InSQL = InSQL.Replace("\r", "");
                string[] SQLList = InSQL.Split('\n');
                foreach (string SQL in SQLList)
                {
                    InSQL = SQL;
                    if (!GetInSQL(Row, ref InSQL)) return false;
                    if (!Submit(InSQL, false)) return false;
                }

                return true;
            }
        }

花了几个亿几百号人开发的系统,从技术架构上我一个业务顾问看不上眼。另外,国内的软件公司到底在做什么?哎!我果然是个天才。